[Bugfix] Make GPU sync checks safe under torch.compile (#56904)

Signed-off-by: Kevin Luu <51931015+khluu@users.noreply.github.com>
Co-authored-by: Sherlock <sherlock@raft.ai>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Kevin H. Luu
2026-09-15 21:37:08 -07:00
committed by GitHub
co-authored by Sherlock mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 6ecd97f1b7
commit af1c01499b
3 changed files with 32 additions and 3 deletions
+18
View File
@@ -123,6 +123,24 @@ def test_suppressing_works_while_compiling(monkeypatch):
with_gpu_sync_check(suppressed)()
@create_new_process_for_each_test()
def test_copy_checker_is_traceable_while_compiling(monkeypatch):
"""The copy wrapper must bypass ContextVars while Dynamo is tracing."""
monkeypatch.setattr(gsd, "_SYNC_CHECK_MODE", "error")
monkeypatch.setattr(gsd, "_sync_check_enabled", True)
gsd._install_copy_checkers()
def convert_like(x, like):
return x.to(device=like.device, dtype=like.dtype)
compiled = torch.compile(convert_like, fullgraph=True)
result = compiled(
torch.ones(4, device="cuda", dtype=torch.float64),
torch.ones(4, device="cuda", dtype=torch.float32),
)
assert result.dtype == torch.float32
@create_new_process_for_each_test()
def test_sync_debug_mode_restored_after_checked_call(monkeypatch):
"""The mode is armed only for the duration of a checked call. Leaving it