Skip to content

Speed up the hf_ptq example tests - #2727

Merged
shengliangxu merged 2 commits into
mainfrom
chenjiel/speed-up-hf-ptq-example-tests
Oct 9, 2026
Merged

shengliangxu merged 2 commits into
mainfrom
chenjiel/speed-up-hf-ptq-example-tests

Conversation

@cjluo-nv

@cjluo-nv cjluo-nv commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Type of change: Test infrastructure / CI time, plus an import-time fix in modelopt

trtllm (hf_ptq) is the slowest example job. I profiled it in the CI image (TRT-LLM 1.3.0rc20, one RTX PRO 6000). A TinyLlama fp8 test with the TRT-LLM deploy step does about 15s of real work. The rest is Python startup in three processes and coverage tracing. This PR makes three changes:

  1. Coverage via sys.monitoring (COVERAGE_CORE=sysmon in _example_tests_runner.yml). CI starts coverage in every example subprocess through COVERAGE_PROCESS_START. On Python 3.12, coverage defaults to its C tracer, which slows the fake-quant generate and the export paths. The same TinyLlama fp8 + deploy run takes 64.8s with no coverage, 103.3s with the C tracer, and 70.5s with sysmon. Both runs cover the same lines: 17,424 in hf_ptq.py and 14,534 in run_tensorrt_llm.py, with none differing. Every example image ships Python 3.12, which sysmon needs.
  2. In-process TRT-LLM executor for deploy smoke tests (TLLM_WORKER_USE_SINGLE_PROCESS=1 in run_hf_ptq_command). For TP1, the LLM API otherwise spawns an MPI worker that imports TRT-LLM again. The TinyLlama deploy step drops from 51s to 31s, and the Qwen3-VL multimodal test from 184s to 116s. Generated outputs are identical. TP>1 deploys (the nightly multi-GPU cases) still spawn workers. The llm_eval tests share this helper, so their TP1 deploys benefit too.
  3. Look up deepspeed when needed instead of importing it. modelopt/torch/utils/network.py imported deepspeed.runtime.engine at module load, and make_deepspeed_compatible imported deepspeed's ZeROOrderedDict on every mtq.quantize. A DeepSpeedEngine or ZeROOrderedDict can only exist once its module is imported, so both now look the class up in sys.modules. hf_ptq.py startup drops from 18.4s to 13.8s, and run_tensorrt_llm.py from 20.6s to 17.4s. Every process that imports modelopt saves this time.

Results

I ran the full tests/examples/hf_ptq lane in the CI image with CI's coverage settings on one GPU, on top of #2596:

before after
pytest 26:51 14:31
PTQ tests, total (excluding one extension build that CI caches) 1480s 824s
TinyLlama tests with TRT-LLM deploy 147–151s 68s
TinyLlama tests without deploy 54–71s 34–51s
Mixtral fp8 168s 92s

The same tests took about twice as long per test on the CI runners as on this machine. The absolute savings in CI should therefore be larger.

Usage

N/A (CI/test infrastructure; no API change)

Testing

  • Full tests/examples/hf_ptq lane, before and after (as above). 217 tests passed in both runs. The two test_qwen_vl cases failed in both, because the container had no HF_TOKEN for the gated default calibration dataset. I ran the same VLM fp8 command with cnn_dailymail, with and without the flag. Both passed with identical generated text.
  • llm_eval. I ran test_qwen3_eval_fp8's command (MMLU, lm_eval, simple_eval via trtllm-serve) through run_hf_ptq_command with cnn_dailymail calibration, for the same gated-dataset reason. It passes.
  • New unit tests for the deepspeed lookups, using stand-in modules: tests/unit/torch/utils/test_network.py and tests/unit/torch/quantization/plugins/test_transformers_deepspeed.py.
  • Unit suites. tests/unit/torch/{utils,opt,quantization/plugins,distill} pass serially in the CI image. Under -n 16, a different handful of tests fails on each run, on both main and this branch.
  • pre-commit on the changed files.
  • Not run: the nightly 2-GPU cases. Their TP2 deploy path is unchanged.

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: N/A (CI/test infrastructure and an import-time improvement)
  • Did you get Claude approval on this PR?: ❌ (not yet run)

Additional Information

This PR is independent of #2596, which trims the hf_ptq test cases. The two touch different files and can merge in either order.

Considered and not done:

  • Swap TinyLlama-1.1B for Qwen3-0.6B. This was slower on every case I tried (+4s to +34s per test). At batch 1, test time scales with module count, and Qwen3-0.6B has more modules (28 layers and 706 quantizers vs 22 and 556). Its 152k vocabulary also makes the auto batch-size probe take 16s instead of 0.5s. Its 40,960-token max_position_embeddings makes the TRT-LLM deploy reserve 9.5GB instead of 2.5GB.
  • Synthetic 2-layer Llama. Saves another 12–15s per test, but loses real weights and a real tokenizer.
  • pytest-xdist. Most per-test time is single-threaded startup, so tests should parallelize well. Two things need to change first:
    • The batch-size probe sizes its batch to fill the GPU's free memory, so calib_batch_size would need pinning.
    • Each test would need its own save directory.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • DeepSpeed compatibility handling now works when DeepSpeed is already loaded, without importing it automatically. Model unwrapping also recognizes loaded DeepSpeed engines.
    • Example Hugging Face PTQ commands now run with single-process TensorRT-LLM worker mode enabled.
  • Tests
    • Added coverage for DeepSpeed compatibility and model unwrapping, including behavior when DeepSpeed is not loaded.
  • Chores
    • Example coverage runs use the sysmon tracer with Python 3.12 or later.

cjluo-nv and others added 2 commits October 9, 2026 20:08
modelopt.torch.utils.network imported deepspeed.runtime.engine at module load
to register DeepSpeedEngine as a wrapper, and make_deepspeed_compatible
imported deepspeed's ZeROOrderedDict on every mtq.quantize call. Importing
deepspeed takes ~5s, so every process that imports modelopt paid for it,
used or not.

A DeepSpeedEngine or ZeROOrderedDict can only exist once its module is
imported, so look the class up in sys.modules when it is needed. This cuts
hf_ptq.py startup from 18.4s to 13.8s, and the TRT-LLM deploy script's from
20.6s to 17.4s.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Chenjie Luo <[email protected]>
- Run single-GPU TRT-LLM deploys' executor in-process
  (TLLM_WORKER_USE_SINGLE_PROCESS=1). By default the LLM API spawns an MPI
  worker that imports TRT-LLM again: ~20s per TinyLlama deploy and ~68s per
  Qwen3-VL multimodal deploy, with identical generated outputs.
- Collect example-test coverage with sys.monitoring (COVERAGE_CORE=sysmon).
  The default C tracer slowed a TinyLlama fp8 + deploy run from 65s to 103s;
  sysmon takes 70s and records the same lines.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Chenjie Luo <[email protected]>
@cjluo-nv
cjluo-nv requested review from a team as code owners October 9, 2026 20:10
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/Model-Optimizer/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 10fe0ef4-68da-461b-b50d-7f9118cff2f8

📥 Commits

Reviewing files that changed from the base of the PR and between 24d6964 and 8b96222.


📒 Files selected for processing (6)
  • .github/workflows/_example_tests_runner.yml
  • modelopt/torch/quantization/plugins/transformers.py
  • modelopt/torch/utils/network.py
  • tests/_test_utils/examples/run_command.py
  • tests/unit/torch/quantization/plugins/test_transformers_deepspeed.py
  • tests/unit/torch/utils/test_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

Walkthrough

DeepSpeed integration now checks already-loaded modules before using DeepSpeed types in quantization and network utilities. Example test setup changes the coverage core and passes a worker environment variable to the Hugging Face PTQ command.

Changes

Dynamic DeepSpeed integration

Layer / File(s) Summary
Quantizer parameter compatibility
modelopt/torch/quantization/plugins/transformers.py, tests/unit/torch/quantization/plugins/test_transformers_deepspeed.py
make_deepspeed_compatible uses ZeROOrderedDict from the loaded parameter-offload module when available. Tests cover both module-present and module-absent cases.
Dynamic DeepSpeed model unwrapping
modelopt/torch/utils/network.py, tests/unit/torch/utils/test_network.py
Network utilities discover DeepSpeedEngine from the loaded runtime module for model unwrapping and name detection. A test verifies both behaviors with a stub module.

Example test environment

Layer / File(s) Summary
Example test environment settings
.github/workflows/_example_tests_runner.yml, tests/_test_utils/examples/run_command.py
The test workflow sets COVERAGE_CORE to sysmon. The Hugging Face PTQ command receives a copied environment with TLLM_WORKER_USE_SINGLE_PROCESS=1.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other


Merge Risk: ⚪ Minimal · up to 8b962

This change speeds up example tests and delays DeepSpeed loading. I found no concrete merge-blocking risk.

Pre-merge checks | Passed 5 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 5 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main objective: reducing runtime for the hf_ptq example tests.
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 No listed security anti-pattern is introduced. The changed modelopt Python files only replace eager DeepSpeed imports with sys.modules lookups. The diff adds no unsafe torch.load, `numpy.load(...,…

Full details: Docstring Coverage

Explanation

Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 5 files. (1 skipped: 1 unsupported.)



  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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 9, 2026 •

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

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.21%. Comparing base (24d6964) to head (8b96222).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2727      +/-   ##
==========================================
+ Coverage   71.67%   78.21%   +6.53%     
==========================================
  Files         644      644              
  Lines       71470    71477       +7     
==========================================
+ Hits        51225    55903    +4678     
+ Misses      20245    15574    -4671     
Flag Coverage Δ
examples-diffusers 20.24% <84.21%> (-0.01%) ⬇️
examples-gpt-oss 13.47% <21.05%> (+<0.01%) ⬆️
examples-hf_ptq 23.35% <84.21%> (-0.05%) ⬇️
examples-llm_distill 13.55% <21.05%> (+0.02%) ⬆️
examples-llm_eval 17.28% <78.94%> (-0.03%) ⬇️
examples-llm_qat 17.58% <84.21%> (+0.05%) ⬆️
examples-llm_sparsity 15.81% <68.42%> (-0.04%) ⬇️
examples-megatron_bridge 26.48% <84.21%> (-0.14%) ⬇️
examples-specdec_bench 13.25% <21.05%> (+<0.01%) ⬆️
examples-speculative_decoding 17.57% <84.21%> (-0.09%) ⬇️
examples-torch_onnx 21.63% <78.94%> (+0.02%) ⬆️
examples-torch_trt 15.25% <78.94%> (+0.02%) ⬆️
examples-vllm_serve 13.92% <21.05%> (+0.02%) ⬆️
gpu 59.07% <94.73%> (+25.54%) ⬆️
regression 15.10% <63.15%> (+0.01%) ⬆️
unit 59.87% <94.73%> (+0.01%) ⬆️

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 (bedrock-claude-opus-5-5) — DM the bot to share feedback.

Approving: the three speedups look correct, the deepspeed change keeps the same behaviour, and the new unit tests cover both lookup paths.

No action needed:

  • _supported_wrappers() returns the same SUPPORTED_WRAPPERS dict, so the in-place registration in mcore_dist_checkpointing.py (SUPPORTED_WRAPPERS[Float16Module] = "module") still works. The test patches a copy of the dict, so the global isn't polluted.
  • Engines and ZeRO-3 dicts only exist after their deepspeed modules are imported, so looking them up in sys.modules matches the old import-or-skip behaviour. Nothing else in the repo imports DeepSpeedEngine from network.py.
  • Passing env= to run_example_command turns off the in-process runner. That runner is only registered by the megatron_bridge conftest, so hf_ptq and llm_eval are unaffected.
  • The TP>1 nightly cases weren't run. The PR says TLLM_WORKER_USE_SINGLE_PROCESS only affects TP1 executors in TRT-LLM, but I couldn't check that against the TRT-LLM source. Watch the next 2-GPU nightly.
  • Tests were read, not run. No existing tests were changed. The new test file's header matches the standard NVIDIA header.
  • Overlap: this touches tests/_test_utils/examples/run_command.py and the shared example runner workflow, which other open hf_ptq PRs also use (#2586 path move, #2596). Expect small rebases, though the PR says it's independent of #2596.

Complex PR: 1 existing test file modified or removed. Looping in a human for approval.

@shengliangxu shengliangxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@shengliangxu
shengliangxu merged commit 4c1f813 into main Oct 9, 2026
58 checks passed
@shengliangxu
shengliangxu deleted the chenjiel/speed-up-hf-ptq-example-tests branch October 9, 2026 23:23
cjluo-nv added a commit that referenced this pull request Oct 13, 2026
…2771)

### What does this PR do?

Type of change: Test infrastructure / CI time

Follow-up to #2727. A TinyLlama `hf_ptq` example test spends most of its
time on single-threaded Python startup and export while the GPU sits
idle: only ~15s of a ~65s fp8 + deploy test is GPU work. PR runs of
`trtllm (hf_ptq)` now run the tests in 4 pytest-xdist workers on the
runner's one GPU. A shared/exclusive file lock
(`tests/_test_utils/examples/gpu_lock.py`) controls which tests may
share it:

- **TinyLlama tests (`shared_gpu`) share the GPU.** Each gets a fixed
calibration batch size equal to its calibration size, which is what the
probe already chose. Without one, `hf_ptq.py` probes for a batch size by
running a forward pass sized to fill all free GPU memory.
- **T5, Mixtral and Qwen3-VL (`exclusive_gpu`) run alone.** The Qwen3-VL
deploy (TRT-LLM's `quickstart_multimodal.py`) reserves 60% of free GPU
memory for KV cache; measured at 60 GiB on a 96 GiB GPU.
- **A waiting exclusive test holds back new shared tests**, so it starts
as soon as the tests already on the GPU finish, not after all of them.
- **The lock is taken in fixture setup.** `timeout_func_only` keeps the
wait outside the per-test timeout. It is a no-op without xdist, and
`flock` releases it if a worker dies.

Each test also gets its own `ROOT_SAVE_PATH`. `huggingface_example.sh`
names a checkpoint directory from the model and format alone. Runs that
differ only in KV format, TP or PP therefore shared one directory, and
the later run found `config.json` and skipped PTQ. Concurrently, they
would race.

`-n 4` applies to `hf_ptq` PR runs only; the 2-GPU nightly stays serial.
`pytest-xdist` is declared in `dev-test`; CI only had it so far because
the TRT-LLM image ships it. `uv.lock` adds only its entries. A full `uv
lock` with a different uv version also reorders unrelated markers, so I
kept only the hunks it adds for `pytest-xdist` and `execnet`. The weekly
bump will normalize the rest.

### Usage

N/A (CI/test infrastructure)

### Testing

- **Full `tests/examples/hf_ptq` lane, `-n 4`, one RTX PRO 6000** in
`nvcr.io/nvidia/tensorrt-llm/release:1.3.0rc20` with CI's coverage
settings: 233 passed, 0 failed, 10:25. The Qwen3-VL tests calibrated on
`cnn_dailymail` locally, because there was no `HF_TOKEN` for the gated
default dataset.
- **Lock event log from that run:** no test overlapped an exclusive one.
Each Qwen3-VL test acquired the GPU as soon as the TinyLlama tests
already running finished, and at most 4 tests held it at once.
- **Caveat on that run:** another user's vLLM job (60–75 GB) shared the
GPU throughout. The run passing shows it tolerates having only ~20–35 GB
free. But its memory peaks can't be attributed to these tests, and its
time was measured under contention.
- **Earlier clean run on an idle GPU,** with every test sharing (before
the exclusive lock existed): 871s serial → 312s with `-n 4` (845s → 301s
when pinned to 8 CPU cores). 4 TinyLlama workers peaked at ~19 GB of GPU
memory and ~40 GB of host RAM (28 GB serial). Covered lines were within
0.25%.
- **`tests/examples/hf_ptq/test_gpu_lock.py`** covers shared overlap,
exclusive isolation, and a waiting exclusive holder queuing new shared
ones. Each test fails against a deliberately broken lock: no turnstile,
always shared, or always exclusive.
- **pre-commit** on the changed files.
- **Not run:**
- a clean serial vs `-n 4` comparison with the Qwen3-VL deploys running;
this PR's CI run will be the real measurement;
  - the 2-GPU nightly.

### Before your PR is "*Ready for review*"

- Is this change backward compatible?: ✅
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`: ✅
(`pytest-xdist`, MIT, test-only)
- Did you write any new necessary tests?: ✅
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
N/A (CI/test infrastructure)
- Did you get Claude approval on this PR?: ❌ (not yet run)

### Additional Information

Effects to be aware of:
- **Nightly:** the per-test `ROOT_SAVE_PATH` means the two 2-GPU
`test_ptq_llama` cases now actually run PTQ and deploy on 2 GPUs. Until
now they silently reused the 1-GPU checkpoints. The nightly gets a few
minutes slower and could surface real 2-GPU failures.
- **Disk:** checkpoints move from `examples/hf_ptq/` to pytest's temp
directory, about the same total (~20 GB).
- **Host RAM:** 4 workers peaked around 40 GB in the clean run. I don't
know the runner's RAM.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Some pull-request test runs now execute in parallel, while other test
runs retain their existing behavior.
* GPU-based example tests now coordinate access so compatible tests can
run together while tests requiring exclusive access run separately.
* Added coverage for GPU access coordination and updated quantization
tests to use the appropriate access mode.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Chenjie Luo <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
shengliangxu added a commit that referenced this pull request Oct 17, 2026
Python 3.12 defaults to coverage's C tracer, which slows every line of Python
that runs under it. Every lane starts coverage in each spawned worker and
subprocess through COVERAGE_PROCESS_START, so the import-heavy start-ups pay
for it: the 76 s Megatron worker-pool start, the 22 s hf_ptq processes of the
unified-export tests, the puzzletron spawns, the vLLM engine core.
COVERAGE_CORE=sysmon records the same lines through sys.monitoring at a
fraction of the overhead.

Measured (the first three here, the last by #2727 on its hf_ptq example lane):
- serial tests/unit run on 4 CPUs: 572 s without coverage, 825 s with the C
  tracer, 640 s with sysmon;
- `import modelopt.torch.quantization.extensions` with this repo's coverage
  config: 17.1 s native, 23.6 s with the C tracer, 18.3 s with sysmon, and the
  child process of a spawn writes its data file too, with the same 362 files
  and 13,821 executed lines;
- one TinyLlama fp8 plus TRT-LLM deploy test: 64.8 s without coverage, 103.3 s
  with the C tracer, 70.5 s with sysmon, identical covered lines.

Applies to the unit `linux` job (Python 3.12), gpu_tests.yml and
regression_tests.yml. The example runner is left to #2727, which makes the same
change there. sysmon needs Python 3.12 or newer; on an older interpreter
coverage warns and keeps its default core, so a lane that turns out to run an
older Python is slower, not broken. The gpu and gpu_megatron logs show 3.12.

Testing: actionlint is clean on all workflows. Not yet run on a real CI runner;
the first run should be compared against the previous coverage.xml.

Signed-off-by: Shengliang Xu <[email protected]>
shengliangxu added a commit that referenced this pull request Oct 21, 2026
### What does this PR do?

Type of change: CI (test runtime)

Sets `COVERAGE_CORE=sysmon` on the unit `linux` job, `gpu_tests.yml` and
`regression_tests.yml`. Python 3.12 defaults to coverage's C tracer,
which slows every line of Python run under it, and every lane starts
coverage in each spawned worker and subprocess through
`COVERAGE_PROCESS_START`, so import-heavy start-ups pay for it (the 76 s
Megatron pool start, the 22 s hf_ptq processes of the unified-export
tests, the puzzletron spawns, the vLLM engine core). sysmon records the
same lines through `sys.monitoring`. The example runner is left to
#2727, which makes the same change there. On a Python older than 3.12
coverage warns and keeps its default core, so a lane that turned out to
run an older Python would be slower, not broken (the gpu and
gpu_megatron logs show 3.12).

### Time improvement (measured in CI)

pytest time of each lane in the run of #2845 (the base of this PR) and
in this PR's run, one run each:

| lane | #2845 | this PR | change |
|---|---|---|---|
| gpu | 2,093 s | 1,289 s | -38% |
| gpu_megatron | 2,240 s | 1,212 s | -46% |
| gpu_vllm v0.20.0 | 204 s | 170 s | -17% |
| gpu_vllm v0.30.0 | 426 s | 328 s | -23% |
| regression | 366 s | 268 s | -27% |
| unit `linux` (xdist) | 479 s | 305 s | -36% |

Workflow wall time: GPU tests 59.2 -> 39.6 min, Regression 21.3 -> 15.2
min.

- **How much of that is this PR.** Two single runs of the same code
differ by 15-30% on their own: the eight example lanes that run over 100
s, which this PR does not touch, moved by -4% to -31% (llm_sparsity
+38%) between the same two runs. The deterministic part is the Megatron
worker-pool start, the setup of the first test of each gpu_megatron
module: 75-77 s in each of 14 modules before (all setups of 12 s or more
add up to 1,365 s) and 22-27 s after (575 s), which is 790 s of the
lane's 1,028 s. Locally the unit suite takes 825 s with the C tracer,
640 s with sysmon and 572 s without coverage (4 CPUs, serial).
- **A `coverage.xml`-only report change was dropped from this PR.** The
runs above are of its earlier head, which also had it. It showed no CI
effect: the pytest summary line came 1-4 s after the last test in the
#2845 runs, which still wrote the html report, and 0-3 s in this PR's
runs (median 1.1 s over the 82 lane runs of the series), so the table is
the sysmon core's. It would only have saved developers' local runs
(about 25 s per pytest session).

Method: every PR of the series has its own CI run, so "before" is the
run of the PR(s) below that lack the change and "after" the runs that
carry it. Times come from the job logs (`--durations`, or the gap
between consecutive result lines). Where runner speed matters, the tests
that no PR of the series touches scale each run, and the raw and the
scaled medians are both shown. One test varies by 15-30% from run to run
on its own, so smaller differences are not evidence.

### Usage

Nothing user-facing.

### Testing

Measured on this tree (tests/unit on 4 CPUs serial: 572 s without
coverage, 825 s with the C tracer, 640 s with sysmon; `import
modelopt.torch.quantization.extensions`: 17.1 s native, 23.6 s with the
C tracer, 18.3 s with sysmon, with the same 362 files and 13,821
executed lines in the spawned child's data file; one TinyLlama fp8 plus
TRT-LLM deploy test: 64.8 s without coverage, 103.3 s with the C tracer,
70.5 s with sysmon, identical covered lines). Pre-commit and actionlint
pass. The CI runs of the series are the check on real runners (time
section above).

### Before your PR is "*Ready for review*"

Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)
and your commits are signed (`git commit -s -S`).

Make sure you read and follow the [Security Best
Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors)
(e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(...,
weights_only=False)`, `pickle`, etc.).

- Is this change backward compatible?: N/A (CI and tests)
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`: no new
dependency
- Did you write any new necessary tests?: N/A (CI configuration)
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
N/A (CI and tests)
- Did you get Claude approval on this PR?: N/A (optional, not run)

### Additional Information

Slice 2 of 11 of the GPU-CI speed-up work, split out of the reference
draft #2730 (not for merge; it holds the whole series with its
measurements). Slices 5, 8 and 10 (#2849, #2852, #2854) target main and
merge independently; the other open slices form a stack and merge
bottom-up. Each PR stands on its own and passes CI without the later
ones.

1. #2845 [OMNIML-6178] [1/11] Run the unit tests in parallel with
pytest-xdist (merged)
2. #2846 [OMNIML-6178] [2/11] Use the sysmon coverage core in CI **(this
PR)**
3. #2847 [OMNIML-6179] [3/11] Run manual-marked tests on nightly and
on-demand GPU runs
4. #2848 [OMNIML-6181] [4/11] Give gpu_megatron's slow cold starts more
time
5. #2849 [OMNIML-6179] [5/11] Make the ONNX tests cheaper: CPU-only ones
to the unit lane, small models (targets main)
6. #2850 [OMNIML-6179] [6/11] Use local tokenizers and calibration text
in GPU tests, shrink puzzletron data
7. #2851 [OMNIML-6180] [7/11] Trim the llm_eval, llm_qat, EAGLE and
megatron_bridge example tests
8. #2852 [OMNIML-6180] [8/11] Trim the DFlash regression test (targets
main)
9. #2853 [OMNIML-6180] [9/11] Trim the torch_onnx example lane
10. #2854 [OMNIML-6181] [10/11] Make the distributed worker pool fail
fast when a worker dies (targets main)
11. #2855 [OMNIML-6181] [11/11] Share one Megatron worker pool across
the gpu_megatron modules


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Tests**
* Updated coverage collection for GPU, regression, and Linux unit-test
runs to use Python’s monitoring-based coverage core on supported Python
3.12+ environments.
* This configuration reduces overhead during coverage-enabled test
execution, particularly for import-heavy worker processes.
* No changes to application functionality or public interfaces are
included.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Shengliang Xu <[email protected]>
kevalmorabia97 added a commit that referenced this pull request Oct 28, 2026
### 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](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Keval Morabia <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

3 participants