Skip to content

Fix vLLM compilation guard for models without marker - #2518

Open
kinjalpatel27 wants to merge 3 commits into
mainfrom
kinjal/vllm_fq_glm
Open

kinjalpatel27 wants to merge 3 commits into
mainfrom
kinjal/vllm_fq_glm

Conversation

@kinjalpatel27

@kinjalpatel27 kinjalpatel27 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

Makes the vLLM disable_compilation context manager support inner model implementations that do not predefine a do_not_compile attribute, including GLM-5.3. The context manager now installs the marker temporarily and removes it afterward, while preserving and restoring existing marker values for other vLLM models.

Adds regression coverage for both supported wrapper layouts: model.model and model.language_model.model.

Usage

with disable_compilation(model):
    mtq.quantize(model, quant_cfg, forward_loop=calibrate_loop)

No caller changes are required.

Testing

  • Ran tests/gpu_vllm/torch/quantization/test_vllm_dynamic_modules.py: 24 passed with vLLM 0.28.
  • Ran pre-commit on both changed files: all applicable hooks passed.
  • Installed this branch into vllm/vllm-openai:glm53-flash on OCI-JHB and served the GLM-5.3-Flash BF16 checkpoint with QUANT_CFG=NVFP4_DEFAULT_CFG, TP=4, eager mode, and BF16 KV cache.
  • GLM passed the previous do_not_compile failure point, inserted 1,700 quantizers, enabled 456 weight quantizers, reached a healthy API server, and returned a relevant manual prompt response.

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • 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 — integration compatibility fix; no user-facing API change.
  • Did you get Claude approval on this PR?: N/A

Additional Information

Validated against GLM-5.3-Flash using ModelOpt commit 869b64fcee0b20be323663449b00e8c52940a289.

Summary by CodeRabbit

  • Bug Fixes

    • Compilation disabling now supports multiple wrapped model configurations.
    • Existing compilation settings are restored when the context ends, including after errors.
    • Temporary settings are removed when no prior setting exists.
    • Models without a compilation setting proceed with a warning; invalid model shapes raise a clear error.
  • Tests

    • Added coverage for nested models, setting precedence, cleanup, restoration, warnings, and error handling.

Signed-off-by: Kinjal Patel <kinjalpravin@nvidia.com>
@kinjalpatel27
kinjalpatel27 requested review from a team as code owners September 23, 2026 00:36
@coderabbitai

coderabbitai Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 72f8d0f9-5aab-4758-895d-d7ae16d96387

📥 Commits

Reviewing files that changed from the base of the PR and between 19ded37 and 3444797.

📒 Files selected for processing (1)
  • tests/gpu_vllm/torch/quantization/test_vllm_dynamic_modules.py

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


📝 Walkthrough

Walkthrough

disable_compilation resolves supported vLLM wrapper layouts and manages the do_not_compile marker for the context. Tests cover missing markers, marker precedence, cleanup, and exception handling.

Changes

vLLM compilation handling

Layer / File(s) Summary
Compilation marker lifecycle
modelopt/torch/quantization/plugins/vllm.py, tests/gpu_vllm/torch/quantization/test_vllm_dynamic_modules.py
The context manager resolves a supported target, temporarily sets do_not_compile, warns when the marker is missing, and restores or removes the marker on exit. Tests cover the language_model.model wrapper, outer-marker precedence, and cleanup after exceptions.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: aanoosheh

Merge Risk: ⚪ Minimal · up to 34447

No concrete issue remains that should prevent merging after normal checks.

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. 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 change: fixing the vLLM compilation guard for models that lack the marker.
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 was introduced. The PR changes only modelopt/torch/quantization/plugins/vllm.py and one test file. Added-line scanning found no unsafe torch.load, `numpy.load(..., …
✨ 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

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

@kinjalpatel27

Copy link
Copy Markdown
Contributor Author

/claude review

@github-actions

github-actions Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://NVIDIA.github.io/Model-Optimizer/pr-preview/pr-2518/

Built to branch gh-pages at 2026-09-23 18:42 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Comment thread modelopt/torch/quantization/plugins/vllm.py Outdated

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude review summary

Scope: full review — 2 changed files (35 additions / 10 deletions): modelopt/torch/quantization/plugins/vllm.py and tests/gpu_vllm/torch/quantization/test_vllm_dynamic_modules.py. Both reviewed in full, plus the three disable_compilation call sites (examples/vllm_serve/fakequant_worker.py, examples/vllm_serve/sparse_attn_worker.py, the existing gpu_vllm tests).

Findings — CRITICAL: 0, IMPORTANT: 1, SUGGESTION: 0

Most impactful finding

plugins/vllm.py:249-258[IMPORTANT Compatibility] the save/restore mechanics of this change are correct (exception-safe, nesting-safe, and the tests cover both wrapper layouts and both marker states), but the premise that a vLLM model may legitimately lack do_not_compile doesn't hold: vLLM's support_torch_compile decorator sets that attribute unconditionally in __init__ and is the only reader of it. An object without the marker is therefore not the compile-wrapped module, so installing the marker on it does not disable compilation — it only silences the AttributeError that was telling you the target was wrong.

The risk is a silent no-op where there used to be a loud failure: mtq.quantize then runs with torch.compile active, able to recompile while quantizers are being inserted. The GLM-5.3 run in the description used eager mode, where compilation is off anyway, so it does not distinguish "guard works" from "guard is a no-op". It also makes the language_model branch permanently unreachable (and now silently so) for wrappers that expose both model and language_model.

Suggested direction, in the inline comment: resolve the module that actually owns do_not_compile by searching model / model.model / model.language_model.model, and fall back to installing the marker only with a warnings.warn so the no-op case stays visible. Two minor robustness points are folded in there as well — use "do_not_compile" in vars(target) rather than hasattr so a class-level default isn't permanently shadowed by an instance attribute, and vars(target).pop(..., None) rather than bare del so cleanup can't raise inside finally and mask an exception from the body.

A quick way to confirm or refute on the GLM-5.3 checkpoint: print type(model).__name__, type(model.model).__name__, and which objects along that chain have do_not_compile. If one of them does, the fix is to target it; if none does, the model isn't compile-wrapped and the warning path is the honest behavior.

Risk assessment

Low-to-moderate. Small, well-tested, backward-compatible change that strictly widens what disable_compilation accepts, and the restore semantics are an improvement over the previous version. The concern is not regression for existing models but whether the guard actually guards for the new case it was added for.

Nothing to flag on mode/state composability, export, or performance — the change touches neither modelopt_state nor any export path.

@codecov

codecov Bot commented Sep 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.36%. Comparing base (7159c01) to head (76cf969).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2518      +/-   ##
==========================================
+ Coverage   68.78%   78.36%   +9.57%     
==========================================
  Files         603      605       +2     
  Lines       66796    68396    +1600     
==========================================
+ Hits        45947    53596    +7649     
+ Misses      20849    14800    -6049     
Flag Coverage Δ
unit 58.41% <0.00%> (+0.12%) ⬆️

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.

Signed-off-by: Kinjal Patel <kinjalpravin@nvidia.com>

@cjluo-nv cjluo-nv 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.

Bot review (gpt-6-astra) — DM the bot to share feedback.

Approve: the guard handles missing markers and restores instance or inherited state correctly, with focused regression coverage and no unrelated changes.

No action needed.

Signed-off-by: Kinjal Patel <kinjalpravin@nvidia.com>

This branch has not been deployed

No deployments
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