Skip to content

Fix test interaction: clean up DTensorSpec pytree registration#176128

Closed
aorenste wants to merge 1 commit intogh/aorenste/199/basefrom
gh/aorenste/199/head
Closed

Fix test interaction: clean up DTensorSpec pytree registration#176128
aorenste wants to merge 1 commit intogh/aorenste/199/basefrom
gh/aorenste/199/head

Conversation

@aorenste
Copy link
Contributor

@aorenste aorenste commented Mar 2, 2026

Stack from ghstack (oldest at bottom):

register_constant(DTensorSpec) in the export test helper was
permanently modifying global pytree state, causing subsequent
compiled DTensor tests to fail. With DTensorSpec registered as a
pytree constant, dynamo no longer decomposes glu into simpler ops
that have sharding strategies, so aten.glu.default gets passed
through to DTensor dispatch which can't handle it.

Wrap in try/finally to deregister after use.

Introduced in PR #163609

Authored with Claude.

register_constant(DTensorSpec) in the export test helper was
permanently modifying global pytree state, causing subsequent
compiled DTensor tests to fail. With DTensorSpec registered as a
pytree constant, dynamo no longer decomposes glu into simpler ops
that have sharding strategies, so aten.glu.default gets passed
through to DTensor dispatch which can't handle it.

Wrap in try/finally to deregister after use.

Authored with Claude.

[ghstack-poisoned]
@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Mar 2, 2026
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 2, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/176128

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit a309060 with merge base b4c6054 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

aorenste added a commit that referenced this pull request Mar 2, 2026
register_constant(DTensorSpec) in the export test helper was
permanently modifying global pytree state, causing subsequent
compiled DTensor tests to fail. With DTensorSpec registered as a
pytree constant, dynamo no longer decomposes glu into simpler ops
that have sharding strategies, so aten.glu.default gets passed
through to DTensor dispatch which can't handle it.

Wrap in try/finally to deregister after use.

Authored with Claude.

ghstack-source-id: e159e65
Pull Request resolved: #176128
@aorenste aorenste requested a review from SherlockNoMad March 2, 2026 02:31
@aorenste
Copy link
Contributor Author

aorenste commented Mar 3, 2026

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 3, 2026
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

RohitRathore1 added a commit to RohitRathore1/pytorch that referenced this pull request Mar 9, 2026
… export

Fixes pytorch#175467. torch.export.export() with strict=False failed on
tensor-parallel DTensor models because DTensorSpec is not a registered
pytree type. In _emit_flat_apply_call, to_graphable() calls
tree_flatten which leaves DTensorSpec as a non-graphable leaf.

Globally registering DTensorSpec as a pytree constant is not viable
because it changes dynamo decomposition behavior, breaking other DTensor
ops like glu and rsub (see pytorch#176128).

Instead, scope the registration tightly: in _emit_flat_apply_call,
scan for non-graphable types not already in SUPPORTED_NODES, temporarily
register them as pytree constants for the tree_flatten call, then
immediately deregister them. This fixes export without polluting global
pytree state.
pytorchmergebot pushed a commit to RohitRathore1/pytorch that referenced this pull request Mar 10, 2026
… export

Fixes pytorch#175467. torch.export.export() with strict=False failed on
tensor-parallel DTensor models because DTensorSpec is not a registered
pytree type. In _emit_flat_apply_call, to_graphable() calls
tree_flatten which leaves DTensorSpec as a non-graphable leaf.

Globally registering DTensorSpec as a pytree constant is not viable
because it changes dynamo decomposition behavior, breaking other DTensor
ops like glu and rsub (see pytorch#176128).

Instead, scope the registration tightly: in _emit_flat_apply_call,
scan for non-graphable types not already in SUPPORTED_NODES, temporarily
register them as pytree constants for the tree_flatten call, then
immediately deregister them. This fixes export without polluting global
pytree state.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants