Buckets:

rtrm's picture
|
download
raw
1.95 kB
# AutoModel
The [AutoModel](/docs/diffusers/pr_12762/en/api/models/auto_model#diffusers.AutoModel) class automatically detects and loads the correct model class (UNet, transformer, VAE) from a `config.json` file. You don't need to know the specific model class name ahead of time. It supports data types and device placement, and works across model types and libraries.
The example below loads a transformer from Diffusers and a text encoder from Transformers. Use the `subfolder` parameter to specify where to load the `config.json` file from.
```py
import torch
from diffusers import AutoModel, DiffusionPipeline
transformer = AutoModel.from_pretrained(
"Qwen/Qwen-Image", subfolder="transformer", torch_dtype=torch.bfloat16, device_map="cuda"
)
text_encoder = AutoModel.from_pretrained(
"Qwen/Qwen-Image", subfolder="text_encoder", torch_dtype=torch.bfloat16, device_map="cuda"
)
```
[AutoModel](/docs/diffusers/pr_12762/en/api/models/auto_model#diffusers.AutoModel) also loads models from the [Hub](https://huggingface.co/models) that aren't included in Diffusers. Set `trust_remote_code=True` in [AutoModel.from_pretrained()](/docs/diffusers/pr_12762/en/api/models/auto_model#diffusers.AutoModel.from_pretrained) to load custom models.
```py
import torch
from diffusers import AutoModel
transformer = AutoModel.from_pretrained(
"custom/custom-transformer-model", trust_remote_code=True, torch_dtype=torch.bfloat16, device_map="cuda"
)
```
If the custom model inherits from the [ModelMixin](/docs/diffusers/pr_12762/en/api/models/overview#diffusers.ModelMixin) class, it gets access to the same features as Diffusers model classes, like [regional compilation](../optimization/fp16#regional-compilation) and [group offloading](../optimization/memory#group-offloading).
> [!NOTE]
> Learn more about implementing custom models in the [Community components](../using-diffusers/custom_pipeline_overview#community-components) guide.

Xet Storage Details

Size:
1.95 kB
·
Xet hash:
392e96acc9f2f6dd6dbf77ad5701a9109b61c2992ede3f6bafb0bcb17f15f9ed

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.