Minor fix constant amax repr#1935
Conversation
Constant-amax quantizers intentionally omit the _amax buffer, but the representation treated every missing buffer as runtime-dynamic. Format the same E4M3 maximum used by the quantization path so diagnostics describe the active behavior. Constraint: Preserve true dynamic, static scalar, per-channel, and MX-format representations Rejected: Register a synthetic _amax buffer | would change quantizer state and calibration semantics for a display-only fix Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep constant-amax reporting derived from the value used by _get_amax Tested: tests/unit/torch/quantization/test_print.py (6 passed); focused Ruff, format, mypy, license, and Bandit hooks Not-tested: Full ModelOpt unit suite Signed-off-by: Meng Xin <mxin@nvidia.com>
A numeric value alone distinguishes constant mode from dynamic mode, but not from a stored calibrated scalar. Append a const marker so logs communicate both the effective value and its source without using per-channel bracket notation. Constraint: Preserve the existing per-channel [min, max](count) representation Rejected: Wrap the scalar in brackets | brackets already denote tensor ranges in quantizer diagnostics Confidence: high Scope-risk: narrow Reversibility: clean Tested: tests/unit/torch/quantization/test_print.py (6 passed); focused Ruff, format, mypy, license, and Bandit hooks Not-tested: Full ModelOpt unit suite Signed-off-by: Meng Xin <mxin@nvidia.com>
|
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. |
📝 WalkthroughWalkthroughAdds a new conditional branch in ChangesConstant amax repr
Estimated code review effort: 1 (Trivial) | ~3 minutes Suggested reviewers: Quantization module maintainers familiar with 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1935 +/- ##
==========================================
- Coverage 77.69% 77.08% -0.61%
==========================================
Files 517 517
Lines 57535 57537 +2
==========================================
- Hits 44699 44350 -349
- Misses 12836 13187 +351
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
modelopt/torch/quantization/nn/modules/tensor_quantizer.py (1)
1202-1213: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUpdate docstring to document the constant-amax case.
The docstring's return list omits the new
(const)format now returned when_use_constant_amaxis set.📝 Suggested docstring update
def _short_amax(self, fmt=".2e"): """Short description of amax. Returns: 'dynamic': if _amax is not registered 'amax': if _amax is per-tensor '[min, max](size)': if _amax is per-channel + 'value(const)': if a constant amax is used (e.g. KV cache quantization) """🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@modelopt/torch/quantization/nn/modules/tensor_quantizer.py` around lines 1202 - 1213, The _short_amax method’s docstring is missing the constant-amax return case now handled by the _use_constant_amax branch. Update the return description in tensor_quantizer.TensorQuantizer._short_amax to document that it can return a constant-amax string with the “(const)” suffix, alongside the existing dynamic/per-tensor/per-channel cases, so the docstring matches the actual behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@modelopt/torch/quantization/nn/modules/tensor_quantizer.py`:
- Around line 1202-1213: The _short_amax method’s docstring is missing the
constant-amax return case now handled by the _use_constant_amax branch. Update
the return description in tensor_quantizer.TensorQuantizer._short_amax to
document that it can return a constant-amax string with the “(const)” suffix,
alongside the existing dynamic/per-tensor/per-channel cases, so the docstring
matches the actual behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 8fbe8244-001c-42da-bf64-e143ab8c72e6
📒 Files selected for processing (2)
modelopt/torch/quantization/nn/modules/tensor_quantizer.pytests/unit/torch/quantization/test_print.py
What does this PR do?
Type of change: ?
The constant amax in kv cache is showing
dynamicwhich is confusing, making it show the "value(const)".Usage
# Add a code snippet demonstrating how to use thisTesting
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.).CONTRIBUTING.md: ✅ / ❌ / N/AAdditional Information
Summary by CodeRabbit
Bug Fixes
Tests