Skip to content

Fix unbacked memo reuse during fake replay - #87

Open
laifenxiawucha wants to merge 3 commits into
mainfrom
fix/issue-1893-unbacked-memo
Open

laifenxiawucha wants to merge 3 commits into
mainfrom
fix/issue-1893-unbacked-memo

Conversation

@laifenxiawucha

Copy link
Copy Markdown
Owner

Summary

Fix unbacked-symbol memo reuse when replaying fake-tensor binding sites.

Root Cause

Fake replay could reuse a bool-mask fake tensor's cached nonzero memo across two aten.index.Tensor nodes that carried distinct old unbacked_bindings. The second replayed node then tried to rename one fresh symbol to two different old symbols, triggering AssertionError: u6 -> u0 during Inductor fake propagation.

Fix

  • add targeted fake-tensor unbacked-memo invalidation helpers
  • clear those memos before replaying nodes with unbacked_bindings in ShapeProp, FakeTensorProp, PropagateUnbackedSymInts, FakeTensorUpdater, and Inductor fallback example propagation
  • add regression tests for FX shape propagation and Inductor bool-mask indexing replay

Verification

  • pre-fix reproducer in /home/jyz/cuda-fix-alignment/.venv/bin/python failed with torch._inductor.exc.InductorError: AssertionError: u6 -> u0
  • post-fix verification passed by loading the patched Python modules into the same XPU wheel environment and rerunning:
import torch
from torch._dynamo import config as dynamo_config

class M(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.w = torch.nn.Parameter(torch.randn(3, 4, 4, device="xpu"))

    def forward(self, mask):
        y1 = self.w[:, ~mask]
        y2 = (self.w + self.w.transpose(1, 2))[:, ~mask]
        return y1, y2

with dynamo_config.patch(capture_dynamic_output_shape_ops=True):
    m = M().to("xpu")
    mask = torch.eye(4, dtype=torch.bool, device="xpu")
    eager = m(mask)
    compiled = torch.compile(m, backend="inductor", fullgraph=True)
    out = compiled(mask)
    torch.testing.assert_close(out[0].cpu(), eager[0].cpu())
    torch.testing.assert_close(out[1].cpu(), eager[1].cpu())

Issue: https://github.com/intel-sandbox/torch-xpu-ops-exp/issues/1893

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant