Skip to content

Conversation

@Edwardf0t1
Copy link
Contributor

@Edwardf0t1 Edwardf0t1 commented Jan 16, 2026

What does this PR do?

Type of change: ?

Overview: Enable GLM-4.7 PTQ workflow, including loading the standalone MTP modules and export as-is.

Usage

python3 hf_ptq.py --pyt_ckpt_path /home/omniml_data_3/models/GLM-4.7 --qformat nvfp4_mlp_only --export_path /home/omniml_data_3/zhiyuc/checkpoints/GLM-4.7-NVFP4-0203 --trust_remote_code

Testing

Before your PR is "Ready for review"

  • Make sure you read and follow Contributor guidelines and your commits are signed.
  • Is this change backward compatible?: Yes
  • Did you write any new necessary tests?: Yes/No
  • Did you add or update any necessary documentation?: Yes/No
  • Did you update Changelog?: Yes

Additional Information

Summary by CodeRabbit

  • New Features

    • Added quantization support for GLM-4.7 model with automatic handling of specialized layer architecture.
    • Added image-text data calibration capabilities for Nemotron VL model quantization.
  • Documentation

    • Updated support matrix to reflect newly supported models and quantization features.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Jan 16, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.73%. Comparing base (e024097) to head (5e42017).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #792   +/-   ##
=======================================
  Coverage   73.73%   73.73%           
=======================================
  Files         196      196           
  Lines       20412    20412           
=======================================
  Hits        15050    15050           
  Misses       5362     5362           

☔ View full report in Codecov by Sentry.
📢 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.

calibration_only = True

# Load any missing weights from non-standard safetensors (handled in get_model for non-low-memory mode)
from example_utils import load_mtp_weights_if_needed
Copy link
Collaborator

Choose a reason for hiding this comment

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

please move to the top

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return False

# Load the index to find all referenced safetensors files
with open(index_file) as f:
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: single line: index = json.loads(index_path.read_text())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This single is not really “better” here. json.load(f) is idiomatic and streams from the file object; json.loads(index_file.read_text()) reads the whole file into memory first.

@Edwardf0t1 Edwardf0t1 force-pushed the zhiyu/glm-4.7-mtp-support branch from ac6b609 to 39c6195 Compare February 4, 2026 00:14
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Adds PTQ support for GLM-4.7 models by implementing utilities to load MTP layer weights from separate files and automatically exclude these layers from quantization during the PTQ process. Includes documentation updates reflecting the new model support.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.rst, examples/llm_ptq/README.md
Added changelog entries and support matrix documentation for GLM-4.7 PTQ support, including footnotes describing MTP layer behavior and exclusion from quantization.
MTP Weight Loading & Integration
examples/llm_ptq/example_utils.py
Introduces load_mtp_weights_if_needed() utility function to inspect safetensors indices, load non-standard weight shards, and identify MTP layer prefixes. Integrates into model initialization in get_model() to attach discovered prefixes to the model instance.
Quantization Config Exclusion
examples/llm_ptq/hf_ptq.py, modelopt/torch/export/unified_export_hf.py
Reads MTP layer prefixes and constructs exclusion patterns in quantization configuration to prevent these layers from being quantized during PTQ processing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'GLM-4.7 MTP support' directly describes the main change: adding support for GLM-4.7's MTP (Modular Tensor Parallel) modules in the PTQ workflow.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch zhiyu/glm-4.7-mtp-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Signed-off-by: Zhiyu Cheng <[email protected]>
Signed-off-by: Zhiyu Cheng <[email protected]>
return False

# Load the index to find all referenced safetensors files
with open(index_file) as f:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This single is not really “better” here. json.load(f) is idiomatic and streams from the file object; json.loads(index_file.read_text()) reads the whole file into memory first.

calibration_only = True

# Load any missing weights from non-standard safetensors (handled in get_model for non-low-memory mode)
from example_utils import load_mtp_weights_if_needed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

- Add ``--opset`` option to ONNX quantization CLI to specify the target opset version for the quantized model.
- Add support for context parallelism in Eagle speculative decoding for huggingface and megatron core models.
- Add PTQ support for GLM-4.7, including loading MTP layer weights from a separate ``mtp.safetensors`` file and export as-is.
- Add support for image-text data calibration in PTQ for Nemotron VL models.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is added for this PR: #755

@Edwardf0t1 Edwardf0t1 marked this pull request as ready for review February 4, 2026 01:45
@Edwardf0t1 Edwardf0t1 requested review from a team as code owners February 4, 2026 01:45
break

# Load the weights
weights = load_file(str(filepath))
Copy link
Collaborator

Choose a reason for hiding this comment

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

then maybe do device="cpu" here?

@Edwardf0t1 Edwardf0t1 self-assigned this Feb 4, 2026
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