Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/diffusers/quantizers/modelopt/modelopt_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def check_if_quantized_param(

module, tensor_name = get_module_from_name(model, param_name)
if self.pre_quantized:
return True
# ModelOpt restoration recreates quantizer state such as `_amax` and
# `_scale` as buffers. Let the regular low-memory loader materialize
# those buffers on their target device. Only parameters need the
# wrapper-aware assignment below.
return tensor_name in module._parameters
elif is_quantized(module) and "weight" in tensor_name:
return True
return False
Expand All @@ -92,6 +96,8 @@ def create_quantized_param(
dtype = kwargs.get("dtype", torch.float32)
module, tensor_name = get_module_from_name(model, param_name)
if self.pre_quantized:
if tensor_name not in module._parameters:
raise ValueError(f"Expected {param_name} to be a parameter in the restored ModelOpt graph.")
module._parameters[tensor_name] = torch.nn.Parameter(param_value.to(device=target_device))
else:
set_module_tensor_to_device(model, param_name, target_device, param_value, dtype)
Expand Down
Loading