-
Notifications
You must be signed in to change notification settings - Fork 5.9k
extend AutoModel to be able to load transformer models & custom diffusers models #11388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @yiyixuxu, I’d love to contribute to this enhancement if you haven’t started already! Just to clarify before I dive in: The current AutoModel implementation only supports models that are importable directly from the diffusers top-level namespace (e.g., via _class_name in config.json). For models like HiDream-I1-Full, which define components only in model_index.json, this approach breaks because the model class isn't found via Here's what I’m proposing at the AutoModel.from_pretrained level:
This would allow AutoModel to load both standard and custom model components defined in model_index.json, even if they’re not importable from diffusers directly. Let me know if you think this is the right approach or if you had a different level in mind (e.g., deeper integration into the loader logic in pipeline_utils.py)! |
hi @afafelwafi a few references might be helpful to you using model_index.json
from diffusers import pipelines
is_pipeline_module = hasattr(pipelines, library_name)
if is_pipeline_module:
pipeline_module = getattr(pipelines, library_name)
class_obj = getattr(pipeline_module, class_name)
else:
library = importlib.import_module(library_name)
class_obj = getattr(library, class_name)
from diffusers import AutoModel
import torch
# test1: load a diffusers model
try:
model = AutoModel.from_pretrained(
"HiDream-ai/HiDream-I1-Full", subfolder="transformer", torch_dtype=torch.bfloat16,
)
print(f"test1 passed!")
except Exception as e:
print(f"test1 failed: {e}")
# test2: load a non-diffusers model
try:
model = AutoModel.from_pretrained(
"HiDream-ai/HiDream-I1-Full", subfolder="text_encoder", torch_dtype=torch.bfloat16,
)
print(f"test2 passed!")
except Exception as e:
print(f"test2 failed: {e}")
# test3: load a custom diffusers model
# https://huggingface.co/Kwai-Kolors/Kolors-diffusers/blob/main/model_index.json#L9
try:
model = AutoModel.from_pretrained("Kwai-Kolors/Kolors-diffusers", subfolder="text_encoder", torch_dtype=torch.bfloat16)
print(f"test3 passed!")
except Exception as e:
print(f"test3 failed: {e}")
# test4: load a model directly (not subfolder)
controlnet_repo = "InstantX/SD3-Controlnet-Canny"
try:
controlnet_model = AutoModel.from_pretrained(
controlnet_repo, revision="refs/pr/12"
)
print(f"test4 passed!")
except Exception as e:
print(f"test4 failed: {e}") |
ohh @afafelwafi sorry, thanks for your interest though! we will keep posting issues like this |
current AutoModel implementation only support models that importable from diffusers
diffusers/src/diffusers/models/auto_model.py
Line 164 in 448c72a
it uses this field in model config.json https://huggingface.co/HiDream-ai/HiDream-I1-Full/blob/main/transformer/config.json#L2
we can use info in model_index.json instead, https://huggingface.co/HiDream-ai/HiDream-I1-Full/blob/main/model_index.json
this way we can load anything that can be load in
from_pretrained
, include transformer models & custom diffusers moduels (not directly importable from top level)can reference the code/logic in
from_pretrained
diffusers/src/diffusers/pipelines/pipeline_utils.py
Line 893 in 448c72a
I will work on this shortly, but feel free to pick this up if anyone in the community is interested!
The text was updated successfully, but these errors were encountered: