Fix count_used_parameters_in_backward crash on PyTorch < 2.3 (#7756)#7849
Draft
harshang03 wants to merge 1 commit intodeepspeedai:masterfrom
Draft
Fix count_used_parameters_in_backward crash on PyTorch < 2.3 (#7756)#7849harshang03 wants to merge 1 commit intodeepspeedai:masterfrom
harshang03 wants to merge 1 commit intodeepspeedai:masterfrom
Conversation
…edai#7756) The function asserted the presence of internal PyTorch APIs (_get_grad_fn_or_grad_acc, _current_graph_task_id, _will_engine_execute_node) that only exist in PyTorch >= 2.3. On older builds (e.g. 2.1.2), the assert fired unconditionally inside gradient hooks, crashing training with ZeRO stage 1/2/3. Changes: - runtime/utils.py: Replace the hard assert with a graceful fallback that counts all grad-requiring parameters (conservative upper bound) when internal APIs are unavailable. - runtime/engine.py: Enable _support_torch_style_backward for all ZeRO optimizers regardless of PyTorch version, since the fallback counting is safe and correct. Remove unused import. - base_optimizer.py: No changes needed (already handles missing APIs in queue_post_backward_callback). - tests/: Add comprehensive test suite covering fallback behaviour, native path, edge cases, and API availability checks. Fixes deepspeedai#7756 Signed-off-by: Harshang Akabari <a.harshang@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
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.
The function asserted the presence of internal PyTorch APIs (_get_grad_fn_or_grad_acc, _current_graph_task_id, _will_engine_execute_node) that only exist in PyTorch >= 2.3. On older builds (e.g. 2.1.2), the assert fired unconditionally inside gradient hooks, crashing training with ZeRO stage 1/2/3.
Changes:
Fixes #7756