Skip to content

[core] TorchAO Quantizer - #10009

Merged
yiyixuxu merged 39 commits into
mainfrom
torchao-quantizer
Dec 16, 2024
Merged

[core] TorchAO Quantizer#10009
yiyixuxu merged 39 commits into
mainfrom
torchao-quantizer

Conversation

@a-r-r-o-w

@a-r-r-o-wa-r-r-o-w commented Nov 25, 2024

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds support for the TorchAO Quantizer.

Quantization formats

TorchAO supports a wide variety of quantizations. For a normal user, it can get quite overwhelming to understand all the different parameters and what they mean. In order to simplify this a bit, I've used some custom commonly used names that are easier to remember/use while also supporting full configurability of the original arguments.

The naming conventions used are:

  • full function names as in torchao: int8_weight_only, float8_weight_only, etc. You can pass the arguments supported by each method (as described in torchao docs) it through quantization kwargs.
  • wo (weight-only) and dq (weight + activation quantization) suffixes
  • {dtype}_a{x}w{y}: shorthand notations for convenience reasons and because the a{x}w{y} notation is used extensively in the torchao docs
  • float8 quantization also supports per tensor and per row granularity. per tensor is suffixed with _tensor and per row is suffixed with _row. per axis and per group granularity is also supported but they involve additional parameters in their constructors so power-users are free to play with that if they like, but the shorthands provided here are just for tensor/row.

Broadly, int4, int8, uintx, fp8 and fpx quantizations are supported, with dynamic activation quants where applicable, otherwise weight-only. Group sizes can be specified by power-users via the full function names and we don't have special names to handle those.

Benchmarks

The following code is used for benchmarking:

Code
importargparseimportgcimportosimportpathlibimporttraceback# os.environ["TORCH_LOGS"] = "+dynamo,graph_breaks,recompiles"# os.environ["TORCHDYNAMO_VERBOSE"] = "1"importgitimportpandasaspdimporttorchimporttorch.utils.benchmarkasbenchmarkfromdiffusersimportCogVideoXPipeline, CogVideoXTransformer3DModel, FluxPipeline, FluxTransformer2DModel, TorchAoConfigfromdiffusers.training_utilsimportset_seedfromdiffusers.utilsimportexport_to_videofromtabulateimporttabulatefromtorchao.quantization.utilsimportrecommended_inductor_config_setterrecommended_inductor_config_setter()
set_seed(42)
PROMPT="A dramatic landscape on an exoplanet with a breathtaking view of a ringed gas giant in the sky. The planet's surface is rugged and alien, green and violet colored rocky lands and mountains, with strange rock formations. The rings of the reddish-yellow gas giant cast colorful shadows and reflections, creating a surreal and captivating environment."defbenchmark_fn(f, *args, **kwargs):
torch.cuda.synchronize()
start=torch.cuda.Event(enable_timing=True)
end=torch.cuda.Event(enable_timing=True)
start.record()
output=f(*args, **kwargs)
end.record()
torch.cuda.synchronize()
elapsed_time=round(start.elapsed_time(end) /1000, 3)
returnelapsed_time, outputdefpretty_print_results(results, precision: int=6):
defformat_value(value):
ifisinstance(value, float):
returnf"{value:.{precision}f}"returnvaluefiltered_table= {k: format_value(v) fork, vinresults.items()}
print(tabulate([filtered_table], headers="keys", tablefmt="pipe", stralign="center"))
defprecompute_flux_embeds(dtype: torch.dtype, output_dir: pathlib.Path):
model_id="black-forest-labs/Flux.1-Dev"cache_dir="/raid/.cache/huggingface"pipe=FluxPipeline.from_pretrained(
model_id,
transformer=None,
vae=None,
torch_dtype=dtype,
cache_dir=cache_dir,
)
pipe.to("cuda")
prompt_embeds, pooled_prompt_embeds, text_ids=pipe.encode_prompt(
prompt=PROMPT,
prompt_2=PROMPT,
device="cuda",
num_images_per_prompt=1,
max_sequence_length=512,
)
torch.save(prompt_embeds, output_dir/"prompt_embeds.pt")
torch.save(pooled_prompt_embeds, output_dir/"pooled_prompt_embeds.pt")
defprecompute_cogvideox_embeds(dtype: torch.dtype, output_dir: pathlib.Path):
model_id="THUDM/CogVideoX1.5-5b"cache_dir=Nonepipe=CogVideoXPipeline.from_pretrained(
model_id,
transformer=None,
vae=None,
torch_dtype=dtype,
cache_dir=cache_dir,
)
pipe.to("cuda")
prompt_embeds, negative_prompt_embeds=pipe.encode_prompt(
prompt=PROMPT,
negative_prompt=None,
do_classifier_free_guidance=True,
num_videos_per_prompt=1,
max_sequence_length=226,
device="cuda",
)
torch.save(prompt_embeds, output_dir/"prompt_embeds.pt")
torch.save(negative_prompt_embeds, output_dir/"negative_prompt_embeds.pt")
defload_flux_embeds(dir: pathlib.Path):
prompt_embeds=torch.load(dir/"prompt_embeds.pt", weights_only=True)
pooled_prompt_embeds=torch.load(dir/"pooled_prompt_embeds.pt", weights_only=True)
return {
"prompt_embeds": prompt_embeds,
"pooled_prompt_embeds": pooled_prompt_embeds,
}
defload_cogvideox_embeds(dir: pathlib.Path):
prompt_embeds=torch.load(dir/"prompt_embeds.pt", weights_only=True)
negative_prompt_embeds=torch.load(dir/"negative_prompt_embeds.pt", weights_only=True)
return {
"prompt_embeds": prompt_embeds,
"negative_prompt_embeds": negative_prompt_embeds,
}
defprepare_flux(
dtype: torch.dtype,
quantization_config: TorchAoConfig,
compile: bool=False,
**kwargs,
):
model_id="black-forest-labs/Flux.1-Dev"cache_dir="/raid/.cache/huggingface"transformer=FluxTransformer2DModel.from_pretrained(
model_id,
subfolder="transformer",
quantization_config=quantization_config,
cache_dir=cache_dir,
torch_dtype=dtype,
)
pipe=FluxPipeline.from_pretrained(
model_id,
text_encoder=None,
text_encoder_2=None,
transformer=transformer,
torch_dtype=dtype,
cache_dir=cache_dir,
)
pipe.to("cuda")
ifcompile:
pipe.transformer=torch.compile(pipe.transformer, mode="max-autotune", fullgraph=True)
forkey, valueinlist(kwargs.items()):
iftorch.is_tensor(value):
kwargs[key] =value.to(device="cuda", dtype=dtype)
generation_kwargs= {
"height": 768,
"width": 768,
"num_inference_steps": 50,
"guidance_scale": 5.0,
**kwargs,
}
returnpipe, generation_kwargsdefprepare_cogvideox(
dtype: torch.dtype,
quantization_config: TorchAoConfig,
compile: bool=False,
**kwargs,
):
model_id="THUDM/CogVideoX1.5-5b"cache_dir=Nonetransformer=CogVideoXTransformer3DModel.from_pretrained(
model_id,
subfolder="transformer",
quantization_config=quantization_config,
cache_dir=cache_dir,
torch_dtype=dtype,
)
pipe=CogVideoXPipeline.from_pretrained(
model_id,
text_encoder=None,
transformer=transformer,
torch_dtype=dtype,
cache_dir=cache_dir,
)
pipe.to("cuda")
ifcompile:
pipe.transformer=torch.compile(pipe.transformer, mode="max-autotune", fullgraph=True)
forkey, valueinlist(kwargs.items()):
iftorch.is_tensor(value):
kwargs[key] =value.to(device="cuda", dtype=dtype)
generation_kwargs= {
"height": 768,
"width": 1360,
"num_frames": 81,
"num_inference_steps": 50,
"guidance_scale": 5.0,
**kwargs,
}
returnpipe, generation_kwargsdefdecode_flux(pipe: FluxPipeline, latents: torch.Tensor, filename: pathlib.Path, **kwargs):
height=kwargs["height"]
width=kwargs["width"]
filename=f"{filename.as_posix()}.png"latents=pipe._unpack_latents(latents, height, width, pipe.vae_scale_factor)
latents= (latents/pipe.vae.config.scaling_factor) +pipe.vae.config.shift_factorimage=pipe.vae.decode(latents, return_dict=False)[0]
image=pipe.image_processor.postprocess(image, output_type="pil")[0]
image.save(filename)
returnfilenamedefdecode_cogvideox(pipe: CogVideoXPipeline, latents: torch.Tensor, filename: pathlib.Path, **kwargs):
filename=f"{filename.as_posix()}.mp4"video=pipe.decode_latents(latents)
video=pipe.video_processor.postprocess_video(video=video, output_type="pil")[0]
export_to_video(video, filename, fps=16)
returnfilenamedef_generate_fpx_quantization_types(bits):
types= []
forebitsinrange(0, bits):
mbits=bits-ebits-1types.append(f"fp{bits}_e{ebits}m{mbits}")
returntypesMODEL_MAPPING= {
"flux": {
"precompute": precompute_flux_embeds,
"load": load_flux_embeds,
"prepare": prepare_flux,
"decode": decode_flux,
},
"cogvideox": {
"precompute": precompute_cogvideox_embeds,
"load": load_cogvideox_embeds,
"prepare": prepare_cogvideox,
"decode": decode_cogvideox,
},
}
STR_TO_COMPUTE_DTYPE= {
"bf16": torch.bfloat16,
"fp16": torch.float16,
"fp32": torch.float32,
}
QUANTIZATION_TYPES_TO_TEST= [
"none",
"int4wo", "int4dq", "int8wo", "int8dq",
"uint1wo", "uint2wo", "uint3wo", "uint4wo", "uint5wo", "uint6wo", "uint7wo", "uint8wo",
]
ifTorchAoConfig._is_cuda_capability_atleast_8_9():
QUANTIZATION_TYPES_TO_TEST.extend([
"float8wo_e5m2", "float8wo_e4m3",
"float8dq_e4m3",
"float8dq_e4m3_tensor", "float8dq_e4m3_row",
*_generate_fpx_quantization_types(3),
*_generate_fpx_quantization_types(4),
*_generate_fpx_quantization_types(5),
*_generate_fpx_quantization_types(6),
*_generate_fpx_quantization_types(7),
*_generate_fpx_quantization_types(8),
])
defrun_inference(pipe, generation_kwargs):
generator=torch.Generator().manual_seed(3047)
output=pipe(generator=generator, output_type="latent", **generation_kwargs)[0]
torch.cuda.synchronize()
returnoutput@torch.no_grad()defmain(model_id: str, output_dir: str, dtype: str, compile: bool=False):
ifmodel_idnotinMODEL_MAPPING.keys():
raiseValueError("Unsupported `model_id` specified.")
output_dir=pathlib.Path(output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
csv_filename=output_dir/f"{model_id}.csv"compute_dtype=STR_TO_COMPUTE_DTYPE[dtype]
model=MODEL_MAPPING[model_id]
model["precompute"](compute_dtype, output_dir)
repo=git.Repo(path="/home/aryan/work/diffusers")
branch=repo.active_branchforquantization_typeinQUANTIZATION_TYPES_TO_TEST:
try:
torch.cuda.reset_peak_memory_stats()
torch.cuda.reset_accumulated_memory_stats()
gc.collect()
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
torch.cuda.synchronize()
# 1. Prepare inputs and quantization configquantization_config=TorchAoConfig(quant_type=quantization_type) ifquantization_type!="none"elseNonekwargs=model["load"](output_dir)
pipe, generation_kwargs=model["prepare"](compute_dtype, quantization_config, compile, **kwargs)
before_inference_memory=round(torch.cuda.memory_allocated() /1024**3, 3)
before_inference_max_memory=round(torch.cuda.max_memory_allocated() /1024**3, 3)
before_inference_max_memory_reserved=round(torch.cuda.max_memory_reserved() /1024**3, 3)
# 2. Warmupnum_warmups=1for_inrange(num_warmups):
run_inference(pipe, generation_kwargs)
# 3. Benchmarktime, latents=benchmark_fn(run_inference, pipe, generation_kwargs)
after_inference_memory=round(torch.cuda.memory_allocated() /1024**3, 3)
after_inference_max_memory=round(torch.cuda.max_memory_allocated() /1024**3, 3)
after_inference_max_memory_reserved=round(torch.cuda.max_memory_reserved() /1024**3, 3)
# 4. Decode latentfilename=output_dir/f"{model_id}---dtype-{dtype}---qtype-{quantization_type}---compile-{compile}"filename=model["decode"](pipe, latents, filename, height=generation_kwargs["height"], width=generation_kwargs["width"])
# 5. Save artifactsinfo= {
"model_id": model_id,
"quantization_type": quantization_type,
"compute_dtype": dtype,
"compile": compile,
"time": time,
"before_inference_memory": before_inference_memory,
"before_inference_max_memory": before_inference_max_memory,
"before_inference_max_memory_reserved": before_inference_max_memory_reserved,
"after_inference_memory": after_inference_memory,
"after_inference_max_memory": after_inference_max_memory,
"after_inference_max_memory_reserved": after_inference_max_memory_reserved,
"branch": branch,
"filename": filename,
"exception": None,
}
exceptExceptionase:
print(f"An error occurred: {e}")
traceback.print_exc()
# 5. Save artifactsinfo= {
"model_id": model_id,
"quantization_type": quantization_type,
"compute_dtype": dtype,
"compile": compile,
"time": None,
"before_inference_memory": None,
"before_inference_max_memory": None,
"before_inference_max_memory_reserved": None,
"after_inference_memory": None,
"after_inference_max_memory": None,
"after_inference_max_memory_reserved": None,
"branch": branch,
"filename": None,
"exception": str(e),
}
pretty_print_results(info, precision=3)
df=pd.DataFrame([info])
df.to_csv(csv_filename.as_posix(), mode="a", index=False, header=notcsv_filename.is_file())
if__name__=="__main__":
parser=argparse.ArgumentParser()
parser.add_argument(
"--model_id",
type=str,
default="flux",
choices=["flux", "cogvideox"],
help="Model to run benchmark for.",
)
parser.add_argument("--output_dir", type=str, help="Path where the benchmark artifacts and outputs are the be saved.")
parser.add_argument("--dtype", type=str, help="torch.dtype to use for inference")
parser.add_argument(
"--compile",
action="store_true",
default=False,
help="Whether to torch.compile the denoiser.",
)
args=parser.parse_args()
main(args.model_id, args.output_dir, args.dtype, args.compile)

You can launch it with something like:

#!/bin/bash
MODEL_IDS=("flux""cogvideox")
COMPILE_OPTIONS=("""--compile")
forcompilein"${COMPILE_OPTIONS[@]}";doformodel_idin"${MODEL_IDS[@]}";do
cmd="python3 benchmark.py --model_id $model_id --output_dir torchao_benchmark_results --dtype bf16 $compile"echo"Running command: $cmd"eval$cmdecho -ne "-------------------- Finished executing script --------------------\n\n"donedone

Here are the time/memory results from a single H100:

Flux Table
model_idquantization_typecompute_dtypecompiletimebefore_inference_memorybefore_inference_max_memorybefore_inference_max_memory_reservedafter_inference_memoryafter_inference_max_memoryafter_inference_max_memory_reservedbranchfilenameexception
fluxnonebf16False6.85622.36422.36422.37722.36522.63323.018torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-none---compile-False.png
fluxint4wobf16False68.0176.21928.55328.5646.21928.55328.564torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-int4wo---compile-False.png
fluxint4dqbf16False23.93118.84519.01330.63118.84519.52530.631torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-int4dq---compile-False.png
fluxint8wobf16False9.74224.01424.18324.53724.01424.31924.959torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-int8wo---compile-False.png
fluxint8dqbf16False229.46322.5824.01427.02522.5824.01427.025torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-int8dq---compile-False.png
fluxuint1wobf16False19.06413.97422.5826.15813.97422.5826.158torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint1wo---compile-False.png
fluxuint2wobf16False16.7816.64713.97416.5926.64713.97416.592torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint2wo---compile-False.png
fluxuint3wobf16False24.5239.5299.6959.7119.52910.12410.631torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint3wo---compile-False.png
fluxuint4wobf16False16.59912.34512.51212.52712.34512.94213.395torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint4wo---compile-False.png
fluxuint5wobf16False22.0515.11515.28115.29915.11515.71216.219torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint5wo---compile-False.png
fluxuint6wobf16False20.50317.9318.09718.1817.9318.52619.1torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint6wo---compile-False.png
fluxuint7wobf16False27.75820.8521.01921.03520.8521.44722.061torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint7wo---compile-False.png
fluxfloat8wo_e5m2bf16False10.20722.52722.69323.5122.52722.90324.014torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8wo_e5m2---compile-False.png
fluxfloat8wo_e4m3bf16False10.3122.53422.70226.0822.53422.90926.08torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8wo_e4m3---compile-False.png
fluxfloat8dq_e4m3bf16False17.20322.52322.69123.23622.52323.04724.078torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8dq_e4m3---compile-False.png
fluxfloat8dq_e4m3_tensorbf16False17.19422.53422.70223.23422.53423.05824.084torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8dq_e4m3_atwt---compile-False.png
fluxfloat8dq_e4m3_rowbf16False16.90622.53422.70223.23422.53423.05824.084torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8dq_e4m3_arwr---compile-False.png
fluxfp3_e1m1bf16False75.21215.58515.75316.40415.58517.218.76torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp3_e1m1---compile-False.png
fluxfp3_e2m0bf16False76.1248.62815.58520.338.62815.58520.33torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp3_e2m0---compile-False.png
fluxfp4_e1m2bf16False59.88310.0110.17110.77710.0111.20312.549torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp4_e1m2---compile-False.png
fluxfp4_e2m1bf16False50.8611.40111.56114.11911.40113.01614.393torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp4_e2m1---compile-False.png
fluxfp4_e3m0bf16False51.61911.40111.56515.96311.40113.01615.963torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp4_e3m0---compile-False.png
fluxfp5_e1m3bf16False93.81712.74912.91313.67612.74913.94215.447torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp5_e1m3---compile-False.png
fluxfp5_e2m2bf16False82.81714.09414.25717.01814.09415.28717.127torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp5_e2m2---compile-False.png
fluxfp5_e3m1bf16False73.49814.0914.25218.69714.0915.70518.697torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp5_e3m1---compile-False.png
fluxfp5_e4m0bf16False74.34814.0914.2519.26414.0915.70519.264torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp5_e4m0---compile-False.png
fluxfp6_e1m4bf16False86.63915.58915.7517.11915.58916.78218.891torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp6_e1m4---compile-False.png
fluxfp6_e2m3bf16False64.29117.08517.24620.46117.08518.27820.779torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp6_e2m3---compile-False.png
fluxfp6_e3m2bf16False53.16717.08317.24622.3517.08318.27722.35torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp6_e3m2---compile-False.png
fluxfp6_e4m1bf16False43.9517.08417.24722.35217.08418.69922.352torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp6_e4m1---compile-False.png
fluxfp6_e5m0bf16False44.67617.08217.24522.91817.08218.69822.918torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp6_e5m0---compile-False.png
fluxfp7_e1m5bf16False178.85818.47218.63520.0718.47219.66621.854torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp7_e1m5---compile-False.png
fluxfp7_e2m4bf16False135.32319.85320.01823.42419.85321.04723.424torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp7_e2m4---compile-False.png
fluxfp7_e3m3bf16False111.12519.8520.01124.59219.8521.04524.592torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp7_e3m3---compile-False.png
fluxfp7_e4m2bf16False100.50219.85220.01424.59219.85221.04624.592torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp7_e4m2---compile-False.png
fluxfp7_e5m1bf16False90.25119.85120.01424.59219.85121.46724.592torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp7_e5m1---compile-False.png
fluxfp7_e6m0bf16False91.34419.85220.01425.15819.85221.46825.158torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp7_e6m0---compile-False.png
fluxnonebf16True4.30522.36422.36422.37722.33322.86123.156torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-none---compile-True.png
fluxint4wobf16True64.2796.21928.55329.3426.18828.55329.342torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-int4wo---compile-True.png
fluxint4dqbf16True5.18818.84519.01319.89312.79319.01319.893torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-int4dq---compile-True.png
fluxint8wobf16True5.2524.01424.18325.50411.35924.18326.125torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-int8wo---compile-True.png
fluxint8dqbf16True3.66322.5822.74924.24211.35922.74924.723torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-int8dq---compile-True.png
fluxuint1wobf16True5.19613.97414.14315.1022.75314.14315.242torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint1wo---compile-True.png
fluxuint2wobf16True4.9436.6456.8118.674.0276.8118.67torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint2wo---compile-True.png
fluxuint3wobf16True6.1349.5249.69110.6745.6339.69110.674torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint3wo---compile-True.png
fluxuint4wobf16True4.86412.34412.5113.496.84612.5113.49torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint4wo---compile-True.png
fluxuint5wobf16True5.83615.11515.28116.0418.40415.28116.041torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint5wo---compile-True.png
fluxuint6wobf16True5.29517.9318.09719.1419.66218.09719.141torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint6wo---compile-True.png
fluxuint7wobf16True7.18320.84921.01722.00211.32421.01722.002torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-uint7wo---compile-True.png
fluxfloat8wo_e5m2bf16True4.73622.52522.6924.45711.33522.6924.457torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8wo_e5m2---compile-True.png
fluxfloat8wo_e4m3bf16True4.78422.53422.70224.31111.33622.70224.311torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8wo_e4m3---compile-True.png
fluxfloat8dq_e5m2bf16True3.62522.52822.69724.20511.3322.87524.686torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8dq_e5m2---compile-True.png
fluxfloat8dq_e4m3bf16True3.51622.52322.69123.95711.3322.87124.438torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8dq_e4m3---compile-True.png
fluxfloat8dq_e5m2_tensorbf16True3.59222.52322.69123.95111.3322.69123.951torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8dq_e5m2_atwt---compile-True.png
fluxfloat8dq_e5m2_rowbf16True3.5122.53422.70223.88711.34122.88124.367torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8dq_e5m2_arwr---compile-True.png
fluxfloat8dq_e4m3_tensorbf16True3.44322.53422.70223.95911.3322.70223.959torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8dq_e4m3_atwt---compile-True.png
fluxfloat8dq_e4m3_rowbf16True3.4722.53422.70223.91811.34122.88124.398torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-float8dq_e4m3_arwr---compile-True.png
fluxfp3_e1m1bf16True13.37215.58415.75217.1134.38115.75217.113torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp3_e1m1---compile-True.png
fluxfp3_e2m0bf16True13.2578.6288.7910.7544.3798.7910.754torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp3_e2m0---compile-True.png
fluxfp4_e1m2bf16True6.55610.01110.17311.9865.76410.17311.986torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp4_e1m2---compile-True.png
fluxfp4_e2m1bf16True6.45611.40211.56213.0595.76911.56213.059torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp4_e2m1---compile-True.png
fluxfp4_e3m0bf16True6.33611.40211.56612.9455.76811.56612.945torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp4_e3m0---compile-True.png
fluxfp5_e1m3bf16True11.85912.7512.91514.6647.11712.91514.664torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp5_e1m3---compile-True.png
fluxfp5_e2m2bf16True11.60114.09414.25716.5537.11114.25716.553torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp5_e2m2---compile-True.png
fluxfp5_e3m1bf16True11.39614.09214.25316.5457.11414.25316.545torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp5_e3m1---compile-True.png
fluxfp5_e4m0bf16True11.24214.09314.25416.5377.11314.25416.537torchao-quantizertorchao_benchmark_results/flux---dtype-bf16---qtype-fp5_e4m0---compile-True.png
Flux visual results
bf16 baseline
bf16---int4wobf16---int4dq
bf16---int8wobf16---int8dq
bf16---uint1wobf16---uint2wo
bf16---uint3wobf16---uint4wo
bf16---uint5wobf16---uint6wo
bf16---uint7wobf16---float8wo_e5m2
bf16---float8wo_e4m3bf16---float8dq_e4m3
bf16---float8dq_e4m3_tensorbf16---float8dq_e4m3_row
bf16---fp3_e1m1bf16---fp3_e2m0
bf16---fp4_e1m2bf16---fp4_e2m1
bf16---fp4_e3m0bf16---fp5_e1m3
bf16---fp5_e2m2bf16---fp5_e3m1
bf16---fp5_e4m0bf16---fp6_e1m4
bf16---fp6_e2m3bf16---fp6_e3m2
bf16---fp6_e4m1bf16---fp6_e5m0
bf16---fp7_e1m5bf16---fp7_e2m4
bf16---fp7_e3m3bf16---fp7_e4m2
bf16---fp7_e5m1bf16---fp7_e6m0
CogVideoX table
model_idquantization_typecompute_dtypecompiletimebefore_inference_memorybefore_inference_max_memorybefore_inference_max_memory_reservedafter_inference_memoryafter_inference_max_memoryafter_inference_max_memory_reservedbranchfilenameexception
cogvideoxnonebf16False109.18310.82410.82410.83610.82713.48515.531torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-none---compile-False.mp4
cogvideoxint4wobf16False666.93.67814.47132.0553.67714.47132.055torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-int4wo---compile-False.mp4
cogvideoxint4dqbf16False157.4759.5169.93535.679.51714.84235.67torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-int4dq---compile-False.mp4
cogvideoxint8wobf16False120.04211.5111.92834.11511.50914.17134.115torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-int8wo---compile-False.mp4
cogvideoxint8dqbf16False338.08310.8811.50933.68910.88114.27433.689torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-int8dq---compile-False.mp4
cogvideoxuint1wobf16False109.5826.95310.88134.7916.95310.88134.791torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint1wo---compile-False.mp4
cogvideoxuint2wobf16False112.5413.526.95329.9773.526.95329.977torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint2wo---compile-False.mp4
cogvideoxuint3wobf16False115.7994.8615.27126.9964.8617.52326.996torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint3wo---compile-False.mp4
cogvideoxuint4wobf16False113.596.186.59827.8776.188.84327.877torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint4wo---compile-False.mp4
cogvideoxuint5wobf16False115.7427.4777.88829.2077.47710.13929.207torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint5wo---compile-False.mp4
cogvideoxuint6wobf16False115.4888.7869.20330.5048.78511.44830.504torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint6wo---compile-False.mp4
cogvideoxuint7wobf16False117.2610.17410.58731.88310.17412.83531.883torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint7wo---compile-False.mp4
cogvideoxfloat8wo_e5m2bf16False110.55610.93911.35811.61110.9413.60216.332torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8wo_e5m2---compile-False.mp4
cogvideoxfloat8wo_e4m3bf16False110.68910.84411.25937.79310.84313.50537.793torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8wo_e4m3---compile-False.mp4
cogvideoxfloat8dq_e4m3bf16False116.1410.82811.24111.80110.82815.74819.938torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8dq_e4m3---compile-False.mp4
cogvideoxfloat8dq_e4m3_tensorbf16False116.19610.83511.24911.80710.83515.75619.941torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8dq_e4m3_atwt---compile-False.mp4
cogvideoxfloat8dq_e4m3_rowbf16False118.43310.83911.24911.80510.83915.75719.941torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8dq_e4m3_arwr---compile-False.mp4
cogvideoxfp3_e1m1bf16False142.8597.6228.0378.5967.62210.34213.551torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp3_e1m1---compile-False.mp4
cogvideoxfp3_e2m0bf16False142.2344.4037.62231.3814.4037.62231.381torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp3_e2m0---compile-False.mp4
cogvideoxfp4_e1m2bf16False132.6285.0265.4415.8815.0267.68910.742torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp4_e1m2---compile-False.mp4
cogvideoxfp4_e2m1bf16False128.2285.6556.06727.2545.6558.37227.254torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp4_e2m1---compile-False.mp4
cogvideoxfp4_e3m0bf16False128.3945.6516.06629.1625.6518.37129.162torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp4_e3m0---compile-False.mp4
cogvideoxfp5_e1m3bf16False150.1366.3026.7137.2856.3028.96212.146torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp5_e1m3---compile-False.mp4
cogvideoxfp5_e2m2bf16False145.2176.9467.36128.6586.9469.60928.658torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp5_e2m2---compile-False.mp4
cogvideoxfp5_e3m1bf16False141.1376.957.36129.5666.959.66829.566torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp5_e3m1---compile-False.mp4
cogvideoxfp5_e4m0bf16False142.0746.9467.36130.9796.9469.66630.979torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp5_e4m0---compile-False.mp4
cogvideoxfp6_e1m4bf16False144.1567.688.0919.3487.6810.34214.209torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp6_e1m4---compile-False.mp4
cogvideoxfp6_e2m3bf16False133.9878.4098.82330.7198.40911.07130.719torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp6_e2m3---compile-False.mp4
cogvideoxfp6_e3m2bf16False128.738.4098.82131.8188.40911.07131.818torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp6_e3m2---compile-False.mp4
cogvideoxfp6_e4m1bf16False124.9778.4088.8231.8388.40811.12731.838torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp6_e4m1---compile-False.mp4
cogvideoxfp6_e5m0bf16False123.9398.4098.82231.9498.40911.12931.949torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp6_e5m0---compile-False.mp4
cogvideoxfp7_e1m5bf16False192.6179.0169.42910.9089.01611.67815.77torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp7_e1m5---compile-False.mp4
cogvideoxfp7_e2m4bf16False171.9639.63910.05233.69.6412.30333.6torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp7_e2m4---compile-False.mp4
cogvideoxfp7_e3m3bf16False161.6239.6410.06933.9089.6412.30333.908torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp7_e3m3---compile-False.mp4
cogvideoxfp7_e4m2bf16False155.9769.63910.06832.5129.63912.30132.512torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp7_e4m2---compile-False.mp4
cogvideoxfp7_e5m1bf16False150.4999.63810.06732.5129.63812.35832.512torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp7_e5m1---compile-False.mp4
cogvideoxfp7_e6m0bf16False148.889.63910.06732.6059.63912.35932.605torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp7_e6m0---compile-False.mp4
cogvideoxnonebf16True84.04110.82410.82410.83610.79613.71913.928torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-none---compile-True.mp4
cogvideoxint4wobf16True629.4713.64714.43937.8093.64614.43937.809torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-int4wo---compile-True.mp4
cogvideoxint4dqbf16True87.6539.4859.90431.2666.26110.2931.266torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-int4dq---compile-True.mp4
cogvideoxint8wobf16True85.00311.47811.89734.8095.63812.17434.809torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-int8wo---compile-True.mp4
cogvideoxint8dqbf16True77.87810.84811.26933.5185.63311.26933.518torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-int8dq---compile-True.mp4
cogvideoxuint1wobf16True80.1056.9247.3435.0251.7097.3435.025torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint1wo---compile-True.mp4
cogvideoxuint2wobf16True84.6753.493.90831.7972.2015.21731.797torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint2wo---compile-True.mp4
cogvideoxuint3wobf16True85.0974.835.23929.7913.0416.05629.791torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint3wo---compile-True.mp4
cogvideoxuint4wobf16True85.0576.1476.56532.1133.5276.56532.113torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint4wo---compile-True.mp4
cogvideoxuint5wobf16True85.0737.4467.85631.1584.3317.85631.158torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint5wo---compile-True.mp4
cogvideoxuint6wobf16True85.1148.759.16833.4164.849.16833.416torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint6wo---compile-True.mp4
cogvideoxuint7wobf16True85.80310.14110.55232.5785.71410.55232.578torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-uint7wo---compile-True.mp4
cogvideoxfloat8wo_e5m2bf16True85.03510.90211.31914.7755.60811.31914.775torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8wo_e5m2---compile-True.mp4
cogvideoxfloat8wo_e4m3bf16True85.01810.80711.21733.3835.61211.21733.383torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8wo_e4m3---compile-True.mp4
cogvideoxfloat8dq_e5m2bf16True76.82910.80311.21833.0885.60812.04433.088torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8dq_e5m2---compile-True.mp4
cogvideoxfloat8dq_e4m3bf16True74.55310.79911.21433.8935.60812.07133.893torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8dq_e4m3---compile-True.mp4
cogvideoxfloat8dq_e5m2_tensorbf16True76.77610.79811.21433.8985.60811.21433.898torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8dq_e5m2_atwt---compile-True.mp4
cogvideoxfloat8dq_e5m2_rowbf16True76.54110.80811.22315.6295.61812.04817.436torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8dq_e5m2_arwr---compile-True.mp4
cogvideoxfloat8dq_e4m3_tensorbf16True74.40910.80811.22333.9385.60711.22333.938torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8dq_e4m3_atwt---compile-True.mp4
cogvideoxfloat8dq_e4m3_rowbf16True75.58610.80711.22215.6235.61712.04817.43torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-float8dq_e4m3_arwr---compile-True.mp4
cogvideoxfp3_e1m1bf16True87.4977.5928.00812.5452.3938.00812.785torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp3_e1m1---compile-True.mp4
cogvideoxfp3_e2m0bf16True87.8334.3714.78430.592.3945.50430.59torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp3_e2m0---compile-True.mp4
cogvideoxfp4_e1m2bf16True85.1974.9985.4129.0593.0216.1689.059torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp4_e1m2---compile-True.mp4
cogvideoxfp4_e2m1bf16True85.3595.6256.0430.5183.0226.08130.518torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp4_e2m1---compile-True.mp4
cogvideoxfp4_e3m0bf16True85.1125.6236.03930.4513.026.0830.451torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp4_e3m0---compile-True.mp4
cogvideoxfp5_e1m3bf16True87.8126.2736.68710.4713.6716.86810.471torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp5_e1m3---compile-True.mp4
cogvideoxfp5_e2m2bf16True87.856.9197.33531.413.6697.33531.41torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp5_e2m2---compile-True.mp4
cogvideoxfp5_e3m1bf16True87.5766.9217.33431.353.677.33431.35torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp5_e3m1---compile-True.mp4
cogvideoxfp5_e4m0bf16True87.0366.9227.33731.3573.6717.33731.357torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp5_e4m0---compile-True.mp4
cogvideoxfp6_e1m4bf16True86.0147.6528.06712.5184.48.06712.518torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp6_e1m4---compile-True.mp4
cogvideoxfp6_e2m3bf16True85.2748.3848.79932.54.4038.79932.5torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp6_e2m3---compile-True.mp4
cogvideoxfp6_e3m2bf16True85.1238.3798.79630.4964.3978.79630.496torchao-quantizercogvideox_benchmark_results/cogvideox---dtype-bf16---qtype-fp6_e3m2---compile-True.mp4
CogVideoX visual results

Unfortunately, the prompt I used does not produce a very good initial video. Should have verified this in the beginning... 🫠

For some reason, GitHub does not render the videos from HF despite trying a few things. So, I'm not embedding it here. The results can be found here: https://huggingface.co/datasets/a-r-r-o-w/randoms/tree/main/cogvideox_benchmark_results

The minimal code for using the quantizer would be:

fromdiffusersimportFluxPipeline, FluxTransformer2DModel, TorchAoConfigmodel_id="black-forest-labs/Flux.1-Dev"dtype=torch.bfloat16quantization_config=TorchAoConfig("int8wo")
transformer=FluxTransformer2DModel.from_pretrained(
model_id,
subfolder="transformer",
quantization_config=quantization_config,
torch_dtype=dtype,
)
pipe=FluxPipeline.from_pretrained(
model_id,
transformer=transformer,
torch_dtype=dtype,
)
pipe.to("cuda")
prompt="A cat holding a sign that says hello world"image=pipe(prompt, num_inference_steps=4, guidance_scale=0.0).images[0]
image.save("output.png")

TODO

  • save_pretrained
  • from_pretrained
  • tests
    • Memory footprint.
    • Integration tests for Flux, Cog, etc.
    • modules_to_not_convert.
    • Training.
    • torch.compile() <> torchao
  • docs

@DN6@sayakpaul@yiyixuxu

@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.

Comment threadtests/quantization/torchao/test_torchao.py Outdated
@jerryzh168

Copy link
Copy Markdown

looks good to me overall, I think we also want to think about how we can integrate autoquant API: https://github.com/pytorch/ao/tree/main/torchao/quantization#autoquantization that works on the full model instead of individual linear modules

Comment threadsrc/diffusers/quantizers/torchao/torchao_quantizer.py Outdated
@a-r-r-o-w
a-r-r-o-w marked this pull request as ready for review November 28, 2024 05:06
Comment on lines -674 to -706
if device_map is not None:
raise NotImplementedError(
"Currently, `device_map` is automatically inferred for quantized models. Support for providing `device_map` as an input will be added in the future."
)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@sayakpaul I'm not sure how this impacts BnB quantizer. I assume it was disabled for BnB for some reason I'm not aware of. It works with TorchAO as expected though so if you need this to have some kind of guard for torchao-specific, I'll add it

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It works with TorchAO as expected though

How did you test that?

I assume it was disabled for BnB for some reason I'm not aware of.

That is because we merge the sharded checkpoints when using bnb and using custom device_maps needs this codepath:

accelerate.load_checkpoint_and_dispatch(

This is not hit when loading quantized checkpoints at least for bitsandbytes. This will be tackled in: #10013

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

How did you test that?

There is a test for this in tests/quantization/torchao/test_torchao.py called test_offload that can be used to verify that cpu/disk offloading works with torchao

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah but this is about custom user-provided device_maps. What am I missing?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The check of if device_map is not None was added in the BnB Quantizer PR. I assume it was added because device_map is not supported in BnB. But it works perfectly fine with TorchAO (as the test checks), so I removed the change in order to do the initial testing of the TorchAO quantizer quickly.

I would like to know if there should be an error raised if BnB quantizer is the method used. Something like:

ifquantizationmethodisBnBanddevice_mapisnotNone:
raiseError

Does that work?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah that works for me.

Comment threadtests/quantization/torchao/test_torchao.py Outdated

@sayakpaulsayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for working on this. I love my aspects of this PR. My favorite being how we're supporting many torchao quant configs!

Apart from the comments I left in-line, I have the following additional comments:

  1. Consider testing for model memory footprint as well.
  2. Consider including integration tests for Flux, Cog, etc. At least Flux should be covered.
  3. Consider adding a note on serialization in the docs.
  4. Consider testing for modules_to_not_convert.
  5. Consider adding a test for training. Example:
    deftest_training(self):

LMK if anything is unclear.

Comment threaddocs/source/en/quantization/torchao.md Outdated

## Usage

Now you can quantize a model by passing a [`TorchAoConfig`] to [`~ModelMixin.from_pretrained`]. This works for any model in any modality, as long as it supports loading with [Accelerate](https://hf.co/docs/accelerate/index) and contains `torch.nn.Linear` layers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Now you can quantize a model by passing a [`TorchAoConfig`] to [`~ModelMixin.from_pretrained`]. This works for any model in any modality, as long as it supports loading with [Accelerate](https://hf.co/docs/accelerate/index) and contains `torch.nn.Linear` layers.
Now you can quantize a model by passing a [`TorchAoConfig`] to [`~ModelMixin.from_pretrained`] or even load a pre-quantized model. This works for any model in any modality, as long as it supports loading with [Accelerate](https://hf.co/docs/accelerate/index) and contains `torch.nn.Linear` layers.

Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threadsrc/diffusers/models/model_loading_utils.py Outdated
Comment on lines -674 to -706
if device_map is not None:
raise NotImplementedError(
"Currently, `device_map` is automatically inferred for quantized models. Support for providing `device_map` as an input will be added in the future."
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It works with TorchAO as expected though

How did you test that?

I assume it was disabled for BnB for some reason I'm not aware of.

That is because we merge the sharded checkpoints when using bnb and using custom device_maps needs this codepath:

accelerate.load_checkpoint_and_dispatch(

This is not hit when loading quantized checkpoints at least for bitsandbytes. This will be tackled in: #10013

Comment threadtests/quantization/torchao/test_torchao.py Outdated
Comment threadtests/quantization/torchao/test_torchao.py Outdated
Comment threadtests/quantization/torchao/test_torchao.py Outdated
"hf-internal-testing/tiny-flux-pipe",
subfolder="transformer",
quantization_config=quantization_config,
device_map=device_map_offload,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We assign a hf_device_map attribute to the model too, so we should also check if the quantized_hf_device_map matches the expected one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@a-r-r-o-w just checking if this is remaining to be added?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated the test_offload test with a check to verify hf_device_map is same as device_map. I don't see any quantized_hf_device_map when grepping the codebase or searching on github, so not sure what you are referring too. Could you help with this?

Comment threadtests/quantization/torchao/test_torchao.py Outdated

@sayakpaulsayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did another pass and answered some questions.

Very important would be to have a test suite for torchao + torch.compile() (at least for some quant types) as that is a massive USP of torchao.

Comment threadsrc/diffusers/models/model_loading_utils.py Outdated
Comment threadsrc/diffusers/quantizers/quantization_config.py
Comment threadsrc/diffusers/quantizers/torchao/torchao_quantizer.py
Comment on lines +170 to +171
module, tensor_name = get_module_from_name(model, param_name)
return isinstance(module, torch.nn.Linear) and (tensor_name == "weight")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We check it to do a further inspection on the shape as well as to handle any parameter creation. But I guess it's fine with torchao because of the reasons you mentioned. @SunMarc WDYT?

Comment threadsrc/diffusers/quantizers/torchao/torchao_quantizer.py
Comment on lines +250 to +253
@property
def is_trainable(self):
# TODO(aryan): needs testing
return self.quantization_config.quant_type.startswith("int8")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fp8 training is orthogonal here if we are talking about peft I think. But I feel we should be able to fine-tune a fp8 quantized model as well (with float8_weight_only, float8_dynamic_activation_float8_weight, float8_static_activation_float8_weight) I feel, I haven't tried this though, did you see any errors when you try it?

I think this should be checked in the torchao CI given the popularity of training quantized models? If you give us a heads up about that, we'd be more than happy to configure this here accordingly.

@BenjaminBossan could you comment on the support of torchao <> peft a bit here?

for param in module.parameters():
if param.__class__.__name__ == "AffineQuantizedTensor":
data, scale, zero_point = param.layout_tensor.get_plain()
quantized_param_memory += data.numel() + data.element_size()

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Oh typo here... should be multiplied

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Oh interesting, missed it! Will try it out

Comment threaddocs/source/en/quantization/torchao.md

@sayakpaulsayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking really well!

I think it would also make sense to run the existing and important integration tests before merging to make sure there's no obvious bugs.

Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md
Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md
"hf-internal-testing/tiny-flux-pipe",
subfolder="transformer",
quantization_config=quantization_config,
device_map=device_map_offload,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@a-r-r-o-w just checking if this is remaining to be added?

Comment threadtests/quantization/torchao/test_torchao.py
self.assertTrue(np.allclose(normal_output, compile_output, atol=1e-2, rtol=1e-3))

@staticmethod
def _get_memory_footprint(module):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this not work?

defget_memory_footprint(self, return_buffers=True):

If not, we should consider these changes in modeling_utils.py, IMO.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Nope, this does not return the correct size of model weights when quantization is applied. We can consider the change in modeling_utils.py in a separate PR to account for the AQT tensors, since this is just present in the tests for the moment.

The TorchAO utility provided by Jerry here is probably better to use that what I have here.

Comment on lines +380 to +420
@staticmethod
def _get_memory_footprint(module):
quantized_param_memory = 0.0
unquantized_param_memory = 0.0

for param in module.parameters():
if param.__class__.__name__ == "AffineQuantizedTensor":
data, scale, zero_point = param.layout_tensor.get_plain()
quantized_param_memory += data.numel() + data.element_size()
quantized_param_memory += scale.numel() + scale.element_size()
quantized_param_memory += zero_point.numel() + zero_point.element_size()
else:
unquantized_param_memory += param.data.numel() * param.data.element_size()

total_memory = quantized_param_memory + unquantized_param_memory
return total_memory, quantized_param_memory, unquantized_param_memory

def test_memory_footprint(self):
r"""
A simple test to check if the model conversion has been done correctly by checking on the
memory footprint of the converted model and the class type of the linear layers of the converted models
"""
transformer_int4wo = self.get_dummy_components(TorchAoConfig("int4wo"))["transformer"]
transformer_int4wo_gs32 = self.get_dummy_components(TorchAoConfig("int4wo", group_size=32))["transformer"]
transformer_int8wo = self.get_dummy_components(TorchAoConfig("int8wo"))["transformer"]
transformer_bf16 = self.get_dummy_components(None)["transformer"]

total_int4wo, quantized_int4wo, unquantized_int4wo = self._get_memory_footprint(transformer_int4wo)
total_int4wo_gs32, quantized_int4wo_gs32, unquantized_int4wo_gs32 = self._get_memory_footprint(
transformer_int4wo_gs32
)
total_int8wo, quantized_int8wo, unquantized_int8wo = self._get_memory_footprint(transformer_int8wo)
total_bf16, quantized_bf16, unquantized_bf16 = self._get_memory_footprint(transformer_bf16)

self.assertTrue(quantized_bf16 == 0 and total_bf16 == unquantized_bf16)
# int4wo_gs32 has smaller group size, so more groups -> more scales and zero points
self.assertTrue(total_int8wo < total_bf16 < total_int4wo_gs32)
# int4 with default group size quantized very few linear layers compared to a smaller group size of 32
self.assertTrue(quantized_int4wo < quantized_int4wo_gs32 and unquantized_int4wo > unquantized_int4wo_gs32)
# int8 quantizes more layers compare to int4 with default group size
self.assertTrue(quantized_int8wo < quantized_int4wo)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah both are separate memory footprint gives us the ballpark around how much we need to load. Memory usage will tell us the actual memory needed for execution. Both could be considered to be included here.

Comment threadtests/quantization/torchao/test_torchao.py

@yiyixuxuyiyixuxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

oh thanks for the great work!
PR looks very good to me and I think we can merge this very soon. The only concern I have is the API to support all the shorthand, IMO we should not, but I'm open to different opinions! :)

)

@classmethod
def _get_torchao_quant_type_to_method(cls):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ohh, I think it will be too much to support API with all the shorthand, creating and maintaining all the related docs, and keeping the list up to date.

Is this something currently supported by TorchAO, or in their plan to? If they support it, I think it will be ok/managable for us to maintain a parallel mapping. otherwise, I think it is unnecessary/not meaningful for us to come up with new APIs for the external libraries we integrate.

If we want to create a set of "shorthand standards" that we can use at diffusers across all the different quantization methods/libraries we support (e.g. something we can use for both bnb, torchAO etc), it might be meaningful, but I think it will be better if we do that after we have a few more libraries in :)

also cc @SunMarc here, because for quantisation we would like to keep the API roughly consistent between transformer and diffusers

Overall, IMO , I think we should just only accept passing method name as it is, for shorthand, it is ok to support a very very small and most commonly used list.

But I'm open to different opinions! so let me know cc @DN6 too

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

makes sense, maybe we can provide some common shorthand, these have been repeated in many libraries: https://github.com/pytorch/ao/blob/8a805d08898e5c961fb9b4f6ab61ffd5d5bdbca5/torchao/_models/llama/generate.py#L702

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Looking forward to hear thoughts from others! I find the shorthands for uintx/fpx, and suffixes of wo and dq, rather convenient. I believe they are commonly used too. No hard preferences, okay with whatever we decide

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah I think the number of terms here will be a bit difficult to maintain. Perhaps we support just the Shorthands mentioned here? Does the community have any preference?
https://github.com/huggingface/diffusers/pull/10009/files#r1873188178

@a-r-r-o-wa-r-r-o-wDec 9, 2024

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks for the review @DN6! I've removed the documentation shorthands (anything of the form {dtype}_aXwY after our discussion in DM.

I think we should definitely have the fully qualified function names, wo and dq suffixes. Updated the documentation accordingly.

For Jerry's suggestion, the hqq, marlin, sparsify, autoquant, intx (prototype), spinquant can be tackled in a separate PR after trying it out. Let's keep this one to the just the ones that we have here already. Will check the generation quality with these soon

Comment threadsrc/diffusers/quantizers/torchao/torchao_quantizer.py

@stevhliustevhliu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding, really super!

Comment threaddocs/source/en/quantization/overview.md Outdated
Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md Outdated
Comment threaddocs/source/en/quantization/torchao.md Outdated
"""This is a config class for torchao quantization/sparsity techniques.

Args:
quant_type (`str`):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah this is quite heavy for a docstring

Comment threadsrc/diffusers/models/modeling_utils.py
a-r-r-o-wand others added 3 commits December 7, 2024 01:08
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
DN6
DN6 approved these changes Dec 9, 2024
Comment threaddocs/source/en/quantization/torchao.md Outdated
)

@classmethod
def _get_torchao_quant_type_to_method(cls):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah I think the number of terms here will be a bit difficult to maintain. Perhaps we support just the Shorthands mentioned here? Does the community have any preference?
https://github.com/huggingface/diffusers/pull/10009/files#r1873188178

@yiyixuxu

Copy link
Copy Markdown
Collaborator

@SunMarc can you do a final review if you haven't?

@yiyixuxu
yiyixuxu merged commit 9f00c61 into mainDec 16, 2024
@yiyixuxu
yiyixuxu deleted the torchao-quantizer branch December 16, 2024 23:35
sayakpaul added a commit that referenced this pull request Dec 23, 2024
* torchao quantizer
---------
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

[TorchAO](https://github.com/pytorch/ao) is an architecture optimization library for PyTorch. It provides high-performance dtypes, optimization techniques, and kernels for inference and training, featuring composability with native PyTorch features like [torch.compile](https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html), FullyShardedDataParallel (FSDP), and more.

Before you begin, make sure you have Pytorch 2.5+ and TorchAO installed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Indeed it seems Pytorch 2.5+ is required because in

there is an import of torch.uint1 (and others) which are not available in earlier torch versions. However, diffusers seem to require torch>=1.4 (ref), so this seem inconsistent. Am I missing something?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

TorchAO will not be imported or usable unless the pytorch version of 2.5 or above is available. Some Diffusers models can run with the 1.4 version as well, which is why that's the minimum required version.

@fjeremicfjeremicDec 24, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm running into the same issue with the torch.unit1 import. It seems the TorchAO import is not guarded according to the backtrace. The following backtrace stems from this import line:

from diffusers import StableDiffusionXLPipeline

Here is the trace, and the pip list:

 Traceback (most recent call last):
File "/github/home/.local/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 920, in _get_module
return importlib.import_module("." + module_name, self.__name__)
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/github/home/.local/lib/python3.10/site-packages/diffusers/loaders/single_file.py", line 24, in <module>
from .single_file_utils import (
File "/github/home/.local/lib/python3.10/site-packages/diffusers/loaders/single_file_utils.py", line 28, in <module>
from ..models.modeling_utils import load_state_dict
File "/github/home/.local/lib/python3.10/site-packages/diffusers/models/modeling_utils.py", line 35, in <module>
from ..quantizers import DiffusersAutoQuantizer, DiffusersQuantizer
File "/github/home/.local/lib/python3.10/site-packages/diffusers/quantizers/__init__.py", line 15, in <module>
from .auto import DiffusersAutoQuantizer
File "/github/home/.local/lib/python3.10/site-packages/diffusers/quantizers/auto.py", line 31, in <module>
from .torchao import TorchAoHfQuantizer
File "/github/home/.local/lib/python3.10/site-packages/diffusers/quantizers/torchao/__init__.py", line 15, in <module>
from .torchao_quantizer import TorchAoHfQuantizer
File "/github/home/.local/lib/python3.10/site-packages/diffusers/quantizers/torchao/torchao_quantizer.py", line 45, in <module>
torch.uint1,
File "/github/home/.local/lib/python3.10/site-packages/torch/__init__.py", line 1938, in __getattr__
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
AttributeError: module 'torch' has no attribute 'uint1'

And the pip list:

pip list -v
Package Version Editable project location Location Installer
------------------------ ----------- ---------------------------- ------------------------------------------------ ---------
certifi 2024.12.14 /github/home/.local/lib/python3.10/site-packages pip
charset-normalizer 3.4.0 /github/home/.local/lib/python3.10/site-packages pip
colorama 0.4.6 /github/home/.local/lib/python3.10/site-packages pip
coloredlogs 15.0.1 /github/home/.local/lib/python3.10/site-packages pip
colorlog 6.9.0 /github/home/.local/lib/python3.10/site-packages pip
coverage 7.6.9 /github/home/.local/lib/python3.10/site-packages pip
diffusers 0.32.0 /github/home/.local/lib/python3.10/site-packages pip
exceptiongroup 1.2.2 /github/home/.local/lib/python3.10/site-packages pip
execnet 2.1.1 /github/home/.local/lib/python3.10/site-packages pip
filelock 3.16.1 /github/home/.local/lib/python3.10/site-packages pip
flatbuffers 24.12.23 /github/home/.local/lib/python3.10/site-packages pip
fsspec 2024.12.0 /github/home/.local/lib/python3.10/site-packages pip
huggingface-hub 0.27.0 /github/home/.local/lib/python3.10/site-packages pip
humanfriendly 10.0 /github/home/.local/lib/python3.10/site-packages pip
idna 3.10 /github/home/.local/lib/python3.10/site-packages pip
importlib_metadata [8](/runs/952286/job/1969259#step:10:9).5.0 /github/home/.local/lib/python3.10/site-packages pip
iniconfig 2.0.0 /github/home/.local/lib/python3.10/site-packages pip
Jinja2 3.1.5 /github/home/.local/lib/python3.10/site-packages pip
markdown-it-py 3.0.0 /github/home/.local/lib/python3.10/site-packages pip
MarkupSafe 3.0.2 /github/home/.local/lib/python3.10/site-packages pip
mdurl 0.1.2 /github/home/.local/lib/python3.10/site-packages pip
mpmath 1.3.0 /github/home/.local/lib/python3.10/site-packages pip
networkx 3.4.2 /github/home/.local/lib/python3.10/site-packages pip
numpy 1.26.4 /github/home/.local/lib/python3.10/site-packages pip
nvidia-cublas-cu12 12.1.3.1 /github/home/.local/lib/python3.10/site-packages pip
nvidia-cuda-cupti-cu12 12.1.105 /github/home/.local/lib/python3.10/site-packages pip
nvidia-cuda-nvrtc-cu12 12.1.105 /github/home/.local/lib/python3.10/site-packages pip
nvidia-cuda-runtime-cu12 12.1.105 /github/home/.local/lib/python3.10/site-packages pip
nvidia-cudnn-cu12 8.[9](/runs/952286/job/1969259#step:10:10).2.26 /github/home/.local/lib/python3.10/site-packages pip
nvidia-cufft-cu12 11.0.2.54 /github/home/.local/lib/python3.[10](/runs/952286/job/1969259#step:10:11)/site-packages pip
nvidia-curand-cu12 10.3.2.106 /github/home/.local/lib/python3.10/site-packages pip
nvidia-cusolver-cu12 [11](/runs/952286/job/1969259#step:10:12).4.5.107 /github/home/.local/lib/python3.10/site-packages pip
nvidia-cusparse-cu[12](/runs/952286/job/1969259#step:10:13) 12.1.0.106 /github/home/.local/lib/python3.10/site-packages pip
nvidia-nccl-cu12 2.19.3 /github/home/.local/lib/python3.10/site-packages pip
nvidia-nvjitlink-cu12 12.6.85 /github/home/.local/lib/python3.10/site-packages pip
nvidia-nvtx-cu12 12.1.105 /github/home/.local/lib/python3.10/site-packages pip
onnx 1.17.0 /github/home/.local/lib/python3.10/site-packages pip
onnx2torch 1.5.15 /github/home/.local/lib/python3.10/site-packages pip
onnxruntime 1.20.1 /github/home/.local/lib/python3.10/site-packages pip
onnxsim 0.4.36 /github/home/.local/lib/python3.10/site-packages pip
packaging 24.2 /github/home/.local/lib/python3.10/site-packages pip
pandas 2.2.3 /github/home/.local/lib/python3.10/site-packages pip
pillow 11.0.0 /github/home/.local/lib/python3.10/site-packages pip
pip 22.0.4 /usr/local/lib/python3.10/site-packages pip
pluggy 1.5.0 /github/home/.local/lib/python3.10/site-packages pip
protobuf 5.29.2 /github/home/.local/lib/python3.10/site-packages pip
Pygments 2.18.0 /github/home/.local/lib/python3.10/site-packages pip
pytest 8.3.4 /github/home/.local/lib/python3.10/site-packages pip
pytest-xdist 3.6.1 /github/home/.local/lib/python3.10/site-packages pip
python-dateutil 2.9.0.post0 /github/home/.local/lib/python3.10/site-packages pip
python-dotenv 1.0.1 /github/home/.local/lib/python3.10/site-packages pip
python-json-logger 3.2.1 /github/home/.local/lib/python3.10/site-packages pip
pytz 2024.2 /github/home/.local/lib/python3.10/site-packages pip
PyYAML 6.0.2 /github/home/.local/lib/python3.10/site-packages pip
regex 2024.11.6 /github/home/.local/lib/python3.10/site-packages pip
requests 2.32.3 /github/home/.local/lib/python3.10/site-packages pip
rich 13.9.4 /github/home/.local/lib/python3.10/site-packages pip
safetensors 0.4.5 /github/home/.local/lib/python3.10/site-packages pip
scipy 1.[14](/runs/952286/job/1969259#step:10:15).1 /github/home/.local/lib/python3.10/site-packages pip
sentencepiece 0.2.0 /github/home/.local/lib/python3.10/site-packages pip
setuptools 58.1.0 /usr/local/lib/python3.10/site-packages pip
six 1.17.0 /github/home/.local/lib/python3.10/site-packages pip
sympy 1.13.3 /github/home/.local/lib/python3.10/site-packages pip
tabulate 0.9.0 /github/home/.local/lib/python3.10/site-packages pip
tokenizers 0.[15](/runs/952286/job/1969259#step:10:16).2 /github/home/.local/lib/python3.10/site-packages pip
tomli 2.2.1 /github/home/.local/lib/python3.10/site-packages pip
torch 2.2.2 /github/home/.local/lib/python3.10/site-packages pip
torchvision 0.[17](/runs/952286/job/1969259#step:10:18).2 /github/home/.local/lib/python3.10/site-packages pip
tqdm 4.67.1 /github/home/.local/lib/python3.10/site-packages pip
transformers 4.38.2 /github/home/.local/lib/python3.10/site-packages pip
triton 2.2.0 /github/home/.local/lib/python3.10/site-packages pip
typing_extensions 4.12.2 /github/home/.local/lib/python3.10/site-packages pip
tzdata [20](/runs/952286/job/1969259#step:10:21)24.2 /github/home/.local/lib/python3.10/site-packages pip
urllib3 2.3.0 /github/home/.local/lib/python3.10/site-packages pip
wheel 0.37.1 /usr/local/lib/python3.10/site-packages pip
zipp 3.[21](/runs/952286/job/1969259#step:10:22).0 /github/home/.local/lib/python3.10/site-packages pip

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks a lot for reporting @fjeremic! We were able to replicate for torch <= 2.2. It seems to not cause the import errors for >= 2.3. We will be doing a patch release soon to fix this behaviour. Sorry for the inconvenience!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for providing a quick fix!
For completeness, I was running into the import error with torch 2.2.2 when importing AutoencoderKL

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@BeckerFelix@fjeremic The patch release is out! Hope it fixes any problems you were facing in torch < 2.3

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

Labels

quantizationroadmapAdd to current release roadmap

Projects

None yet

Development

Successfully merging this pull request may close these issues.

11 participants

@a-r-r-o-w@HuggingFaceDocBuilderDev@jerryzh168@yiyixuxu@DN6@fjeremic@sayakpaul@BeckerFelix@SunMarc@stevhliu@bghira