Repository navigation
Preserve shared modules in regional compilation - #4389
Open
AaravMehta-07 wants to merge 1 commit into
Open
AaravMehta-07 wants to merge 1 commit into
AaravMehta-07 wants to merge 1 commit into
Conversation
Traverse every registered child and reuse each original module's compiled result so aliases and tied repeated blocks keep their identity. Cover sibling aliases, shared blocks and descendants with forward and gradient checks. Co-authored-by: OpenAI Codex Signed-off-by: Aarav <211792885+AaravMehta-07@users.noreply.github.com>
Author
|
Hi maintainers, whenever you have a chance, I'd appreciate a review of this fix for preserving shared module aliases during regional compilation. Five focused CPU tests passed locally; five hardware-gated cases were skipped. Forward and gradient checks are included, without claiming hardware coverage. Please let me know if you'd prefer a different approach or additional focused coverage. Thank you for your time. AI-assisted follow-up. |
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.
What does this PR do?
Preserve shared module registrations in
compile_regions.When a model contains repeated blocks, regional compilation rebuilds its module hierarchy. The rebuild iterates through
named_children(), which deduplicates shared children. If a child is registered under two names, the second registration disappears from the compiled model and a forward pass that uses that name raisesAttributeError. Separately, a block registered at multiple positions or under different parents receives different compiled wrappers, breaking module identity even though the original model shares the module.This change traverses all registered children and caches the result for each original module within one
compile_regionscall. Aliased names, repeated block references, and shared descendants then reference the same rebuilt or compiled module. RegisteredNonechildren are retained as well. The source hierarchy is not rewritten, and the existing regional compilation boundaries are unchanged.No runtime dependencies are added. This does not change the in-place FSDP2 or DeepSpeed paths.
Reproduction
Validation
Windows, Python 3.11.9, PyTorch 2.13.0+cpu, pytest 8.4.2. Tests use the real repository implementation and
torch.compile(..., backend="eager"), without checkpoint downloads.4ebc726849a2d7f03c16198847c22954e224dd87and pass after this change.python -m pytest tests/test_compile.py -v: 5 passed, 5 skipped. The existing model/performance tests are explicitly skipped by their upstream decorator.python -m pytest tests/test_utils.py -k extract_model -v: 3 passed, 1 skipped, 48 deselected.git diff --checkpassed.The full suite, GPU backends, Inductor code generation, distributed execution, and performance were not validated locally. The eager backend verifies the compilation wrapping and real forward/backward behavior, not hardware speedups.
Before submitting
AI disclosure: this patch, regression tests, and description were prepared by a Codex coding agent. The agent ran the reported validation. This disclosure does not represent the work as unaided human authorship or claim human review or maintainer approval.