Buckets:
| # ComponentsManager | |
| > [!WARNING] | |
| > [ComponentsManager](/docs/diffusers/main/vi/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) vẫn đang trong quá trình phát triển tích cực và API của nó có thể thay đổi. | |
| [ComponentsManager](/docs/diffusers/main/vi/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) là hệ thống đăng ký và quản lý mô hình cho Modular Diffusers. Nó thêm và theo dõi các mô hình, lưu trữ các siêu dữ liệu hữu ích (kích thước mô hình, vị trí thiết bị, adapter) và hỗ trợ offloading. | |
| Hướng dẫn này sẽ cho bạn thấy cách sử dụng [ComponentsManager](/docs/diffusers/main/vi/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) để quản lý các thành phần và bộ nhớ thiết bị. | |
| ## Kết nối với một pipeline | |
| Tạo một [ComponentsManager](/docs/diffusers/main/vi/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) và truyền nó vào một [ModularPipeline](/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline) bằng cách sử dụng [from_pretrained()](/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained) hoặc [init_pipeline()](/docs/diffusers/main/vi/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) | |
| ``` | |
| Các thành phần được nạp bởi pipeline sẽ được đăng ký tự động trong manager. Bạn có thể kiểm tra chúng ngay lập tức. | |
| ## Kiểm tra các thành phần | |
| In [ComponentsManager](/docs/diffusers/main/vi/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) để xem tất cả các thành phần đã đăng ký, bao gồm lớp, vị trí thiết bị, dtype, kích thước bộ nhớ và ID tải. | |
| Đầu ra bên dưới tương ứng với ví dụ `from_pretrained` ở trên. | |
| ```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 | |
| ----------------------------------------------------------------------------------------------------------------------------- | |
| ``` | |
| Bảng hiển thị các model (kèm thông tin về device, dtype và bộ nhớ) tách biệt với các thành phần khác như scheduler và tokenizer. Nếu bất kỳ model nào có áp dụng LoRA adapters, IP-Adapters hoặc lượng tử hóa, thông tin đó sẽ được hiển thị trong một phần bổ sung ở cuối. | |
| ## Offloading | |
| Phương thức [enable_auto_cpu_offload()](/docs/diffusers/main/vi/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager.enable_auto_cpu_offload) là một chiến lược offload toàn cục, hoạt động trên tất cả các mô hình bất kể pipeline nào đang sử dụng chúng. Một khi đã được bật, bạn không cần lo lắng về việc đặt thiết bị nếu thêm hoặc xóa các thành phần. | |
| ```py | |
| manager.enable_auto_cpu_offload(device="cuda") # or "mps", "xpu", "cpu" | |
| ``` | |
| Tất cả các model bắt đầu trên CPU và [ComponentsManager](/docs/diffusers/main/vi/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager) sẽ di chuyển chúng sang thiết bị phù hợp ngay trước khi cần dùng, đồng thời di chuyển các model khác trở lại CPU khi bộ nhớ GPU thấp. | |
| Gọi [disable_auto_cpu_offload()](/docs/diffusers/main/vi/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager.disable_auto_cpu_offload) để tắt offloading. | |
| ```py | |
| manager.disable_auto_cpu_offload() | |
| ``` | |
Xet Storage Details
- Size:
- 5.7 kB
- Xet hash:
- 7bfea56390e3abdb4b967d5f1aa9a75f9d46526ca5b74ffe4f8843af7855fbd6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.