Buckets:
| # ๋ชจ๋ธ | |
| ๐ค Diffusers๋ ์ธ๊ธฐ ์๋ ์๊ณ ๋ฆฌ์ฆ์ ๋ํ ์ฌ์ ํ์ต๋ ๋ชจ๋ธ๊ณผ ์ปค์คํ diffusion ์์คํ ์ ์์ฑํ๊ธฐ ์ํ ๋ชจ๋์ ์ ๊ณตํฉ๋๋ค. ๋ชจ๋ธ์ ์ฃผ์ ๊ธฐ๋ฅ์ ๋ถํฌ \\(p_{\theta}(x_{t-1}|x_{t})\\)๋ก ๋ชจ๋ธ๋ง๋ ์ ๋ ฅ ์ํ์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๋ ๊ฒ์ ๋๋ค. | |
| ๋ชจ๋ ๋ชจ๋ธ์ ๋ก์ปฌ ๋ฐ Hugging Face Hub์์ ๋ชจ๋ธ์ ์ ์ฅํ๊ณ ๋ก๋ํ๋ ๊ธฐ๋ณธ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ [`torch.nn.Module`](https://pytorch.org/docs/stable/generated/torch.nn.Module.html)์ธ ๊ธฐ๋ณธ [ModelMixin](/docs/diffusers/main/ko/api/models/overview#diffusers.ModelMixin) ํด๋์ค๋ก ๊ตฌ์ฑ๋ฉ๋๋ค. | |
| ## ModelMixin[[diffusers.ModelMixin]] | |
| #### diffusers.ModelMixin[[diffusers.ModelMixin]] | |
| ```python | |
| diffusers.ModelMixin() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L243) | |
| ๋ชจ๋ ๋ชจ๋ธ์ ๋ฒ ์ด์ค ํด๋์ค์ ๋๋ค. | |
| [ModelMixin](/docs/diffusers/main/ko/api/models/overview#diffusers.ModelMixin)์ ๋ชจ๋ธ ๊ตฌ์ฑ์ ์ ์ฅํ๋ ์ญํ ์ ํ๋ฉฐ, ๋ชจ๋ธ์ ๋ก๋, ๋ค์ด๋ก๋ ๋ฐ ์ ์ฅํ๋ ๋ฉ์๋๋ฅผ ์ ๊ณตํฉ๋๋ค. | |
| - **config_name** (`str`) -- [save_pretrained()](/docs/diffusers/main/ko/api/models/overview#diffusers.ModelMixin.save_pretrained)๋ฅผ ํธ์ถํ ๋ ๋ชจ๋ธ์ ์ ์ฅํ ํ์ผ ์ด๋ฆ. | |
| #### compile_repeated_blocks[[diffusers.ModelMixin.compile_repeated_blocks]] | |
| ```python | |
| compile_repeated_blocks(*args, **kwargs) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L1678) | |
| ๋ชจ๋ธ ์ ์ฒด๋ฅผ ์ปดํ์ผํ๋ ๋์ , ๋ชจ๋ธ ๋ด์์ ๋ฐ๋ณต์ ์ผ๋ก ์คํ๋๋ ์๋ธ๋ชจ๋(์: Transformer ๋ ์ด์ด)๋ง *์ปดํ์ผ*ํฉ๋๋ค. ์ด ๊ธฐ๋ฒ์ **๋ฆฌ์ ๋ ์ปดํ์ผ**(PyTorch ๋ ์ํผ https://docs.pytorch.org/tutorials/recipes/regional_compilation.html ์ฐธ์กฐ)์ด๋ผ๊ณ ๋ ๋ถ๋ฆฌ๋ฉฐ, ์ ์ฒด `torch.compile`์์ ๊ธฐ๋ํ ์ ์๋ ๋ฐํ์ ์๋ ํฅ์์ ์ ์งํ๋ฉด์ ์๋ํฌ์๋ ์ปดํ์ผ ์๊ฐ์ ํฌ๊ฒ ์ค์ผ ์ ์์ต๋๋ค. | |
| ์ปดํ์ผํ ์๋ธ๋ชจ๋ ์งํฉ์ ๋ชจ๋ธ ์ ์์ **`_repeated_blocks`** ์์ฑ์ด ์กด์ฌํ๋์ง ์ฌ๋ถ๋ก ๊ฒฐ์ ๋ฉ๋๋ค. ์ด ์์ฑ์ ๋ชจ๋ธ ์๋ธํด๋์ค์ ํด๋์ค ์ด๋ฆ(๋ฌธ์์ด)์ ๋ฆฌ์คํธ/ํํ๋ก ์ ์ํ์ญ์์ค. ํด๋์ค ์ด๋ฆ์ด ์ผ์นํ๋ ๋ชจ๋ ๋ชจ๋์ด ์ปดํ์ผ๋ฉ๋๋ค. | |
| ๋ฐ๊ฒฌ๋ ๊ฐ ๋งค์นญ ์๋ธ๋ชจ๋์ `submodule.compile(*args, **kwargs)`๋ฅผ ํธ์ถํ์ฌ ์ปดํ์ผ๋ฉ๋๋ค. `compile_repeated_blocks`์ ์ ๋ฌํ๋ ๋ชจ๋ ์์น ์ธ์ ๋๋ ํค์๋ ์ธ์๋ `torch.compile`์ ๊ทธ๋๋ก ์ ๋ฌ๋ฉ๋๋ค. | |
| #### cuda[[diffusers.ModelMixin.cuda]] | |
| ```python | |
| cuda(*args, **kwargs) | |
| ``` | |
| ์ ์ผ๋ก ๊ตฌ๋ถ๋ ๊ฒฝ๋ก(์: `torch.float32`)์ mock ๊ฐ์ ๋๋ค: ์์ฑ ์ ๊ทผ ์ฒด์ธ, ํธ์ถ์ pass-through ๋ฐ์ฝ๋ ์ดํฐ์ฒ๋ผ ๋์ํ๋ฉฐ, `repr`์ ํด๋น ์ ์ผ๋ก ๊ตฌ๋ถ๋ ๊ฒฝ๋ก์ ๋๋ค. ์ด๋ฅผ ๋ฒ ์ด์ค ํด๋์ค๋ก ์ฌ์ฉํ๋ฉด plain-`type` ๋ฒ ์ด์ค๋ก ๋์ฒด๋ฉ๋๋ค(PEP 560 `__mro_entries__`). ๋ฐ๋ผ์ ์ค์ ์๋ธํด๋์ค๋ ์ผ๋ฐ์ ์ธ ๋ฉํํด๋์ค๋ฅผ ์ ์งํ๊ณ , `inspect.signature`๋ mock์ ๊ฒ์ด ์๋๋ผ ์ค์ `__init__`๋ฅผ ์ฝ์ต๋๋ค. | |
| #### dequantize[[diffusers.ModelMixin.dequantize]] | |
| ```python | |
| dequantize() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L894) | |
| ์์ํ ๋ฐฉ๋ฒ ์ค ์ญ์์ํ๋ฅผ ์ง์ํ๋ ๊ฒ์ผ๋ก ์์ํ๋ ๊ฒฝ์ฐ, ๋ชจ๋ธ์ ์ญ์์ํํ ์ ์์ต๋๋ค. | |
| #### disable_gradient_checkpointing[[diffusers.ModelMixin.disable_gradient_checkpointing]] | |
| ```python | |
| disable_gradient_checkpointing() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L327) | |
| ํ์ฌ ๋ชจ๋ธ์ ๋ํ gradient checkpointing์ ๋นํ์ฑํํฉ๋๋ค(๋ค๋ฅธ ํ๋ ์์ํฌ์์๋ *activation checkpointing* ๋๋ *checkpoint activations*๋ผ๊ณ ๋ ๋ถ๋ฆฝ๋๋ค). | |
| #### disable_npu_flash_attention[[diffusers.ModelMixin.disable_npu_flash_attention]] | |
| ```python | |
| disable_npu_flash_attention() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L358) | |
| torch_npu์์ npu flash attention ๋นํ์ฑํ | |
| #### disable_xformers_memory_efficient_attention[[diffusers.ModelMixin.disable_xformers_memory_efficient_attention]] | |
| ```python | |
| disable_xformers_memory_efficient_attention() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L441) | |
| [xFormers](https://facebookresearch.github.io/xformers/)์์ ๋ฉ๋ชจ๋ฆฌ ํจ์จ์ ์ดํ ์ ์ ๋นํ์ฑํํฉ๋๋ค. | |
| #### disable_xla_flash_attention[[diffusers.ModelMixin.disable_xla_flash_attention]] | |
| ```python | |
| disable_xla_flash_attention() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L388) | |
| torch_xla์ flash attention pallals ์ปค๋์ ๋นํ์ฑํํฉ๋๋ค. | |
| #### enable_gradient_checkpointing[[diffusers.ModelMixin.enable_gradient_checkpointing]] | |
| ```python | |
| enable_gradient_checkpointing(gradient_checkpointing_func: typing.Optional[typing.Callable] = None) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L297) | |
| **๋งค๊ฐ๋ณ์:** | |
| gradient_checkpointing_func (`Callable`, *์ ํ ์ฌํญ*) : gradient checkpointing์ ์ฌ์ฉํ ํจ์์ ๋๋ค. `None`์ธ ๊ฒฝ์ฐ, ๊ธฐ๋ณธ PyTorch checkpointing ํจ์(`torch.utils.checkpoint.checkpoint`)๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. | |
| ํ์ฌ ๋ชจ๋ธ์ ๋ํด gradient checkpointing์ ํ์ฑํํฉ๋๋ค(๋ค๋ฅธ ํ๋ ์์ํฌ์์๋ *activation checkpointing* ๋๋ *checkpoint activations*๋ผ๊ณ ๋ ๋ถ๋ฆฝ๋๋ค). | |
| #### enable_group_offload[[diffusers.ModelMixin.enable_group_offload]] | |
| ```python | |
| enable_group_offload(onload_device: device, offload_device: device = torch.device(), offload_type: str = 'block_level', num_blocks_per_group: int | None = None, non_blocking: bool = False, use_stream: bool = False, record_stream: bool = False, low_cpu_mem_usage = False, offload_to_disk_path: str | None = None, block_modules: str | None = None, exclude_kwargs: str | None = None) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L532) | |
| ํ์ฌ ๋ชจ๋ธ์ ๋ํ ๊ทธ๋ฃน ์คํ๋ก๋ฉ์ ํ์ฑํํฉ๋๋ค. | |
| ์์ธํ ๋ด์ฉ์ [apply_group_offloading()](/docs/diffusers/main/ko/api/utilities#diffusers.hooks.apply_group_offloading)์ ์ฐธ์กฐํ์ธ์. | |
| ์: | |
| ```python | |
| >>> from diffusers import CogVideoXTransformer3DModel | |
| >>> transformer = CogVideoXTransformer3DModel.from_pretrained( | |
| ... "THUDM/CogVideoX-5b", subfolder="transformer", torch_dtype=torch.bfloat16 | |
| ... ) | |
| >>> transformer.enable_group_offload( | |
| ... onload_device=torch.device("cuda"), | |
| ... offload_device=torch.device("cpu"), | |
| ... offload_type="leaf_level", | |
| ... use_stream=True, | |
| ... ) | |
| ``` | |
| #### enable_layerwise_casting[[diffusers.ModelMixin.enable_layerwise_casting]] | |
| ```python | |
| enable_layerwise_casting(storage_dtype: dtype = torch.float8_e4m3fn, compute_dtype: typing.Optional[torch.dtype] = None, skip_modules_pattern: tuple[str, ...] | None = None, skip_modules_classes: tuple[typing.Type[torch.nn.Module], ...] | None = None, non_blocking: bool = False) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L447) | |
| **๋งค๊ฐ๋ณ์:** | |
| storage_dtype (`torch.dtype`) : ๋ชจ๋ธ์ด ์ ์ฅ๋๋๋ก ์บ์คํ ๋์ด์ผ ํ dtype์ ๋๋ค. | |
| compute_dtype (`torch.dtype`) : forward pass ์ค์ ๋ชจ๋ธ ๊ฐ์ค์น๋ฅผ ์บ์คํ ํ dtype์ ๋๋ค. | |
| skip_modules_pattern (`tuple[str, ...]`, *์ ํ ์ฌํญ*) : ๋ ์ด์ด๋ณ ์บ์คํ ๊ณผ์ ์์ ๊ฑด๋๋ธ ๋ชจ๋์ ์ด๋ฆ์ ์ผ์น์ํค๊ธฐ ์ํ ํจํด ๋ชฉ๋ก์ ๋๋ค. `None`์ผ๋ก ์ค์ ํ๋ฉด, ๋ชจ๋์ ํน์ ๋ด๋ถ ๋ ์ด์ด์ PEFT ๋ ์ด์ด๋ฅผ ๋ฌด์ํ๊ธฐ ์ํ ๊ธฐ๋ณธ ๊ฑด๋๋ฐ๊ธฐ ํจํด์ด ์ฌ์ฉ๋ฉ๋๋ค. | |
| skip_modules_classes (`tuple[Type[torch.nn.Module], ...]`, *์ ํ ์ฌํญ*) : ๋ ์ด์ด๋ณ ์บ์คํ ๊ณผ์ ์์ ๊ฑด๋๋ธ ๋ชจ๋ ํด๋์ค ๋ชฉ๋ก์ ๋๋ค. | |
| non_blocking (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : `True`์ธ ๊ฒฝ์ฐ, ๊ฐ์ค์น ์บ์คํ ์์ ์ด ๋น์ฐจ๋จ(non-blocking) ๋ฐฉ์์ผ๋ก ์ํ๋ฉ๋๋ค. | |
| ํ์ฌ ๋ชจ๋ธ์ ๋ํด ๋ ์ด์ด๋ณ ์บ์คํ ์ ํ์ฑํํฉ๋๋ค. | |
| Layerwise casting์ ๋ชจ๋ธ ๊ฐ์ค์น๋ฅผ ์ ์ฅ์ ์ํด ๋ ๋ฎ์ ์ ๋ฐ๋์ dtype์ผ๋ก ๋ณํํ๋, ๊ณ์ฐ ์์๋ ๋ ๋์ ์ ๋ฐ๋์ dtype์ผ๋ก ์ฆ์ ๋ณํํ๋ ๊ธฐ๋ฒ์ ๋๋ค. ์ด ๊ณผ์ ์ ๋ชจ๋ธ ๊ฐ์ค์น๋ก ์ธํ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ํฌ๊ฒ ์ค์ผ ์ ์์ง๋ง, ์ถ๋ ฅ์ ํ์ง์ด ์ผ๋ถ ์ ํ๋ ์ ์์ต๋๋ค. ๋๋ถ๋ถ์ ํ์ง ์ ํ๋ ๋ฌด์ํ ์ ์๋ ์์ค์ด๋ฉฐ, ์ฃผ๋ก ์ ๊ทํ ๋ฐ ๋ณ์กฐ ๋ ์ด์ด์ ๊ฐ์ค์น ๋ณํ์์ ๋น๋กฏ๋ฉ๋๋ค. | |
| ๊ธฐ๋ณธ์ ์ผ๋ก diffusers์ ๋๋ถ๋ถ์ ๋ชจ๋ธ์ ํจ์น ์๋ฒ ๋ฉ, ์์น ์๋ฒ ๋ฉ ๋ฐ ์ ๊ทํ ๋ ์ด์ด๋ฅผ ๋ฌด์ํ๋๋ก `_skip_layerwise_casting_patterns` ์์ฑ์ ์ค์ ํฉ๋๋ค. ์ด๋ ์ด๋ฌํ ๋ ์ด์ด๊ฐ ํ์ง์ ์์ด ์ ๋ฐ๋๊ฐ ๊ฐ์ฅ ์ค์ํ ๊ฐ๋ฅ์ฑ์ด ๋๊ธฐ ๋๋ฌธ์ ๋๋ค. ์ด ๋์์ ๋ณ๊ฒฝํ๋ ค๋ฉด `_skip_layerwise_casting_patterns` ์์ฑ์ `None`์ผ๋ก ์ค์ ํ๊ฑฐ๋, ์ฌ์ฉ์ ์ ์ ์ธ์๋ฅผ ์ฌ์ฉํ์ฌ [apply_layerwise_casting()](/docs/diffusers/main/ko/api/utilities#diffusers.hooks.apply_layerwise_casting)์ ํธ์ถํ ์ ์์ต๋๋ค. | |
| ์: | |
| [enable_layerwise_casting()](/docs/diffusers/main/ko/api/models/overview#diffusers.ModelMixin.enable_layerwise_casting) ์ฌ์ฉ: | |
| ```python | |
| >>> from diffusers import CogVideoXTransformer3DModel | |
| >>> transformer = CogVideoXTransformer3DModel.from_pretrained( | |
| ... "THUDM/CogVideoX-5b", subfolder="transformer", torch_dtype=torch.bfloat16 | |
| ... ) | |
| >>> # Enable layerwise casting via the model, which ignores certain modules by default | |
| >>> transformer.enable_layerwise_casting(storage_dtype=torch.float8_e4m3fn, compute_dtype=torch.bfloat16) | |
| ``` | |
| #### enable_npu_flash_attention[[diffusers.ModelMixin.enable_npu_flash_attention]] | |
| ```python | |
| enable_npu_flash_attention() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L351) | |
| torch_npu์์ npu flash attention ํ์ฑํ | |
| #### enable_xformers_memory_efficient_attention[[diffusers.ModelMixin.enable_xformers_memory_efficient_attention]] | |
| ```python | |
| enable_xformers_memory_efficient_attention(attention_op: typing.Optional[typing.Callable] = None) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L409) | |
| **๋งค๊ฐ๋ณ์:** | |
| attention_op (`Callable`, *์ ํ ์ฌํญ*) : xFormers์ [`memory_efficient_attention()`](https://facebookresearch.github.io/xformers/components/ops.html#xformers.ops.memory_efficient_attention) ํจ์์ `op` ์ธ์๋ก ์ฌ์ฉ๋ ๋ ๊ธฐ๋ณธ `None` ์ฐ์ฐ์๋ฅผ ์ฌ์ ์ํฉ๋๋ค. | |
| [xFormers](https://facebookresearch.github.io/xformers/)์์ ๋ฉ๋ชจ๋ฆฌ ํจ์จ์ ์ธ ์ดํ ์ ์ ํ์ฑํํฉ๋๋ค. | |
| ์ด ์ต์ ์ด ํ์ฑํ๋๋ฉด GPU ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ด ๋ฎ์์ง๊ณ ์ถ๋ก ๊ณผ์ ์์ ์๋ ํฅ์์ด ๊ด์ฐฐ๋ ์ ์์ต๋๋ค. ํ์ต ๊ณผ์ ์์์ ์๋ ํฅ์์ ๋ณด์ฅ๋์ง ์์ต๋๋ค. | |
| > [!WARNING] > โ ๏ธ memory efficient attention๊ณผ sliced attention์ด ๋ชจ๋ ํ์ฑํ๋ ๊ฒฝ์ฐ, memory efficient | |
| attention์ > ์ฐ์ ์์๋ฅผ ๊ฐ์ง๋๋ค. | |
| ์: | |
| ```py | |
| >>> import torch | |
| >>> from diffusers import UNet2DConditionModel | |
| >>> from xformers.ops import MemoryEfficientAttentionFlashAttentionOp | |
| >>> model = UNet2DConditionModel.from_pretrained( | |
| ... "stabilityai/stable-diffusion-2-1", subfolder="unet", torch_dtype=torch.float16 | |
| ... ) | |
| >>> model = model.to("cuda") | |
| >>> model.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp) | |
| ``` | |
| #### enable_xla_flash_attention[[diffusers.ModelMixin.enable_xla_flash_attention]] | |
| ```python | |
| enable_xla_flash_attention(partition_spec: typing.Optional[typing.Callable] = None, **kwargs) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L382) | |
| torch_xla์ ๋ํ flash attention pallals ์ปค๋์ ํ์ฑํํฉ๋๋ค. | |
| #### from_pretrained[[diffusers.ModelMixin.from_pretrained]] | |
| ```python | |
| from_pretrained(pretrained_model_name_or_path: str | os.PathLike | None, **kwargs) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L906) | |
| **๋งค๊ฐ๋ณ์:** | |
| pretrained_model_name_or_path (`str` ๋๋ `os.PathLike`, *์ ํ ์ฌํญ*) : ๋ค์ ์ค ํ๋์ผ ์ ์์ต๋๋ค. - Hub์ ํธ์คํ ๋ ์ฌ์ ํ์ต ๋ชจ๋ธ์ *๋ชจ๋ธ ID* ๋ฌธ์์ด(์: `google/ddpm-celebahq-256`). - [save_pretrained()](/docs/diffusers/main/ko/api/models/overview#diffusers.ModelMixin.save_pretrained)๋ก ์ ์ฅ๋ ๋ชจ๋ธ ๊ฐ์ค์น๋ฅผ ํฌํจํ๋ *๋๋ ํฐ๋ฆฌ* ๊ฒฝ๋ก(์: `./my_model_directory`). | |
| cache_dir (`str | os.PathLike`, *์ ํ ์ฌํญ*) : ํ์ค ์บ์๋ฅผ ์ฌ์ฉํ์ง ์์ ๊ฒฝ์ฐ, ๋ค์ด๋ก๋๋ ์ฌ์ ํ์ต ๋ชจ๋ธ ๊ตฌ์ฑ์ด ์บ์๋๋ ๋๋ ํฐ๋ฆฌ์ ๊ฒฝ๋ก์ ๋๋ค. | |
| dtype (`torch.dtype`, *์ ํ ์ฌํญ*) : ๊ธฐ๋ณธ `torch.dtype`๋ฅผ ์ฌ์ ์ํ์ฌ ๋ค๋ฅธ dtype๋ก ๋ชจ๋ธ์ ๋ก๋ํฉ๋๋ค. | |
| force_download (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ์บ์๋ ๋ฒ์ ์ด ์กด์ฌํ๋๋ผ๋ ๋ชจ๋ธ ๊ฐ์ค์น ๋ฐ ๊ตฌ์ฑ ํ์ผ์ (์ฌ)๋ค์ด๋ก๋๋ฅผ ๊ฐ์ ํ ์ง ์ฌ๋ถ. | |
| proxies (`dict[str, str]`, *์ ํ ์ฌํญ*) : ํ๋กํ ์ฝ ๋๋ ์๋ํฌ์ธํธ๋ณ๋ก ์ฌ์ฉํ ํ๋ก์ ์๋ฒ์ ์ฌ์ ์ ๋๋ค. ์๋ฅผ ๋ค์ด, `{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}`์ ๊ฐ์ต๋๋ค. ๊ฐ ์์ฒญ์ ํ๋ก์๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. | |
| output_loading_info (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ๋๋ฝ๋ ํค, ์์์น ๋ชปํ ํค ๋ฐ ์ค๋ฅ ๋ฉ์์ง๊ฐ ํฌํจ๋ ์ฌ์ ๋ ํจ๊ป ๋ฐํํ ์ง ์ฌ๋ถ. | |
| local_files_only(`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ๋ก์ปฌ ๋ชจ๋ธ ๊ฐ์ค์น ๋ฐ ๊ตฌ์ฑ ํ์ผ๋ง ๋ก๋ํ ์ง ์ฌ๋ถ์ ๋๋ค. `True`๋ก ์ค์ ํ๋ฉด Hub์์ ๋ชจ๋ธ์ ๋ค์ด๋ก๋ํ์ง ์์ต๋๋ค. | |
| token (`str` ๋๋ *bool*, *์ ํ ์ฌํญ*) : ์๊ฒฉ ํ์ผ์ ๋ํ HTTP bearer ์ธ์ฆ์ผ๋ก ์ฌ์ฉํ ํ ํฐ์ ๋๋ค. `True`์ธ ๊ฒฝ์ฐ, `diffusers-cli login`์์ ์์ฑ๋ ํ ํฐ(`~/.huggingface`์ ์ ์ฅ๋จ)์ด ์ฌ์ฉ๋ฉ๋๋ค. | |
| revision (`str`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `"main"`) : ์ฌ์ฉํ ํน์ ๋ชจ๋ธ ๋ฒ์ ์ ๋๋ค. Git์์ ํ์ฉํ๋ ๋ธ๋์น ์ด๋ฆ, ํ๊ทธ ์ด๋ฆ, ์ปค๋ฐ ID ๋๋ ๊ธฐํ ์๋ณ์์ผ ์ ์์ต๋๋ค. | |
| subfolder (`str`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `""`) : Hub ๋๋ ๋ก์ปฌ์ ๋ ํฐ ๋ชจ๋ธ ์ ์ฅ์ ๋ด์์ ๋ชจ๋ธ ํ์ผ์ ์๋ธํด๋ ์์น์ ๋๋ค. | |
| mirror (`str`, *์ ํ ์ฌํญ*) : ์ค๊ตญ์์ ๋ชจ๋ธ์ ๋ค์ด๋ก๋ํ ๋ ์ ๊ทผ์ฑ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํ ๋ฏธ๋ฌ ์์ค์ ๋๋ค. ํด๋น ์์ค์ ์ ์์ฑ์ด๋ ์์ ์ฑ์ ๋ณด์ฅํ์ง ์์ผ๋ฉฐ, ์์ธํ ๋ด์ฉ์ ๋ฏธ๋ฌ ์ฌ์ดํธ๋ฅผ ์ฐธ๊ณ ํ์ธ์. | |
| device_map (`int | str | torch.device` ๋๋ `dict[str, int | str | torch.device]`, *์ ํ ์ฌํญ*) : ๊ฐ ์๋ธ๋ชจ๋์ด ์ด๋์ ๋ฐฐ์น๋์ด์ผ ํ๋์ง ์ง์ ํ๋ ๋งต์ ๋๋ค. ๋ชจ๋ ํ๋ผ๋ฏธํฐ/๋ฒํผ ์ด๋ฆ์ ๋ํด ์ ์ํ ํ์๋ ์์ผ๋ฉฐ, ํน์ ๋ชจ๋ ์ด๋ฆ์ด ๋งต์ ํฌํจ๋๋ฉด ํด๋น ๋ชจ๋์ ๋ชจ๋ ์๋ธ๋ชจ๋์ด ๋์ผํ ๋๋ฐ์ด์ค๋ก ์ ์ก๋ฉ๋๋ค. ๊ธฐ๋ณธ๊ฐ์ `None`์ด๋ฉฐ, ์ด๋ ๋ชจ๋ธ์ด CPU์ ๋ก๋๋จ์ ์๋ฏธํฉ๋๋ค. ์์: ```py >>> from diffusers import AutoModel >>> import torch >>> # This works. >>> model = AutoModel.from_pretrained( ... "stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", device_map="cuda" ... ) >>> # This also works (integer accelerator device ID). >>> model = AutoModel.from_pretrained( ... "stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", device_map=0 ... ) >>> # Specifying a supported offloading strategy like "auto" also works. >>> model = AutoModel.from_pretrained( ... "stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", device_map="auto" ... ) >>> # Specifying a dictionary as `device_map` also works. >>> model = AutoModel.from_pretrained( ... "stabilityai/stable-diffusion-xl-base-1.0", ... subfolder="unet", ... device_map={"": torch.device("cuda")}, ... ) ``` `device_map="auto"`๋ฅผ ์ค์ ํ๋ฉด ๐ค Accelerate๊ฐ ๊ฐ์ฅ ์ต์ ํ๋ `device_map`์ ์๋์ผ๋ก ๊ณ์ฐํฉ๋๋ค. ๊ฐ ์ต์ ์ ๋ํ ์์ธํ ๋ด์ฉ์ [device map ์ค๊ณ](https://huggingface.co/docs/accelerate/en/concept_guides/big_model_inference#the-devicemap)๋ฅผ ์ฐธ๊ณ ํ์ธ์. ๋ ๊ตฌ์ฒด์ ์ธ ์์๋ [Diffusers ์ ์ฉ ๋ฌธ์](https://huggingface.co/docs/diffusers/main/en/training/distributed_inference#model-sharding)๋ฅผ ์ฐธ๊ณ ํ ์ ์์ต๋๋ค. | |
| max_memory (`Dict`, *์ ํ ์ฌํญ*) : ์ต๋ ๋ฉ๋ชจ๋ฆฌ์ ๋ํ ๋๋ฐ์ด์ค ์๋ณ์๋ฅผ ๋ํ๋ด๋ ์ฌ์ ์ ๋๋ค. ์ค์ ๋์ง ์์ผ๋ฉด ๊ฐ GPU์ ์ฌ์ฉ ๊ฐ๋ฅํ ์ต๋ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ์ฉ ๊ฐ๋ฅํ CPU RAM์ด ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. | |
| offload_folder (`str` ๋๋ `os.PathLike`, *์ ํ ์ฌํญ*) : `device_map`์ `"disk"` ๊ฐ์ด ํฌํจ๋ ๊ฒฝ์ฐ, ๊ฐ์ค์น๋ฅผ ์คํ๋ก๋ํ ๊ฒฝ๋ก์ ๋๋ค. | |
| offload_state_dict (`bool`, *์ ํ ์ฌํญ*) : `True`์ธ ๊ฒฝ์ฐ, CPU ์ํ ์ฌ์ ์ ๊ฐ์ค์น์ ์ฒดํฌํฌ์ธํธ์ ๊ฐ์ฅ ํฐ ์ค๋ ํฉ์ด CPU RAM์ ๋ง์ง ์์ ๋ CPU RAM ๋ถ์กฑ์ ๋ฐฉ์งํ๊ธฐ ์ํด CPU ์ํ ์ฌ์ ์ ํ๋ ๋๋ผ์ด๋ธ๋ก ์ผ์์ ์ผ๋ก ์คํ๋ก๋ํฉ๋๋ค. ๋์คํฌ ์คํ๋ก๋๊ฐ ์๋ ๊ฒฝ์ฐ ๊ธฐ๋ณธ๊ฐ์ `True`์ ๋๋ค. | |
| low_cpu_mem_usage (`bool`, *์ ํ ์ฌํญ*, torch ๋ฒ์ ์ด 1.9.0 ์ด์์ด๋ฉด ๊ธฐ๋ณธ๊ฐ์ `True`, ๊ทธ ์ธ์๋ `False`) : ๊ฐ์ค์น๋ฅผ ์ด๊ธฐํํ์ง ์๊ณ ์ฌ์ ํ์ต๋ ๊ฐ์ค์น๋ง ๋ก๋ํ์ฌ ๋ชจ๋ธ ๋ก๋ฉ ์๋๋ฅผ ๋์ ๋๋ค. ๋ชจ๋ธ ๋ก๋ฉ ์ CPU ๋ฉ๋ชจ๋ฆฌ(ํผํฌ ๋ฉ๋ชจ๋ฆฌ ํฌํจ)๋ฅผ ๋ชจ๋ธ ํฌ๊ธฐ์ 1๋ฐฐ๋ฅผ ์ด๊ณผํ์ง ์๋๋ก ์๋ํฉ๋๋ค. PyTorch 1.9.0 ์ด์์์๋ง ์ง์๋ฉ๋๋ค. PyTorch์ ์ด์ ๋ฒ์ ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ด ์ธ์๋ฅผ `True`๋ก ์ค์ ํ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. | |
| variant (`str`, *์ ํ ์ฌํญ*) : `"fp16"` ๋๋ `"ema"`์ ๊ฐ์ ์ง์ ๋ `variant` ํ์ผ ์ด๋ฆ์์ ๊ฐ์ค์น๋ฅผ ๋ก๋ํฉ๋๋ค. | |
| use_safetensors (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `None`) : `None`์ผ๋ก ์ค์ ๋ ๊ฒฝ์ฐ, `safetensors` ๊ฐ์ค์น๊ฐ ์ฌ์ฉ ๊ฐ๋ฅํ **๊ทธ๋ฆฌ๊ณ ** `safetensors` ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ค์น๋์ด ์์ผ๋ฉด ๋ค์ด๋ก๋๋ฉ๋๋ค. `True`๋ก ์ค์ ๋ ๊ฒฝ์ฐ, ๋ชจ๋ธ์ `safetensors` ๊ฐ์ค์น์์ ๊ฐ์ ๋ก ๋ก๋๋ฉ๋๋ค. `False`๋ก ์ค์ ๋ ๊ฒฝ์ฐ, `safetensors` ๊ฐ์ค์น๋ ๋ก๋๋์ง ์์ต๋๋ค. | |
| disable_mmap ('bool', *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ 'False') : Safetensors ๋ชจ๋ธ์ ๋ก๋ํ ๋ mmap์ ๋นํ์ฑํํ ์ง ์ฌ๋ถ์ ๋๋ค. ๋คํธ์ํฌ ๋ง์ดํธ๋ ํ๋ ๋๋ผ์ด๋ธ์ ๋ชจ๋ธ์ด ์๋ ๊ฒฝ์ฐ, mmap์ seek ๋์์ ์ ์ฒ๋ฆฌํ์ง ๋ชปํ ์ ์์ผ๋ฏ๋ก ์ด ์ต์ ์ ์ฌ์ฉํ๋ฉด ์ฑ๋ฅ์ด ๋ ์ข์์ง ์ ์์ต๋๋ค. | |
| use_flashpack (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : `True`๋ก ์ค์ ํ๋ฉด ๋ชจ๋ธ์ `flashpack` ๊ฐ์ค์น์์ ๋ก๋๋ฉ๋๋ค. | |
| flashpack_kwargs(`dict[str, Any]`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `{}`) : [`flashpack.deserialization.assign_from_file`](https://github.com/fal-ai/flashpack/blob/f1aa91c5cd9532a3dbf5bcc707ab9b01c274b76c/src/flashpack/deserialization.py#L408-L422)์ ์ ๋ฌ๋๋ Kwargs | |
| pretrained model configuration์์ ์ฌ์ ํ์ต๋ PyTorch ๋ชจ๋ธ์ ์ด๊ธฐํํฉ๋๋ค. | |
| ๋ชจ๋ธ์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ๊ฐ ๋ชจ๋(`model.eval()`)๋ก ์ค์ ๋๋ฉฐ, dropout ๋ชจ๋์ ๋นํ์ฑํ๋ฉ๋๋ค. ๋ชจ๋ธ์ ํ์ตํ๋ ค๋ฉด `model.train()`์ ์ฌ์ฉํ์ฌ ๋ค์ ํ์ต ๋ชจ๋๋ก ์ค์ ํ์ธ์. | |
| > [!TIP] > ๋น๊ณต๊ฐ ๋๋ [๊ฒ์ดํธ๋ ๋ชจ๋ธ](https://huggingface.co/docs/hub/models-gated#gated-models)์ ์ฌ์ฉํ๋ ค๋ฉด ๋ก๊ทธ์ธํ์ธ์ | |
| `hf > auth login`์(๋ฅผ) ํตํด ์ํํ ์ ์์ต๋๋ค. ๋ํ ๋ฐฉํ๋ฒฝ์ด ์๋ ํ๊ฒฝ์์ ์ด ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ ค๋ฉด ํน์ํ ["์คํ๋ผ์ธ ๋ชจ๋"](https://huggingface.co/diffusers/installation.html#offline-mode)๋ฅผ ํ์ฑํํ ์๋ ์์ต๋๋ค. | |
| ์: | |
| ```py | |
| from diffusers import UNet2DConditionModel | |
| unet = UNet2DConditionModel.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", subfolder="unet") | |
| ``` | |
| ์๋์ ๊ฐ์ ์ค๋ฅ ๋ฉ์์ง๊ฐ ํ์๋๋ฉด ๋ค์ด์คํธ๋ฆผ ์์ ์ ์ํด ๊ฐ์ค์น๋ฅผ ๋ฏธ์ธ ์กฐ์ ํด์ผ ํฉ๋๋ค: | |
| ```bash | |
| Some weights of UNet2DConditionModel were not initialized from the model checkpoint at stable-diffusion-v1-5/stable-diffusion-v1-5 and are newly initialized because the shapes did not match: | |
| - conv_in.weight: found shape torch.Size([320, 4, 3, 3]) in the checkpoint and torch.Size([320, 9, 3, 3]) in the model instantiated | |
| You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. | |
| ``` | |
| #### get_memory_footprint[[diffusers.ModelMixin.get_memory_footprint]] | |
| ```python | |
| get_memory_footprint(return_buffers = True) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L2186) | |
| **๋งค๊ฐ๋ณ์:** | |
| return_buffers (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `True`) : ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ๊ณ์ฐ ์ ๋ฒํผ ํ ์์ ํฌ๊ธฐ๋ฅผ ๋ฐํํ ์ง ์ฌ๋ถ์ ๋๋ค. ๋ฒํผ๋ ๊ทธ๋๋์ธํธ๊ฐ ํ์ํ์ง ์๊ณ ํ๋ผ๋ฏธํฐ๋ก ๋ฑ๋ก๋์ง ์์ ํ ์๋ฅผ ์๋ฏธํฉ๋๋ค. ์๋ฅผ ๋ค์ด, ๋ฐฐ์น ์ ๊ทํ ๋ ์ด์ด์ mean๊ณผ std๊ฐ ํด๋น๋ฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ๋ค์์ ์ฐธ์กฐํ์ธ์: https://discuss.pytorch.org/t/what-pytorch-means-by-buffers/120266/2 | |
| ๋ชจ๋ธ์ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ๊ฐ์ ธ์ต๋๋ค. ์ด ํจ์๋ ํ์ฌ ๋ชจ๋ธ์ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ๋ฐ์ดํธ ๋จ์๋ก ๋ฐํํฉ๋๋ค. ํ์ฌ ๋ชจ๋ธ์ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ๋ฒค์น๋งํนํ๊ณ ํ ์คํธ๋ฅผ ์ค๊ณํ๋ ๋ฐ ์ ์ฉํฉ๋๋ค. PyTorch ํ ๋ก ์์ ์๊ฐ์ ๋ฐ์ ํด๊ฒฐ์ฑ ์ ๋๋ค: https://discuss.pytorch.org/t/gpu-memory-that-model-uses/56822/2 | |
| #### num_parameters[[diffusers.ModelMixin.num_parameters]] | |
| ```python | |
| num_parameters(only_trainable: bool = False, exclude_embeddings: bool = False) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L2122) | |
| **๋งค๊ฐ๋ณ์:** | |
| only_trainable (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ํ์ต ๊ฐ๋ฅํ ๋งค๊ฐ๋ณ์์ ์๋ง ๋ฐํํ ์ง ์ฌ๋ถ. | |
| exclude_embeddings (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ์๋ฒ ๋ฉ์ด ์๋ ๋งค๊ฐ๋ณ์์ ๊ฐ์๋ง ๋ฐํํ ์ง ์ฌ๋ถ. | |
| **๋ฐํ๊ฐ:** `int` | |
| ํ๋ผ๋ฏธํฐ์ ์. | |
| ๋ชจ๋์ (ํ์ต ๊ฐ๋ฅ ๋๋ ์๋ฒ ๋ฉ์ด ์๋) ๋งค๊ฐ๋ณ์ ์๋ฅผ ๊ฐ์ ธ์ต๋๋ค. | |
| ์: | |
| ```py | |
| from diffusers import UNet2DConditionModel | |
| model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5" | |
| unet = UNet2DConditionModel.from_pretrained(model_id, subfolder="unet") | |
| unet.num_parameters(only_trainable=True) | |
| 859520964 | |
| ``` | |
| #### reset_attention_backend[[diffusers.ModelMixin.reset_attention_backend]] | |
| ```python | |
| reset_attention_backend() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L667) | |
| ๋ชจ๋ธ์ attention backends๋ฅผ ์ด๊ธฐํํฉ๋๋ค. ์ดํ `forward` ํธ์ถ ์ ์ค์ ๋ ํ๊ฒฝ ๊ธฐ๋ณธ๊ฐ ๋๋ torch ๋ค์ดํฐ๋ธ scaled dot product attention์ ์ฌ์ฉํฉ๋๋ค. | |
| #### save_pretrained[[diffusers.ModelMixin.save_pretrained]] | |
| ```python | |
| save_pretrained(save_directory: str | os.PathLike, is_main_process: bool = True, save_function: typing.Optional[typing.Callable] = None, safe_serialization: bool = True, variant: str | None = None, max_shard_size: int | str = '10GB', push_to_hub: bool = False, use_flashpack: bool = False, **kwargs) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L686) | |
| **๋งค๊ฐ๋ณ์:** | |
| save_directory (`str` ๋๋ `os.PathLike`) : ๋ชจ๋ธ๊ณผ ํด๋น ๊ตฌ์ฑ ํ์ผ์ ์ ์ฅํ ๋๋ ํฐ๋ฆฌ์ ๋๋ค. ์กด์ฌํ์ง ์์ผ๋ฉด ์์ฑ๋ฉ๋๋ค. | |
| is_main_process (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `True`) : ์ด ํจ์๋ฅผ ํธ์ถํ๋ ํ๋ก์ธ์ค๊ฐ ๋ฉ์ธ ํ๋ก์ธ์ค์ธ์ง ์ฌ๋ถ์ ๋๋ค. ๋ถ์ฐ ํ์ต ์ค์ ๋ชจ๋ ํ๋ก์ธ์ค์์ ์ด ํจ์๋ฅผ ํธ์ถํด์ผ ํ๋ ๊ฒฝ์ฐ ์ ์ฉํฉ๋๋ค. ์ด ๊ฒฝ์ฐ ๋ ์ด์ค ์กฐ๊ฑด์ ๋ฐฉ์งํ๊ธฐ ์ํด ๋ฉ์ธ ํ๋ก์ธ์ค์์๋ง `is_main_process=True`๋ก ์ค์ ํ์ธ์. | |
| save_function (`Callable`) : ์ํ ์ฌ์ (state dictionary)์ ์ ์ฅํ๋ ๋ฐ ์ฌ์ฉํ ํจ์์ ๋๋ค. ๋ถ์ฐ ํ์ต ์ค์ `torch.save`๋ฅผ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ๋์ฒดํด์ผ ํ๋ ๊ฒฝ์ฐ ์ ์ฉํฉ๋๋ค. ํ๊ฒฝ ๋ณ์ `DIFFUSERS_SAVE_MODE`๋ก ์ค์ ํ ์ ์์ต๋๋ค. | |
| safe_serialization (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `True`) : `safetensors` ๋๋ `pickle`๋ฅผ ์ฌ์ฉํ ์ ํต์ ์ธ PyTorch ๋ฐฉ์์ผ๋ก ๋ชจ๋ธ์ ์ ์ฅํ ์ง ์ฌ๋ถ. | |
| variant (`str`, *์ ํ ์ฌํญ*) : ์ง์ ๋ ๊ฒฝ์ฐ, ๊ฐ์ค์น๊ฐ `pytorch_model.<variant>.bin` ํ์์ผ๋ก ์ ์ฅ๋ฉ๋๋ค. | |
| max_shard_size (`int` ๋๋ `str`, ๊ธฐ๋ณธ๊ฐ์ `"10GB"`) : ์ค๋ฉ๋๊ธฐ ์ ์ฒดํฌํฌ์ธํธ์ ์ต๋ ํฌ๊ธฐ์ ๋๋ค. ์ค๋ฉ๋ ๊ฐ ์ฒดํฌํฌ์ธํธ์ ํฌ๊ธฐ๋ ์ด ํฌ๊ธฐ๋ณด๋ค ์์์ง๋๋ค. ๋ฌธ์์ด๋ก ํํํ ๊ฒฝ์ฐ, ์ซ์ ๋ค์ ๋จ์(์: `"5GB"`)๊ฐ ๋ฐ๋ผ์์ผ ํฉ๋๋ค. ์ ์๋ก ํํํ ๊ฒฝ์ฐ, ๋จ์๋ ๋ฐ์ดํธ์ ๋๋ค. 2024๋ 10์๋ถํฐ ํน์ ๊ธฐ๊ฐ์ด ์ง๋ ํ ์ด ์ ํ์ด ๋ฎ์์ง ์ ์์ผ๋ฉฐ, ์ด๋ ์ฌ์ฉ์๊ฐ `diffusers`์ ์ต์ ๋ฒ์ ์ผ๋ก ์ ๊ทธ๋ ์ด๋ํ ์ ์๋๋ก ํ๊ธฐ ์ํ ๊ฒ์ ๋๋ค. ์ด๋ Hugging Face ์ํ๊ณ์ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(์: `transformers`, `accelerate`)์์ ์ด ์ธ์์ ๊ณตํต ๊ธฐ๋ณธ ํฌ๊ธฐ๋ฅผ ์ค์ ํ๊ธฐ ์ํ ๊ฒ์ ๋๋ค. | |
| push_to_hub (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ๋ชจ๋ธ์ ์ ์ฅํ ํ Hugging Face Hub์ ํธ์ํ ์ง ์ฌ๋ถ์ ๋๋ค. `repo_id`๋ฅผ ์ฌ์ฉํ์ฌ ํธ์ํ ์ ์ฅ์๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค(๊ธฐ๋ณธ๊ฐ์ ๋ค์์คํ์ด์ค์ `save_directory` ์ด๋ฆ์ ๋๋ค). | |
| kwargs (`dict[str, Any]`, *์ ํ ์ฌํญ*) : [push_to_hub()](/docs/diffusers/main/ko/api/schedulers/overview#diffusers.utils.PushToHubMixin.push_to_hub) ๋ฉ์๋์ ํจ๊ป ์ ๋ฌ๋๋ ์ถ๊ฐ ํค์๋ ์ธ์์ ๋๋ค. | |
| ๋ชจ๋ธ๊ณผ ํด๋น ๊ตฌ์ฑ ํ์ผ์ ๋๋ ํ ๋ฆฌ์ ์ ์ฅํ์ฌ [from_pretrained()](/docs/diffusers/main/ko/api/models/overview#diffusers.ModelMixin.from_pretrained) ํด๋์ค ๋ฉ์๋๋ฅผ ์ฌ์ฉํด ๋ค์ ๋ก๋ํ ์ ์๋๋ก ํฉ๋๋ค. | |
| #### set_attention_backend[[diffusers.ModelMixin.set_attention_backend]] | |
| ```python | |
| set_attention_backend(backend: str) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L608) | |
| **๋งค๊ฐ๋ณ์:** | |
| backend (`str`) : ์ค์ ํ ๋ฐฑ์๋์ ์ด๋ฆ์ ๋๋ค. `AttentionBackendName`์ ์ ์๋ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฐฑ์๋ ์ค ํ๋์ฌ์ผ ํฉ๋๋ค. ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฐฑ์๋๋ `diffusers.attention_dispatch.AttentionBackendName`์์ ํ์ธํ ์ ์์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ์ torch ๋ค์ดํฐ๋ธ scaled dot product attention์ ๋ฐฑ์๋๋ก ์ฌ์ฉํฉ๋๋ค. | |
| ๋ชจ๋ธ์ attention ๋ฐฑ์๋๋ฅผ ์ค์ ํฉ๋๋ค. | |
| #### set_use_npu_flash_attention[[diffusers.ModelMixin.set_use_npu_flash_attention]] | |
| ```python | |
| set_use_npu_flash_attention(valid: bool) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/modeling_utils.py#L335) | |
| npu flash attention ์ค์์น๋ฅผ ์ค์ ํฉ๋๋ค. | |
| #### (์ผ)๋ก[[diffusers.ModelMixin.to]] | |
| ```python | |
| to(*args, **kwargs) | |
| ``` | |
| ์ ์ผ๋ก ๊ตฌ๋ถ๋ ๊ฒฝ๋ก(์: `torch.float32`)์ mock ๊ฐ์ ๋๋ค: ์์ฑ ์ ๊ทผ ์ฒด์ธ, ํธ์ถ์ pass-through ๋ฐ์ฝ๋ ์ดํฐ์ฒ๋ผ ๋์ํ๋ฉฐ, `repr`์ ํด๋น ์ ์ผ๋ก ๊ตฌ๋ถ๋ ๊ฒฝ๋ก์ ๋๋ค. ์ด๋ฅผ ๋ฒ ์ด์ค ํด๋์ค๋ก ์ฌ์ฉํ๋ฉด plain-`type` ๋ฒ ์ด์ค๋ก ๋์ฒด๋ฉ๋๋ค(PEP 560 `__mro_entries__`). ๋ฐ๋ผ์ ์ค์ ์๋ธํด๋์ค๋ ์ผ๋ฐ์ ์ธ ๋ฉํํด๋์ค๋ฅผ ์ ์งํ๊ณ , `inspect.signature`๋ mock์ ๊ฒ์ด ์๋๋ผ ์ค์ `__init__`๋ฅผ ์ฝ์ต๋๋ค. | |
| ## PushToHubMixin[[diffusers.utils.PushToHubMixin]] | |
| #### diffusers.utils.PushToHubMixin[[diffusers.utils.PushToHubMixin]] | |
| ```python | |
| diffusers.utils.PushToHubMixin() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/hub_utils.py#L491) | |
| Hugging Face Hub์ ๋ชจ๋ธ, ์ค์ผ์ค๋ฌ ๋๋ ํ์ดํ๋ผ์ธ์ ํธ์ํ๊ธฐ ์ํ Mixin์ ๋๋ค. | |
| #### push_to_hub[[diffusers.utils.PushToHubMixin.push_to_hub]] | |
| ```python | |
| push_to_hub(repo_id: str, commit_message: str | None = None, private: bool | None = None, token: str | None = None, create_pr: bool = False, safe_serialization: bool = True, variant: str | None = None, subfolder: str | None = None) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/hub_utils.py#L526) | |
| **๋งค๊ฐ๋ณ์:** | |
| repo_id (`str`) : ๋ชจ๋ธ, ์ค์ผ์ค๋ฌ ๋๋ ํ์ดํ๋ผ์ธ ํ์ผ์ ํธ์ํ ์ ์ฅ์์ ์ด๋ฆ์ ๋๋ค. ์กฐ์ง์ ํธ์ํ ๊ฒฝ์ฐ ์กฐ์ง ์ด๋ฆ์ ํฌํจํด์ผ ํฉ๋๋ค. `repo_id`๋ ๋ก์ปฌ ๋๋ ํฐ๋ฆฌ์ ๊ฒฝ๋ก์ผ ์๋ ์์ต๋๋ค. | |
| commit_message (`str`, *์ ํ ์ฌํญ*) : pushํ ๋ ์ปค๋ฐํ ๋ฉ์์ง. ๊ธฐ๋ณธ๊ฐ์ `"Upload {object}"`์ ๋๋ค. | |
| private (`bool`, *์ ํ ์ฌํญ*) : ์ ์ฅ์๋ฅผ ๋น๊ณต๊ฐ๋ก ๋ง๋ค์ง ์ฌ๋ถ์ ๋๋ค. `None`(๊ธฐ๋ณธ๊ฐ)์ธ ๊ฒฝ์ฐ, ์กฐ์ง์ ๊ธฐ๋ณธ ์ค์ ์ด ๋น๊ณต๊ฐ๊ฐ ์๋ ํ ์ ์ฅ์๋ ๊ณต๊ฐ๋ฉ๋๋ค. ์ด๋ฏธ ์ ์ฅ์๊ฐ ์กด์ฌํ๋ฉด ์ด ๊ฐ์ ๋ฌด์๋ฉ๋๋ค. | |
| token (`str`, *์ ํ ์ฌํญ*) : ์๊ฒฉ ํ์ผ์ ๋ํ HTTP bearer ์ธ์ฆ์ผ๋ก ์ฌ์ฉํ ํ ํฐ์ ๋๋ค. `hf auth login` ์คํ ์ ์์ฑ๋ ํ ํฐ์ด๋ฉฐ `~/.huggingface`์ ์ ์ฅ๋ฉ๋๋ค. | |
| create_pr (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ์ ๋ก๋๋ ํ์ผ๋ก PR์ ์์ฑํ ์ง ์๋๋ฉด ์ง์ ์ปค๋ฐํ ์ง ์ฌ๋ถ. | |
| safe_serialization (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `True`) : ๋ชจ๋ธ ๊ฐ์ค์น๋ฅผ `safetensors` ํ์์ผ๋ก ๋ณํํ ์ง ์ฌ๋ถ. | |
| variant (`str`, *์ ํ ์ฌํญ*) : ์ง์ ๋ ๊ฒฝ์ฐ, ๊ฐ์ค์น๊ฐ `pytorch_model.<variant>.bin` ํ์์ผ๋ก ์ ์ฅ๋ฉ๋๋ค. | |
| ๋ชจ๋ธ, ์ค์ผ์ค๋ฌ ๋๋ ํ์ดํ๋ผ์ธ ํ์ผ์ ๐ค Hugging Face Hub์ ์ ๋ก๋ํฉ๋๋ค. | |
| ์: | |
| ```python | |
| from diffusers import UNet2DConditionModel | |
| unet = UNet2DConditionModel.from_pretrained("stabilityai/stable-diffusion-2", subfolder="unet") | |
| # Push the `unet` to your namespace with the name "my-finetuned-unet". | |
| unet.push_to_hub("my-finetuned-unet") | |
| # Push the `unet` to an organization with the name "my-finetuned-unet". | |
| unet.push_to_hub("your-org/my-finetuned-unet") | |
| ``` | |
Xet Storage Details
- Size:
- 30.2 kB
- Xet hash:
- 98286f9bf0d3f2696c5c4826ae6ac40835636830a9489ccd4303c69da11ecc33
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.