Skip to content

[torchao]: fix how FqnConfig is resolved and handled - #14686

Open
sayakpaul wants to merge 3 commits into
mainfrom
resolve-fqn-config-torchao
Open

[torchao]: fix how FqnConfig is resolved and handled#14686
sayakpaul wants to merge 3 commits into
mainfrom
resolve-fqn-config-torchao

Conversation

@sayakpaul

Copy link
Copy Markdown
Member

Fixes #14667. It surfaced additional issues which I have fixed as well.

I have run the TorchAO test suite and it's green.

@github-actions github-actions Bot added size/M PR with diff < 200 LOC and removed pipelines CI size/L PR with diff > 200 LOC labels Sep 2, 2026
import torch
import torch.nn as nn

if is_torch_version(">=", "2.5"):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Deadcode not needed.

return None


def _fqn_to_config_weight_sizes(config: "FqnToConfig") -> tuple[set[str | None], bool]:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Needed to determine CUDA warmup factor from FqnConfig.

return size_digits, leaves_modules_unquantized


def _resolve_fqn_to_config(config: "FqnToConfig", module_fqn: str, param_fqn: str):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Needed so that we can properly resolve config for a single linear layer because that is how we create the quantized params, i.e., iterating over the modules and calling quantize_() over them individually.

Comment on lines -239 to -249
if isinstance(target_dtype, SUPPORTED_TORCH_DTYPES_FOR_QUANTIZATION):
return target_dtype

# We need one of the supported dtypes to be selected in order for accelerate to determine
# the total size of modules/parameters for auto device placement.
possible_device_maps = ["auto", "balanced", "balanced_low_0", "sequential"]
raise ValueError(
f"You have set `device_map` as one of {possible_device_maps} on a TorchAO quantized model but a suitable target dtype "
f"could not be inferred. The supported target_dtypes are: {SUPPORTED_TORCH_DTYPES_FOR_QUANTIZATION}. If you think the "
f"dtype you are using should be supported, please open an issue at https://github.com/huggingface/diffusers/issues."
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Deadcode.

@sayakpaul
sayakpaul requested a review from DN6 September 2, 2026 04:13
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

FqnToConfig raises inside TorchAoConfig

2 participants