A small CPU swap exposes two separate parts of a compiled program's contract:
the values it returns and the storage it changes. Both deserve a reference check.
Peter Sharpe reported a real torch._foreach_copy_ compiler fault
while working on TensorDict. His application uses a
materialized stack buffer as a
workaround. A proposed upstream repair
realizes cross-read sources before mutating their destinations.
I measured the original fault and two application-level controls on the released
PyTorch 2.15.0+cpu , commit d0f2af8b66b20da4baa50644c0cd3f887a2eae2e .
The CPU reports AVX512 . All runtime and compiler thread counts are one;
compilation uses backend="inductor", fullgraph=True, dynamic=False .
The snapshot is part of the operation
The intended operation is a simultaneous value swap of two independent,
contiguous FP32 CPU tensors. Capture both old values before the first write:
def explicit_snapshot ( a , b ): sources = ( b . clone (), a .…