Skip to content

mps: clone() aliases its source, so x.clone().add_(1) changes x #97

Closed

Description

@b-re-w

Measured on this Mac with the real shim (develop and feat/mps-index alike): on mps, y = x.clone(); y.add_(1) changes x too; so do fill_, setitem, clone(memory_format=contiguous) and detach().clone(). cpu is correct. No compute or blit encoder runs: nothing is copied.

Cause: clone_default calls candle Tensor::copy(), whose MetalStorage::try_clone is upstream's Ok(self.clone()), an Arc<Buffer> share. candle never writes a buffer in place, so it was safe there; torch._C does.

Done when

  • MetalStorage::try_clone in the candle fork copies into a fresh buffer (one blit), patch regenerated, vendor_candle.sh --check passes.
  • A test: every clone spelling x every in-place write leaves the source unchanged on mps; detach and alias still share (upstream semantics); a blit encoder is counted. Red before.

Activity

  1. added a commit that references this issue on Oct 16, 2026
  2. b-re-w commented on Oct 16, 2026

    @b-re-w
    MemberAuthor

    Landed in develop via #98

  3. added a commit that references this issue on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions