huggingface / huggingface/diffusers
Flux1-Dev inference with single file ComfyUI/SD-Forge Safetensors
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 34.5k
- Forks
- 7.3k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 91
Description
Is it possible to run inference with diffusers using a single-file safetensors created for ComfyUI/SD-Forge?
It looks like FluxPipeline.from_single_file() might be intended for this purpose, but I'm getting the following errors:
import torch
from diffusers import FluxPipeline
pipe = FluxPipeline.from_single_file("./flux1-dev-fp8.safetensors", torch_dtype=torch.float8_e4m3fn, use_safetensors=True)
Traceback (most recent call last):
File "/home/user/flux/imgen.py", line 9, in <module>
pipe = FluxPipeline.from_single_file("./flux1-dev-fp8.safetensors", torch_dtype=torch.float8_e4m3fn, use_safetensors=True)
File "/home/user/.local/lib/python3.13/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
return fn(*args, **kwargs)
File "/home/user/.local/lib/python3.13/site-packages/diffusers/loaders/single_file.py", line 509, in from_single_file
loaded_sub_model = load_single_file_sub_model(
library_name=library_name,
...<11 lines>...
**kwargs,
)
File "/home/user/.local/lib/python3.13/site-packages/diffusers/loaders/single_file.py", line 127, in load_single_file_sub_model
loaded_sub_model = create_diffusers_t5_model_from_checkpoint(
class_obj,
...<4 lines>...
local_files_only=local_files_only,
)
File "/home/user/.local/lib/python3.13/site-packages/diffusers/loaders/single_file_utils.py", line 2156, in create_diffusers_t5_model_from_checkpoint
model.load_state_dict(diffusers_format_checkpoint)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.13/site-packages/torch/nn/modules/module.py", line 2641, in load_state_dict
raise RuntimeError(
...<3 lines>...
)
RuntimeError: Error(s) in loading state_dict for T5EncoderModel:
Missing key(s) in state_dict: "encoder.embed_tokens.weight".
I checked the safetensors file and the T5 encoder is present. However, it is named differently, which confuses diffusers.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with FluxPipeline.from_single_file in diffusers/loaders/single_file.py and the T5 conversion logic in diffusers/loaders/single_file_utils.py. Compare the safetensors T5 key naming described in the issue with the keys expected by T5EncoderModel; done means the reported single-file Flux1-Dev checkpoint loads without the missing encoder.embed_tokens.weight error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100