Buckets:

hf-doc-build/doc / diffusers /main /ja /modular_diffusers /components_manager.md
mishig's picture
|
download
raw
5.84 kB
# ComponentsManager
> [!WARNING]
> [ComponentsManager](/docs/diffusers/main/ja/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) は現在も開発が進行中で、API が変更される可能性があります。
[ComponentsManager](/docs/diffusers/main/ja/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) は、Modular Diffusers 向けのモデルレジストリおよび管理システムです。モデルの追加と追跡を行い、有用なメタデータ(モデルサイズ、デバイス配置、アダプター)を保存し、オフローディングをサポートします。
このガイドでは、[ComponentsManager](/docs/diffusers/main/ja/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager)を使用してコンポーネントとデバイスメモリを管理する方法について説明します。
## パイプラインに接続
Create a [ComponentsManager](/docs/diffusers/main/ja/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) and pass it to a [ModularPipeline](/docs/diffusers/main/ja/api/modular_diffusers/pipeline#diffusers.ModularPipeline) with either [from_pretrained()](/docs/diffusers/main/ja/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained) or [init_pipeline()](/docs/diffusers/main/ja/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline).
```py
from diffusers import ModularPipeline, ComponentsManager
import torch
manager = ComponentsManager()
pipe = ModularPipeline.from_pretrained("Tongyi-MAI/Z-Image-Turbo", components_manager=manager)
pipe.load_components(dtype=torch.bfloat16)
```
```py
from diffusers import ModularPipelineBlocks, ComponentsManager
import torch
manager = ComponentsManager()
blocks = ModularPipelineBlocks.from_pretrained("diffusers/Florence2-image-Annotator", trust_remote_code=True)
pipe= blocks.init_pipeline(components_manager=manager)
pipe.load_components(dtype=torch.bfloat16)
```
pipeline によって読み込まれるコンポーネントは、マネージャーに自動的に登録されます。すぐにそれらをインスペクトできます。
## コンポーネントの検査
[ComponentsManager](/docs/diffusers/main/ja/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) を出力すると、クラス、デバイス配置、dtype、メモリサイズ、ロード ID を含む、登録されたすべてのコンポーネントを確認できます。
以下の出力は、上記の`from_pretrained`の例に対応しています。
```py
Components:
=============================================================================================================================
Models:
-----------------------------------------------------------------------------------------------------------------------------
Name_ID | Class | Device: act(exec) | Dtype | Size (GB) | Load ID
-----------------------------------------------------------------------------------------------------------------------------
text_encoder_140458257514752 | Qwen3Model | cpu | torch.bfloat16 | 7.49 | Tongyi-MAI/Z-Image-Turbo|text_encoder|null|null
vae_140458257515376 | AutoencoderKL | cpu | torch.bfloat16 | 0.16 | Tongyi-MAI/Z-Image-Turbo|vae|null|null
transformer_140458257515616 | ZImageTransformer2DModel | cpu | torch.bfloat16 | 11.46 | Tongyi-MAI/Z-Image-Turbo|transformer|null|null
-----------------------------------------------------------------------------------------------------------------------------
Other Components:
-----------------------------------------------------------------------------------------------------------------------------
ID | Class | Collection
-----------------------------------------------------------------------------------------------------------------------------
scheduler_140461023555264 | FlowMatchEulerDiscreteScheduler | N/A
tokenizer_140458256346432 | Qwen2Tokenizer | N/A
-----------------------------------------------------------------------------------------------------------------------------
```
このテーブルでは、モデル(デバイス、dtype、メモリ情報を含む)と、スケジューラーやトークナイザーなどの他のコンポーネントを別々に表示しています。モデルに LoRA アダプター、IP-Adapter、または量子化が適用されている場合、その情報は下部の追加セクションに表示されます。
## オフローディング
[enable_auto_cpu_offload()](/docs/diffusers/main/ja/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager.enable_auto_cpu_offload) メソッドは、どのパイプラインがモデルを使用しているかに関係なく、すべてのモデルで機能するグローバルなオフロード戦略です。有効化後は、コンポーネントの追加や削除時にデバイスの配置を気にする必要はありません。
```py
manager.enable_auto_cpu_offload(device="cuda") # or "mps", "xpu", "cpu"
```
すべてのモデルはCPU上で開始され、[ComponentsManager](/docs/diffusers/main/ja/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager)はモデルが必要になる直前に適切なデバイスへ移動し、GPUメモリが不足している場合は他のモデルをCPUへ戻します。
オフロードを無効にするには、[disable_auto_cpu_offload()](/docs/diffusers/main/ja/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager.disable_auto_cpu_offload)を呼び出します。
```py
manager.disable_auto_cpu_offload()
```

Xet Storage Details

Size:
5.84 kB
·
Xet hash:
46bd75ea9b27d7acef63a3f935f89ee1d2effe421e8622dcb415b210213b972e

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