Skip to content

Conversation

sayakpaul
Copy link
Member

What does this PR do?

The AOBaseConfig classes introduced in torchao (since 0.9.0) are more flexible. Similar to Transformers, this PR adds support for allowing them in Diffusers:

from diffusers import DiffusionPipeline, TorchAoConfig, PipelineQuantizationConfig
from torchao.quantization import Int8WeightOnlyConfig
import torch 

ckpt_id = "black-forest-labs/FLUX.1-dev"
pipeline_quant_config = PipelineQuantizationConfig(
    quant_mapping={"transformer": TorchAoConfig(Int8WeightOnlyConfig())}
)
pipe = DiffusionPipeline.from_pretrained(
    ckpt_id, quantization_config=pipeline_quant_config, torch_dtype=torch.bfloat16
).to("cuda")
_ = pipe("dog", num_inference_steps=2)

@stevhliu, would it be possible for you to propagate the relevant changes to our TorchAO docs from Transformers? Can happen in a later PR.

@sayakpaul sayakpaul requested a review from a-r-r-o-w September 3, 2025 07:11
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@stevhliu stevhliu mentioned this pull request Sep 8, 2025

quantization_config = TorchAoConfig(Int8WeightOnlyConfig())

# String-based config

Choose a reason for hiding this comment

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

I think we can deprecate this one since this is less scalable than AOBaseConfig

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, will do so after this PR. Meanwhile, if you could review the PR, it'd be helpful.

@sayakpaul sayakpaul requested review from DN6 and SunMarc September 9, 2025 02:06
init

Co-authored-by: Sayak Paul <[email protected]>
Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Thanks for updating this !

)

if isinstance(self.quant_type, str):

Choose a reason for hiding this comment

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

nit: merge this with the branch in L521 to keep relevant things relevant together?

if isinstance(self.quant_type, str):
methods = self._get_torchao_quant_type_to_method()
quant_type_kwargs = self.quant_type_kwargs.copy()
if (

Choose a reason for hiding this comment

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

we should probably clean this up in the future..

Copy link

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

looks good, would be good to put up a deprecation plan for torchao version support and clean up the old code for str support I think, I don't think there is any reason why people can't upgrade to the most recent version currently

@sayakpaul
Copy link
Member Author

@jerryzh168 thanks for your reviews! I agree that it will make the library codebase cleaner if we started a deprecation cycle to promote the AoBaseConfig more and more. Will let @DN6 also review and then merge.

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.

5 participants