Preserve gradient checkpointing kwargs during GKD generation - #6827
Preserve gradient checkpointing kwargs during GKD generation#6827DimensionSTP wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2369cb4. Configure here.
| yield accelerator.unwrap_model(model) | ||
| add_hooks(model) | ||
| else: | ||
| yield unwrapped_model |
There was a problem hiding this comment.
Checkpoint restore breaks kwargs-only wrappers
High Severity
Generation unwrap now restores checkpointing through disable_gradient_checkpointing, which calls gradient_checkpointing_enable with a positional dict. Wrappers whose method is keyword-only, including PPO's PolicyAndValueWrapper, raise TypeError on exit whenever checkpointing was enabled. Previously unwrap restored with a no-arg enable() call, so PPO generation with checkpointing worked.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 2369cb4. Configure here.


What does this PR do?
GKD temporarily disables gradient checkpointing while unwrapping the student or teacher model for generation. The previous restoration path called
gradient_checkpointing_enable()without the configuredgradient_checkpointing_kwargs.With reentrant checkpointing under DeepSpeed ZeRO-3, this changes checkpointing behavior between the original forward and backward recomputation. The recomputation can then observe partitioned zero-sized parameters and fail with:
This change:
disable_gradient_checkpointingcontext manager, including exception exits;self.args.gradient_checkpointing_kwargsfrom both GKD generation paths;The GKD objective, generation behavior, and DeepSpeed gathering policy are unchanged.
Verification
pytest -q tests/test_model_utils.py: 7 passedcompileall: passedgit diff --check: passedBefore submitting
AI writing disclosure
Note
Cursor Bugbot is generating a summary for commit 2369cb4. Configure here.