Buckets:

mishig's picture
|
download
raw
4.58 kB
# AutoModel
[AutoModel](/docs/diffusers/main/tr/api/models/auto_model#diffusers.AutoModel) sınıfı, `config.json` dosyasından doğru model sınıfını (UNet, transformer, VAE) otomatik olarak algılar ve yükler. Önceden belirli model sınıfının adını bilmenize gerek yoktur. Veri türlerini ve cihaz yerleşimini destekler ve farklı model türleri ile kütüphaneler arasında çalışır.
Aşağıdaki örnek, Diffusers'tan bir transformer ve Transformers'tan bir metin kodlayıcı yükler. `config.json` dosyasının nereden yükleneceğini belirtmek için `subfolder` parametresini kullanın.
```py
import torch
from diffusers import AutoModel, DiffusionPipeline
transformer = AutoModel.from_pretrained(
"Qwen/Qwen-Image", subfolder="transformer", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu"
)
text_encoder = AutoModel.from_pretrained(
"Qwen/Qwen-Image", subfolder="text_encoder", dtype=torch.bfloat16, device_map="cuda"
)
```
## Özel modeller
[AutoModel](/docs/diffusers/main/tr/api/models/auto_model#diffusers.AutoModel), Diffusers'ta yer almayan [Hub](https://huggingface.co/models) modellerini de yükler. Özel modelleri yüklemek için [AutoModel.from_pretrained()](/docs/diffusers/main/tr/api/models/auto_model#diffusers.AutoModel.from_pretrained) içinde `trust_remote_code=True` değerini ayarlayın.
Özel bir model deposu, model sınıfını içeren bir Python modülü ve `"AutoModel"` anahtarını `"module_file.ClassName"` değerine eşleyen bir `auto_map` girdisi bulunan `config.json` dosyası gerektirir.
```
custom/custom-transformer-model/
├── config.json
├── my_model.py
└── diffusion_pytorch_model.safetensors
```
`config.json`, özel sınıfa işaret eden `auto_map` alanını içerir.
```json
{
"auto_map": {
"AutoModel": "my_model.MyCustomModel"
}
}
```
Ardından `trust_remote_code=True` ile yükleyin.
```py
import torch
from diffusers import AutoModel
transformer = AutoModel.from_pretrained(
"custom/custom-transformer-model", trust_remote_code=True, dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu"
)
```
Gerçek dünya örneği olarak, [Overworld/Waypoint-1-Small](https://huggingface.co/Overworld/Waypoint-1-Small/tree/main/transformer), `transformer` alt klasöründeki birkaç modülde özel bir `WorldModel` sınıfı barındırır.
```
transformer/
├── config.json # auto_map: "model.WorldModel"
├── model.py
├── attn.py
├── nn.py
├── cache.py
├── quantize.py
├── __init__.py
└── diffusion_pytorch_model.safetensors
```
```py
import torch
from diffusers import AutoModel
transformer = AutoModel.from_pretrained(
"Overworld/Waypoint-1-Small", subfolder="transformer", trust_remote_code=True, dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu"
)
```
Özel model [ModelMixin](/docs/diffusers/main/tr/api/models/overview#diffusers.ModelMixin) sınıfından türetiliyorsa, [regional compilation](../optimization/fp16#regional-compilation) ve [group offloading](../optimization/memory#group-offloading) gibi Diffusers model sınıflarının aynı özelliklerine erişim sağlar.
> [!WARNING]
> `trust_remote_code=True` kullanırken bir önlem olarak, kodun yeni kötü amaçlı kodlarla güncellenmediğinden emin olmak için [AutoModel.from_pretrained()](/docs/diffusers/main/tr/api/models/auto_model#diffusers.AutoModel.from_pretrained) içindeki `revision` argümanına bir commit hash'i iletin (model sahiplerine tamamen güvenmiyorsanız).
>
> ```py
> transformer = AutoModel.from_pretrained(
> "Overworld/Waypoint-1-Small", subfolder="transformer", trust_remote_code=True, revision="a3d8cb2"
> )
> ```
## Özel modellerin kaydedilmesi
Kaydetme sırasında `config.json` dosyasına `auto_map` girdisini otomatik olarak eklemek için `register_for_auto_class()` kullanın. Bu, yapılandırma dosyasını manuel olarak düzenleme gereksinimini ortadan kaldırır.
```py
# my_model.py
from diffusers import ModelMixin, ConfigMixin
class MyCustomModel(ModelMixin, ConfigMixin):
...
MyCustomModel.register_for_auto_class("AutoModel")
model = MyCustomModel(...)
model.save_pretrained("./my_model")
```
Kaydedilen `config.json`, `auto_map` alanını içerecektir.
```json
{
"auto_map": {
"AutoModel": "my_model.MyCustomModel"
}
}
```
## Sonraki adımlar
Özel modellerin uygulanması hakkında daha fazla bilgi için [Topluluk bileşenleri](../using-diffusers/custom_pipeline_overview#community-components) kılavuzuna göz atın.

Xet Storage Details

Size:
4.58 kB
·
Xet hash:
934c1d6830b97bfbe0b52daf014363ee13c1bbb39e79dec291edc663d777a4bb

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