Skip to content

[0.48.0] Narrow bare except around optional deepspeed import - #3090

Merged
kevalmorabia97 merged 1 commit into
release/0.48.0from
cherry-picks/release-0.48.0-network-except
Oct 28, 2026
Merged

kevalmorabia97 merged 1 commit into
release/0.48.0from
cherry-picks/release-0.48.0-network-except

Conversation

@kevalmorabia97

@kevalmorabia97 kevalmorabia97 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Type of change: Bug fix (release branch only)

modelopt/torch/utils/network.py wrapped the optional deepspeed import in a bare except:, which also swallowed SystemExit and KeyboardInterrupt during import modelopt (SonarQube python:S5754 on release/0.48.0). It now catches Exception. ImportError alone is not enough: deepspeed can fail at import with other errors (e.g. CUDA/op-builder checks), and those should keep falling back to "no deepspeed" rather than break import modelopt.

main no longer has this code: #2727 replaced the import with a sys.modules lookup as part of a larger CI speed-up PR, so this is a minimal release-only equivalent instead of a cherry-pick.

Testing

  • tests/unit/torch/utils/test_network.py: 50 passed.
  • import modelopt.torch.utils.network with deepspeed installed still registers DeepSpeedEngine.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility when DeepSpeed cannot be imported. The application now handles import errors and continues with DeepSpeed unavailable, rather than allowing those errors to interrupt the fallback behavior.

A bare except also swallowed SystemExit and KeyboardInterrupt
(SonarQube python:S5754). main no longer imports deepspeed here (#2727);
this is the minimal equivalent for release/0.48.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Keval Morabia <[email protected]>
@kevalmorabia97
kevalmorabia97 requested a review from a team as a code owner October 28, 2026 20:04
@kevalmorabia97
kevalmorabia97 requested review from AAnoosheh and removed request for a team October 28, 2026 20:04
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 085ae67 and 377cdbe.

Files selected for processing: 1
  • modelopt/torch/utils/network.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

The DeepSpeed import handler now catches Exception instead of using a bare except. The fallback assignment to DeepSpeedEngine remains unchanged.

Changes: DeepSpeed import fallback

Layer / File(s) Summary
DeepSpeed import handling
modelopt/torch/utils/network.py
The import handler catches Exception instead of using a bare except. The fallback assignment to DeepSpeedEngine is unchanged.

Priority: Low

Estimated code review effort: 1 (Trivial) | ~2 minutes

Change: Bug fix

Suggested reviewers: realasma

Merge Risk: Minimal · up to 377cd

No concrete merge-blocking risk was identified in this focused import-handling change.

Pre-merge checks: Passed 6
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately and concisely describes the main change: narrowing exception handling around the optional DeepSpeed import.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns Passed PASS. The pull request changes only modelopt/torch/utils/network.py, replacing except: # noqa: E722 with except Exception and an explanatory comment. It adds no `torch.load(..., weights_only=Fal…
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Full details: Security Anti-Patterns

Explanation

PASS. The pull request changes only modelopt/torch/utils/network.py, replacing except: # noqa: E722 with except Exception and an explanatory comment. It adds no torch.load(..., weights_only=False), numpy.load(..., allow_pickle=True), hardcoded trust_remote_code=True, eval, exec, # nosec, or dependency changes. No listed security anti-pattern is introduced.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2
Preview removed because the pull request was closed.
2026-10-28 21:09 UTC

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.67%. Comparing base (4496cfc) to head (377cdbe).
⚠️ Report is 1 commits behind head on release/0.48.0.

Additional details and impacted files
@@                Coverage Diff                 @@
##           release/0.48.0    #3090      +/-   ##
==================================================
+ Coverage           72.18%   78.67%   +6.49%     
==================================================
  Files                 649      647       -2     
  Lines               72638    72578      -60     
==================================================
+ Hits                52431    57099    +4668     
+ Misses              20207    15479    -4728     
Flag Coverage Δ
examples-diffusers 20.15% <0.00%> (-1.16%) ⬇️
examples-gpt-oss 13.48% <0.00%> (+0.04%) ⬆️
examples-hf_ptq 23.35% <0.00%> (+0.01%) ⬆️
examples-llm_distill 13.54% <0.00%> (+0.04%) ⬆️
examples-llm_eval 17.30% <0.00%> (+0.06%) ⬆️
examples-llm_qat 17.47% <0.00%> (+<0.01%) ⬆️
examples-llm_sparsity 16.91% <0.00%> (+1.10%) ⬆️
examples-megatron_bridge 26.25% <0.00%> (-0.32%) ⬇️
examples-specdec_bench 13.25% <0.00%> (+0.04%) ⬆️
examples-speculative_decoding 17.53% <0.00%> (-0.21%) ⬇️
examples-torch_onnx 21.46% <0.00%> (-0.14%) ⬇️
examples-torch_trt 15.22% <0.00%> (+0.01%) ⬆️
examples-vllm_serve 13.90% <0.00%> (+0.02%) ⬆️
gpu 58.87% <0.00%> (+25.34%) ⬆️
regression 15.07% <0.00%> (+<0.01%) ⬆️
unit 60.95% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@meenchen meenchen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot review (gpt-6.1-sol) — DM the bot to share feedback.

Nudge: the supplied change looks correct, but targeted regression coverage is absent and the requested pinned revisions could not be verified.

Needs action:

  • Add parameterized import regression tests in tests/unit/torch/utils/test_network.py: preserve fallback for ImportError/RuntimeError, propagate SystemExit/KeyboardInterrupt, and retain wrapper registration on success.
  • Confirm the surrounding source and tests against the requested base/head SHAs using SHA-aware retrieval; the available branch-file tools return no commit metadata.
  • Correct the generated PR summary: ordinary import errors already fell back; this change stops swallowing process-control exceptions.

@kevalmorabia97
kevalmorabia97 merged commit 1acc46e into release/0.48.0 Oct 28, 2026
57 checks passed
@kevalmorabia97
kevalmorabia97 deleted the cherry-picks/release-0.48.0-network-except branch October 28, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants