| <!--Copyright 2025 The HuggingFace Team. All rights reserved. | |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
| the License. You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| specific language governing permissions and limitations under the License. | |
| --> | |
| # ํ์ผ๋ค์ Hub๋ก ํธ์ํ๊ธฐ | |
| [[open-in-colab]] | |
| ๐ค Diffusers๋ ๋ชจ๋ธ, ์ค์ผ์ค๋ฌ ๋๋ ํ์ดํ๋ผ์ธ์ Hub์ ์ ๋ก๋ํ ์ ์๋ [`~diffusers.utils.PushToHubMixin`]์ ์ ๊ณตํฉ๋๋ค. ์ด๋ Hub์ ๋น์ ์ ํ์ผ์ ์ ์ฅํ๋ ์ฌ์ด ๋ฐฉ๋ฒ์ด๋ฉฐ, ๋ค๋ฅธ ์ฌ๋๋ค๊ณผ ์์ ์ ๊ณต์ ํ ์๋ ์์ต๋๋ค. ์ค์ ์ ์ผ๋ก [`~diffusers.utils.PushToHubMixin`]๊ฐ ๋์ํ๋ ๋ฐฉ์์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| 1. Hub์ ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค. | |
| 2. ๋์ค์ ๋ค์ ๋ถ๋ฌ์ฌ ์ ์๋๋ก ๋ชจ๋ธ, ์ค์ผ์ค๋ฌ ๋๋ ํ์ดํ๋ผ์ธ ํ์ผ์ ์ ์ฅํฉ๋๋ค. | |
| 3. ์ด๋ฌํ ํ์ผ์ด ํฌํจ๋ ํด๋๋ฅผ Hub์ ์ ๋ก๋ํฉ๋๋ค. | |
| ์ด ๊ฐ์ด๋๋ [`~diffusers.utils.PushToHubMixin`]์ ์ฌ์ฉํ์ฌ Hub์ ํ์ผ์ ์ ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค. | |
| ๋จผ์ ์ก์ธ์ค [ํ ํฐ](https://huggingface.co/settings/tokens)์ผ๋ก Hub ๊ณ์ ์ ๋ก๊ทธ์ธํด์ผ ํฉ๋๋ค: | |
| ```py | |
| from huggingface_hub import notebook_login | |
| notebook_login() | |
| ``` | |
| ## ๋ชจ๋ธ | |
| ๋ชจ๋ธ์ ํ๋ธ์ ํธ์ํ๋ ค๋ฉด [`~diffusers.utils.PushToHubMixin.push_to_hub`]๋ฅผ ํธ์ถํ๊ณ Hub์ ์ ์ฅํ ๋ชจ๋ธ์ ๋ฆฌํฌ์งํ ๋ฆฌ id๋ฅผ ์ง์ ํฉ๋๋ค: | |
| ```py | |
| from diffusers import ControlNetModel | |
| controlnet = ControlNetModel( | |
| block_out_channels=(32, 64), | |
| layers_per_block=2, | |
| in_channels=4, | |
| down_block_types=("DownBlock2D", "CrossAttnDownBlock2D"), | |
| cross_attention_dim=32, | |
| conditioning_embedding_out_channels=(16, 32), | |
| ) | |
| controlnet.push_to_hub("my-controlnet-model") | |
| ``` | |
| ๋ชจ๋ธ์ ๊ฒฝ์ฐ Hub์ ํธ์ํ ๊ฐ์ค์น์ [*๋ณํ*](loading#checkpoint-variants)์ ์ง์ ํ ์๋ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, `fp16` ๊ฐ์ค์น๋ฅผ ํธ์ํ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ํ์ธ์: | |
| ```py | |
| controlnet.push_to_hub("my-controlnet-model", variant="fp16") | |
| ``` | |
| [`~diffusers.utils.PushToHubMixin.push_to_hub`] ํจ์๋ ๋ชจ๋ธ์ `config.json` ํ์ผ์ ์ ์ฅํ๊ณ ๊ฐ์ค์น๋ `safetensors` ํ์์ผ๋ก ์๋์ผ๋ก ์ ์ฅ๋ฉ๋๋ค. | |
| ์ด์ Hub์ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ๋ชจ๋ธ์ ๋ค์ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค: | |
| ```py | |
| model = ControlNetModel.from_pretrained("your-namespace/my-controlnet-model") | |
| ``` | |
| ## ์ค์ผ์ค๋ฌ | |
| ์ค์ผ์ค๋ฌ๋ฅผ ํ๋ธ์ ํธ์ํ๋ ค๋ฉด [`~diffusers.utils.PushToHubMixin.push_to_hub`]๋ฅผ ํธ์ถํ๊ณ Hub์ ์ ์ฅํ ์ค์ผ์ค๋ฌ์ ๋ฆฌํฌ์งํ ๋ฆฌ id๋ฅผ ์ง์ ํฉ๋๋ค: | |
| ```py | |
| from diffusers import DDIMScheduler | |
| scheduler = DDIMScheduler( | |
| beta_start=0.00085, | |
| beta_end=0.012, | |
| beta_schedule="scaled_linear", | |
| clip_sample=False, | |
| set_alpha_to_one=False, | |
| ) | |
| scheduler.push_to_hub("my-controlnet-scheduler") | |
| ``` | |
| [`~diffusers.utils.PushToHubMixin.push_to_hub`] ํจ์๋ ์ค์ผ์ค๋ฌ์ `scheduler_config.json` ํ์ผ์ ์ง์ ๋ ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ ์ฅํฉ๋๋ค. | |
| ์ด์ ํ๋ธ์ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ์ค์ผ์ค๋ฌ๋ฅผ ๋ค์ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค: | |
| ```py | |
| scheduler = DDIMScheduler.from_pretrained("your-namepsace/my-controlnet-scheduler") | |
| ``` | |
| ## ํ์ดํ๋ผ์ธ | |
| ๋ชจ๋ ์ปดํฌ๋ํธ๊ฐ ํฌํจ๋ ์ ์ฒด ํ์ดํ๋ผ์ธ์ Hub๋ก ํธ์ํ ์๋ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, ์ํ๋ ํ๋ผ๋ฏธํฐ๋ก [`StableDiffusionPipeline`]์ ์ปดํฌ๋ํธ๋ค์ ์ด๊ธฐํํฉ๋๋ค: | |
| ```py | |
| from diffusers import ( | |
| UNet2DConditionModel, | |
| AutoencoderKL, | |
| DDIMScheduler, | |
| StableDiffusionPipeline, | |
| ) | |
| from transformers import CLIPTextModel, CLIPTextConfig, CLIPTokenizer | |
| unet = UNet2DConditionModel( | |
| block_out_channels=(32, 64), | |
| layers_per_block=2, | |
| sample_size=32, | |
| in_channels=4, | |
| out_channels=4, | |
| down_block_types=("DownBlock2D", "CrossAttnDownBlock2D"), | |
| up_block_types=("CrossAttnUpBlock2D", "UpBlock2D"), | |
| cross_attention_dim=32, | |
| ) | |
| scheduler = DDIMScheduler( | |
| beta_start=0.00085, | |
| beta_end=0.012, | |
| beta_schedule="scaled_linear", | |
| clip_sample=False, | |
| set_alpha_to_one=False, | |
| ) | |
| vae = AutoencoderKL( | |
| block_out_channels=[32, 64], | |
| in_channels=3, | |
| out_channels=3, | |
| down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"], | |
| up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"], | |
| latent_channels=4, | |
| ) | |
| text_encoder_config = CLIPTextConfig( | |
| bos_token_id=0, | |
| eos_token_id=2, | |
| hidden_size=32, | |
| intermediate_size=37, | |
| layer_norm_eps=1e-05, | |
| num_attention_heads=4, | |
| num_hidden_layers=5, | |
| pad_token_id=1, | |
| vocab_size=1000, | |
| ) | |
| text_encoder = CLIPTextModel(text_encoder_config) | |
| tokenizer = CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip") | |
| ``` | |
| ๋ชจ๋ ์ปดํฌ๋ํธ๋ค์ [`StableDiffusionPipeline`]์ ์ ๋ฌํ๊ณ [`~diffusers.utils.PushToHubMixin.push_to_hub`]๋ฅผ ํธ์ถํ์ฌ ํ์ดํ๋ผ์ธ์ Hub๋ก ํธ์ํฉ๋๋ค: | |
| ```py | |
| components = { | |
| "unet": unet, | |
| "scheduler": scheduler, | |
| "vae": vae, | |
| "text_encoder": text_encoder, | |
| "tokenizer": tokenizer, | |
| "safety_checker": None, | |
| "feature_extractor": None, | |
| } | |
| pipeline = StableDiffusionPipeline(**components) | |
| pipeline.push_to_hub("my-pipeline") | |
| ``` | |
| [`~diffusers.utils.PushToHubMixin.push_to_hub`] ํจ์๋ ๊ฐ ์ปดํฌ๋ํธ๋ฅผ ๋ฆฌํฌ์งํ ๋ฆฌ์ ํ์ ํด๋์ ์ ์ฅํฉ๋๋ค. ์ด์ Hub์ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ํ์ดํ๋ผ์ธ์ ๋ค์ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค: | |
| ```py | |
| pipeline = StableDiffusionPipeline.from_pretrained("your-namespace/my-pipeline") | |
| ``` | |
| ## ๋น๊ณต๊ฐ | |
| ๋ชจ๋ธ, ์ค์ผ์ค๋ฌ ๋๋ ํ์ดํ๋ผ์ธ ํ์ผ๋ค์ ๋น๊ณต๊ฐ๋ก ๋๋ ค๋ฉด [`~diffusers.utils.PushToHubMixin.push_to_hub`] ํจ์์์ `private=True`๋ฅผ ์ค์ ํ์ธ์: | |
| ```py | |
| controlnet.push_to_hub("my-controlnet-model-private", private=True) | |
| ``` | |
| ๋น๊ณต๊ฐ ๋ฆฌํฌ์งํ ๋ฆฌ๋ ๋ณธ์ธ๋ง ๋ณผ ์ ์์ผ๋ฉฐ ๋ค๋ฅธ ์ฌ์ฉ์๋ ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ๋ณต์ ํ ์ ์๊ณ ๋ฆฌํฌ์งํ ๋ฆฌ๊ฐ ๊ฒ์ ๊ฒฐ๊ณผ์ ํ์๋์ง ์์ต๋๋ค. ์ฌ์ฉ์๊ฐ ๋น๊ณต๊ฐ ๋ฆฌํฌ์งํ ๋ฆฌ์ URL์ ๊ฐ์ง๊ณ ์๋๋ผ๋ `404 - Sorry, we can't find the page you are looking for`๋ผ๋ ๋ฉ์์ง๊ฐ ํ์๋ฉ๋๋ค. ๋น๊ณต๊ฐ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ๋ชจ๋ธ์ ๋ก๋ํ๋ ค๋ฉด [๋ก๊ทธ์ธ](https://huggingface.co/docs/huggingface_hub/quick-start#login) ์ํ์ฌ์ผ ํฉ๋๋ค. |