Skip to content

Flux.1 cannot load standard transformer in nf4 #9996

Description

@vladmandic

Describe the bug

loading different flux transformer models is fine except for nf4.
it works for 1% of fine-tunes provided on Huggingface, but it doesn't work for 99% standard fine-tunes available on CivitAI.

example of such model: https://civitai.com/models/118111?modelVersionId=1009051

note i'm using FluxTransformer2DModel directly as its easiest for reproduction plus majority of flux fine-tunes are provided as transformer-only, not full models. but where full model does exist, its exactly the same problem using FluxPipeline

Reproduction

importtorchimportbitsandbytesasbnbimportdiffusersprint(f'torch=={torch.__version__} diffusers=={diffusers.__version__} bnb=={bnb.__version__}')
kwargs= { 'low_cpu_mem_usage': True, 'torch_dtype': torch.bfloat16, 'cache_dir': '/mnt/models/huggingface' }
files= [
'flux-c4pacitor_v2alpha-f1s-bf16.safetensors',
'flux-iniverse_v2-f1d-fp8.safetensors',
'flux-copax_timeless_xplus_mix2-nf4.safetensors',
]
forfinfiles:
print(f)
try:
transformer=diffusers.FluxTransformer2DModel.from_single_file(f, **kwargs)
print(transformer.__class__)
exceptExceptionase:
print(e)
transformer=Nonetorch.cuda.empty_cache()

Logs

in`diffusers/loaders/single_file_utils.py:convert_flux_transformer_checkpoint_to_diffusers`
q, k, v, mlp = torch.split(checkpoint.pop(f"single_blocks.{i}.linear1.weight"), split_size, dim=0)
> RuntimeError: split_with_sizes expects split_sizes to sum exactly to 33030144 (input tensor's size at dimension 0), but got split_sizes=[3072, 3072, 3072, 12288]

System Info

torch==2.5.1+cu124 diffusers==0.32.0.dev0 bnb==0.44.1

Who can help?

@yiyixuxu@sayakpaul@DN6@asomoza

Activity

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingwip

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions