[PyTorch] Fix deferred initialization in fusible ops - #3327
Conversation
Ops replace their params when materializing them on the first fuser forward pass, which invalidated the fuser's cached params and ops.Linear's parameter aliases. Backward then failed with a meta-vs-cuda device mismatch. - Re-cache the basic ops' params after first-forward materialization - Run first-forward initialization on the top-level ops, before the cached params are used to pick which ops require backward - Sync ops.Linear weight/bias aliases with its basic ops - Add deferred initialization tests for the affected ops Fixes NVIDIA#3322 Signed-off-by: Alp Dener <adener@nvidia.com>
Greptile SummaryThe PR fixes deferred initialization for PyTorch fusible operations by initializing top-level operations before backward selection, refreshing cached basic-operation parameters after materialization, and synchronizing
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or non-blocking defects identified in the changed paths. First-forward initialization now reaches nested basic operations, synchronizes wrapper aliases, and refreshes the parameter cache before backward eligibility and fusion planning consume it. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Fuser as OperationFuser
participant Basic as Basic operations
participant Top as Top-level operations
participant Autograd
User->>Fuser: First forward
Fuser->>Basic: reset_recipe_state(recipe)
Fuser->>Top: pre_first_fuser_forward()
Top->>Basic: materialize meta parameters
Top->>Top: synchronize parameter aliases
Fuser->>Basic: cache materialized parameters
Fuser->>Fuser: select and build forward/backward fusions
Fuser->>Autograd: execute with refreshed parameters
Autograd-->>User: outputs and parameter gradients
Reviews (1): Last reviewed commit: "[PyTorch] Fix deferred initialization in..." | Re-trigger Greptile |
|
/te-ci pytorch |
Description
Ops replace their params when materializing them on the first fuser forward pass, which invalidated the fuser's cached params and ops.Linear's parameter aliases. Backward then failed with a meta-vs-cuda device mismatch.
te.ops.Linearweight/bias aliases with its basic opsFixes #3322
Type of change
Checklist: