Skip to content
Merged
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
33 changes: 9 additions & 24 deletions src/diffusers/quantizers/autoround/autoround_quantizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
# Copyright 2025 The Intel and The HuggingFace Inc. teams. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,21 +14,14 @@

from typing import TYPE_CHECKING

from ...utils import (
is_auto_round_available,
is_torch_available,
logging,
)
from ...utils import is_auto_round_available, logging
from ..base import DiffusersQuantizer


if TYPE_CHECKING:
from ...models.modeling_utils import ModelMixin


if is_torch_available():
pass

logger = logging.get_logger(__name__)


Expand Down Expand Up @@ -91,10 +84,9 @@ def _process_model_before_weight_loading(
"""
from auto_round.inference.convert_model import convert_hf_model, infer_target_device

if self.pre_quantized:
target_device = infer_target_device(self.device_map)
model, used_backends = convert_hf_model(model, target_device)
self.used_backends = used_backends
target_device = infer_target_device(self.device_map)
model, used_backends = convert_hf_model(model, target_device)
self.used_backends = used_backends

def _process_model_after_weight_loading(self, model, **kwargs):
"""
Expand All @@ -103,22 +95,15 @@ def _process_model_after_weight_loading(self, model, **kwargs):

Uses `auto_round.inference.convert_model.post_init` which:
- Performs backend-specific finalization (e.g. repacking weights into the kernel's expected memory layout,
moving buffers to the correct device).
moving buffers to the correct device).
- Freezes quantized parameters (requires_grad=False).
- Prepares the model for inference.

Raises ValueError if the model is not pre-quantized, since AutoRound does not support on-the-fly quantization
through this loading path.
"""
if self.pre_quantized:
from auto_round.inference.convert_model import post_init
from auto_round.inference.convert_model import post_init

post_init(model, self.used_backends)

post_init(model, self.used_backends)
else:
raise ValueError(
"AutoRound quantizer in diffusers only supports pre-quantized models. "
"Please provide a model that has already been quantized with AutoRound."
)
return model

@property
Expand Down
Loading