[Quantization] Fix ModelOpt pre-quantized loading #14188
Open
yzhautouskay wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes loading of pre-quantized ModelOpt models via
from_pretrained(..., device_map=...),which currently crashes with:
Note: this is required for the pre-quantized path to work at all with HF checkpointing enabled —
no combination of
device_map/.to(device)load options works around it without this change.Root cause
For pre-quantized models,
NVIDIAModelOptQuantizer.check_if_quantized_paramreturnedTruefor every tensor. That routes the quantizer buffers ModelOpt recreates on restore
(
_amax,_scale) throughcreate_quantized_param, which assigns them intomodule._parameters. Those buffers are then never materialized by the low-memory loader andstay on the
metadevice, so the later device move fails.Fix
check_if_quantized_param: for pre-quantized models, only claim real parameters(
return tensor_name in module._parameters); buffers fall back to the standard loader, whichmaterializes
_amax/_scaleon their target device.create_quantized_param: guard the pre-quantized branch so a non-parameter reaching itraises clearly instead of silently mis-assigning.
TODO (follow-up)
Add a real regression test: enable
enable_huggingface_checkpointing()before save+load (current tests don't do that), loadthe round-tripped model with
device_map, and assert nometaparams/buffers remain (fails onmain, passes with this fix). Not included here.Environment
Single ModelOpt version on both export and load (ModelOpt state is version-sensitive, so
producer and consumer must match):
diffusers0.40.0.dev0 (this branch)nvidia-modelopt0.44.0 (quantize + load)torch2.9.0a0+145a3a7bda.nv25.10 (NVIDIA NGC container build)Who can review?
<>