[PyTorch] Pair delayed-scaling FP8 recompute metadata per module - #3394
[PyTorch] Pair delayed-scaling FP8 recompute metadata per module#3394nvegesna-netizen wants to merge 3 commits into
Conversation
The delayed-scaling stash and its two restore sites made independent decisions. Module mode changes between the original forward and checkpoint replay could therefore leak a stash or restore one that was never created. Track pending stashes per module and record whether each prepare_forward call swapped one in, so end_forward performs exactly the matching restore. Stash every delayed-scaling FP8 module encountered in checkpoint phase 1: in reentrant checkpointing the original forward runs under no_grad, so an eval module receiving an intermediate tensor has no module-local autograd signal even though backward will replay it. Tests cover training and eval modules, both checkpoint implementations, mode changes in both directions, repeated iterations, multi-module reentrant replay, and exact FIFO drainage. Signed-off-by: Nitin Vegesna <nvegesna@nvidia.com>
Greptile SummaryThe PR adjusts delayed-scaling FP8 activation-recompute bookkeeping so checkpointed modules stash metadata independently of training mode and avoids creating unreachable recompute state when autograd is disabled.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[TE checkpoint invocation] --> B{Autograd enabled?}
B -- No --> C[Enter user forward context]
C --> D[Run function directly]
B -- Yes --> E[Checkpoint phase 1]
E --> F[Each delayed-scaling FP8 module stashes metadata]
F --> G[Backward requests recompute]
G --> H[Checkpoint phase 2]
H --> I[Module consumes matching FIFO metadata]
I --> J[Forward completes and live metadata is restored]
Reviews (2): Last reviewed commit: "Bypass FP8 recompute bookkeeping without..." | Re-trigger Greptile |
|
After a longer discussion with Codex, we came to the following conclusion:
What do you think? |
Signed-off-by: Nitin Vegesna <nvegesna@nvidia.com>
Signed-off-by: Nitin Vegesna <nvegesna@nvidia.com>
Description
Fix delayed-scaling FP8 metadata stash/restore pairing when a checkpointed module is in eval mode or changes mode between the original forward and recompute forward.
The original forward stashed metadata only when
self.trainingwas true, while recompute restored metadata from every FP8 module in the recompute phase. An eval module could therefore try to restore a stash it never created. Conversely, deriving the two decisions independently makes mode changes capable of leaking or mispairing FIFO entries.Each module now records its pending recompute stashes and whether the current invocation actually restored one. Every delayed-scaling FP8 module in checkpoint phase 1 stashes: reentrant checkpointing runs that forward under
no_grad, so an eval module receiving an intermediate tensor has no reliable module-local autograd signal even though backward will replay it. Phase 2 consumes only a stash recorded by that module, andend_forwardrestores live metadata only after a matching consume.Type of change
Changes
no_grad.Validation
module/base.pyproduces the expected eval-module and reentrant-intermediate failures.Checklist: