Fix complex rewrite device mismatch - #4513
Open
jloftin-nv wants to merge 1 commit into
Open
Conversation
apbose
reviewed
Aug 21, 2026
| xq = torch.randn(1, 2, 4, 8) | ||
| freqs = torch.polar(torch.ones(1, 2, 4, 4), torch.randn(1, 2, 4, 4)) | ||
| _export_and_lower(RotaryComplex(), (xq, freqs, scale)) | ||
|
|
Collaborator
There was a problem hiding this comment.
this test would pass even without the fix. 0 dim would pass in eager mode and fake tensor mode,but then if you do torch.tensor([2.0]) triggers a mismatch too early FakeTensorDeviceMismatchError—in eager/export—rather than specifically during post-rewrite metadata propagation.
| if isinstance(attr, torch.Tensor) and attr.device != self._align_device: | ||
| return attr.to(self._align_device) | ||
| return attr | ||
|
|
Collaborator
There was a problem hiding this comment.
Every tensor attribute is moved to the first CUDA input’s device.
The new fetch_attr changes all tensor attributes whenever any CUDA placeholder exists. That includes intentionally CPU attributes or an independent CPU branch, producing incorrect device metadata. Something like below
class M(torch.nn.Module):
def __init__(self):
super().__init__()
self.register_buffer("cpu_table", torch.arange(4)) # intentionally CPU
def forward(self, z):
gpu_result = z * z # z is CUDA complex
cpu_result = self.cpu_table + 1 # independent CPU computation
return gpu_result, cpu_result
Maybe we should add
- A real _frozen_param mismatch test proving the target attribute gets aligned.
- A mixed-device test like the example above proving an unrelated CPU attribute remains CPU.
jloftin-nv
force-pushed
the
dev-jloftin-complex-mismatch
branch
from
August 21, 2026 18:28
e5253a9 to
292d096
Compare
Collaborator
|
LGTM. Waiting on CI. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
After complex-graph rewrite, FakeTensorProp can mix CUDA activations with CPU _frozen_param* weights and raise FakeTensorDeviceMismatchError, aborting builds that dry-ran cleanly.
Align parameter devices before prop (and keep the non-tensor meta["val"] guard) so rewritten graphs re-propagate on a single device.
Type of change
Please delete options that are not relevant and/or add your own.
Checklist: