Spaces:
Runtime error
Runtime error
<!--Copyright 2022 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. | |
โ ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be | |
rendered properly in your Markdown viewer. | |
--> | |
# ๋ชจ๋ธ ๊ณต์ ํ๊ธฐ[[share-a-model]] | |
์ง๋ ๋ ํํ ๋ฆฌ์ผ์์ ๋ถ์ฐ ์ค์ ์ ์ํด PyTorch, Keras ๋ฐ ๐ค Accelerate๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์์ต๋๋ค. ๋ค์ ๋จ๊ณ๋ ๋ชจ๋ธ์ ์ปค๋ฎค๋ํฐ์ ๊ณต์ ํ๋ ๊ฒ์ ๋๋ค! Hugging Face๋ ์ธ๊ณต์ง๋ฅ์ ๋ฏผ์ฃผํ๋ฅผ ์ํด ๋ชจ๋์๊ฒ ์ง์๊ณผ ์์์ ๊ณต๊ฐ์ ์ผ๋ก ๊ณต์ ํด์ผ ํ๋ค๊ณ ๋ฏฟ์ต๋๋ค. ๋ค๋ฅธ ์ฌ๋๋ค์ด ์๊ฐ๊ณผ ์์์ ์ ์ฝํ ์ ์๋๋ก ์ปค๋ฎค๋ํฐ์ ๋ชจ๋ธ์ ๊ณต์ ํ๋ ๊ฒ์ ๊ณ ๋ คํด ๋ณด์ธ์. | |
์ด ํํ ๋ฆฌ์ผ์์ [Model Hub](https://huggingface.co/models)์์ ํ๋ จ๋๊ฑฐ๋ ๋ฏธ์ธ ์กฐ์ ๋ชจ๋ธ์ ๊ณต์ ํ๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ ๋ํด ์์๋ด ์๋ค: | |
- API๋ฅผ ํตํด ํ์ผ์ Hub์ ํธ์ํฉ๋๋ค. | |
- ์น์ฌ์ดํธ๋ฅผ ํตํด ํ์ผ์ Hub๋ก ๋์ด๋ค ๋์ต๋๋ค. | |
<iframe width="560" height="315" src="https://www.youtube.com/embed/XvSGPZFEjDY" title="YouTube video player" | |
frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; | |
picture-in-picture" allowfullscreen></iframe> | |
<Tip> | |
์ปค๋ฎค๋ํฐ์ ๋ชจ๋ธ์ ๊ณต์ ํ๋ ค๋ฉด, [huggingface.co](https://huggingface.co/join)์ ๊ณ์ ์ด ํ์ํฉ๋๋ค. ๊ธฐ์กด ์กฐ์ง์ ๊ฐ์ ํ๊ฑฐ๋ ์๋ก ๋ง๋ค ์๋ ์์ต๋๋ค. | |
</Tip> | |
## ์ ์ฅ์ ํน์ง[[repository-features]] | |
๋ชจ๋ธ ํ๋ธ์ ๊ฐ ์ ์ฅ์๋ ์ผ๋ฐ์ ์ธ GitHub ์ ์ฅ์์ฒ๋ผ ์๋ํฉ๋๋ค. ์ ์ฅ์๋ ๋ฒ์ ๊ด๋ฆฌ, ์ปค๋ฐ ๊ธฐ๋ก, ์ฐจ์ด์ ์๊ฐํ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค. | |
๋ชจ๋ธ ํ๋ธ์ ๋ด์ฅ๋ ๋ฒ์ ๊ด๋ฆฌ๋ git ๋ฐ [git-lfs](https://git-lfs.github.com/)๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํฉ๋๋ค. ์ฆ, ํ๋์ ๋ชจ๋ธ์ ํ๋์ ์ ์ฅ์๋ก ์ทจ๊ธํ์ฌ ์ ๊ทผ ์ ์ด ๋ฐ ํ์ฅ์ฑ์ด ํฅ์๋ฉ๋๋ค. ๋ฒ์ ์ ์ด๋ ์ปค๋ฐ ํด์, ํ๊ทธ ๋๋ ๋ธ๋์น๋ก ๋ชจ๋ธ์ ํน์ ๋ฒ์ ์ ๊ณ ์ ํ๋ ๋ฐฉ๋ฒ์ธ *revision*์ ํ์ฉํฉ๋๋ค. | |
๋ฐ๋ผ์ `revision` ๋งค๊ฐ๋ณ์๋ฅผ ์ฌ์ฉํ์ฌ ํน์ ๋ชจ๋ธ ๋ฒ์ ์ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค: | |
```py | |
>>> model = AutoModel.from_pretrained( | |
... "julien-c/EsperBERTo-small", revision="v2.0.1" # tag name, or branch name, or commit hash | |
... ) | |
``` | |
๋ํ ์ ์ฅ์์์ ํ์ผ์ ์ฝ๊ฒ ํธ์งํ ์ ์์ผ๋ฉฐ, ์ปค๋ฐ ๊ธฐ๋ก๊ณผ ์ฐจ์ด๋ฅผ ๋ณผ ์ ์์ต๋๋ค: | |
 | |
## ์ค์ [[setup]] | |
๋ชจ๋ธ์ ํ๋ธ์ ๊ณต์ ํ๊ธฐ ์ ์ Hugging Face ์๊ฒฉ ์ฆ๋ช ์ด ํ์ํฉ๋๋ค. ํฐ๋ฏธ๋์ ์ก์ธ์คํ ์ ์๋ ๊ฒฝ์ฐ, ๐ค Transformers๊ฐ ์ค์น๋ ๊ฐ์ ํ๊ฒฝ์์ ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค. ๊ทธ๋ฌ๋ฉด Hugging Face ์บ์ ํด๋(๊ธฐ๋ณธ์ ์ผ๋ก `~/.cache/`)์ ์ก์ธ์ค ํ ํฐ์ ์ ์ฅํฉ๋๋ค: | |
```bash | |
huggingface-cli login | |
``` | |
Jupyter ๋๋ Colaboratory์ ๊ฐ์ ๋ ธํธ๋ถ์ ์ฌ์ฉ ์ค์ธ ๊ฒฝ์ฐ, [`huggingface_hub`](https://huggingface.co/docs/hub/adding-a-library) ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ค์น๋์๋์ง ํ์ธํ์ธ์. ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฉด API๋ก ํ๋ธ์ ์ํธ ์์ฉํ ์ ์์ต๋๋ค. | |
```bash | |
pip install huggingface_hub | |
``` | |
๊ทธ๋ฐ ๋ค์ `notebook_login`๋ก ํ๋ธ์ ๋ก๊ทธ์ธํ๊ณ , [์ฌ๊ธฐ](https://huggingface.co/settings/token) ๋งํฌ์์ ๋ก๊ทธ์ธํ ํ ํฐ์ ์์ฑํฉ๋๋ค: | |
```py | |
>>> from huggingface_hub import notebook_login | |
>>> notebook_login() | |
``` | |
## ํ๋ ์์ํฌ ๊ฐ ๋ชจ๋ธ ๋ณํํ๊ธฐ[[convert-a-model-for-all-frameworks]] | |
๋ค๋ฅธ ํ๋ ์์ํฌ๋ก ์์ ํ๋ ์ฌ์ฉ์๊ฐ ๋ชจ๋ธ์ ์ฌ์ฉํ ์ ์๋๋ก ํ๋ ค๋ฉด, PyTorch ๋ฐ TensorFlow ์ฒดํฌํฌ์ธํธ๋ฅผ ๋ชจ๋ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ ๋ณํํ๊ณ ์ ๋ก๋ํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ์ด ๋จ๊ณ๋ฅผ ๊ฑด๋๋ฐ์ด๋ ์ฌ์ฉ์๋ ๋ค๋ฅธ ํ๋ ์์ํฌ์์ ๋ชจ๋ธ์ ๊ฐ์ ธ์ฌ ์ ์์ง๋ง, ๐ค Transformers๊ฐ ์ฒดํฌํฌ์ธํธ๋ฅผ ์ฆ์์์ ๋ณํํด์ผ ํ๋ฏ๋ก ์๋๊ฐ ๋๋ ค์ง ์ ์์ต๋๋ค. | |
์ฒดํฌํฌ์ธํธ๋ฅผ ๋ค๋ฅธ ํ๋ ์์ํฌ๋ก ๋ณํํ๋ ๊ฒ์ ์ฝ์ต๋๋ค. PyTorch ๋ฐ TensorFlow๊ฐ ์ค์น๋์ด ์๋์ง ํ์ธํ ๋ค์(์ค์น ์ง์นจ์ [์ฌ๊ธฐ](installation) ์ฐธ์กฐ) ๋ค๋ฅธ ํ๋ ์์ํฌ์์ ์์ ์ ๋ํ ํน์ ๋ชจ๋ธ์ ์ฐพ์ต๋๋ค. | |
<frameworkcontent> | |
<pt> | |
์ฒดํฌํฌ์ธํธ๋ฅผ TensorFlow์์ PyTorch๋ก ๋ณํํ๋ ค๋ฉด `from_tf=True`๋ฅผ ์ง์ ํ์ธ์: | |
```py | |
>>> pt_model = DistilBertForSequenceClassification.from_pretrained("path/to/awesome-name-you-picked", from_tf=True) | |
>>> pt_model.save_pretrained("path/to/awesome-name-you-picked") | |
``` | |
</pt> | |
<tf> | |
์ฒดํฌํฌ์ธํธ๋ฅผ PyTorch์์ TensorFlow๋ก ๋ณํํ๋ ค๋ฉด `from_pt=True`๋ฅผ ์ง์ ํ์ธ์: | |
```py | |
>>> tf_model = TFDistilBertForSequenceClassification.from_pretrained("path/to/awesome-name-you-picked", from_pt=True) | |
``` | |
๊ทธ๋ฐ ๋ค์ ์๋ก์ด ์ฒดํฌํฌ์ธํธ์ ํจ๊ป ์๋ก์ด TensorFlow ๋ชจ๋ธ์ ์ ์ฅํ ์ ์์ต๋๋ค: | |
```py | |
>>> tf_model.save_pretrained("path/to/awesome-name-you-picked") | |
``` | |
</tf> | |
<jax> | |
Flax์์ ๋ชจ๋ธ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ, PyTorch์์ Flax๋ก ์ฒดํฌํฌ์ธํธ๋ฅผ ๋ณํํ ์๋ ์์ต๋๋ค: | |
```py | |
>>> flax_model = FlaxDistilBertForSequenceClassification.from_pretrained( | |
... "path/to/awesome-name-you-picked", from_pt=True | |
... ) | |
``` | |
</jax> | |
</frameworkcontent> | |
## ํ๋ จ ์ค ๋ชจ๋ธ ํธ์ํ๊ธฐ[[push-a-model-during-training]] | |
<frameworkcontent> | |
<pt> | |
<Youtube id="Z1-XMy-GNLQ"/> | |
๋ชจ๋ธ์ ํ๋ธ์ ๊ณต์ ํ๋ ๊ฒ์ ์ถ๊ฐ ๋งค๊ฐ๋ณ์๋ ์ฝ๋ฐฑ์ ์ถ๊ฐํ๋ ๊ฒ๋งํผ ๊ฐ๋จํฉ๋๋ค. [๋ฏธ์ธ ์กฐ์ ํํ ๋ฆฌ์ผ](training)์์ [`TrainingArguments`] ํด๋์ค๋ ํ์ดํผํ๋ผ๋ฏธํฐ์ ์ถ๊ฐ ํ๋ จ ์ต์ ์ ์ง์ ํ๋ ๊ณณ์ด๋ผ๋ ๊ฒ์ ๊ธฐ์ตํ์ธ์. ์ด๋ฌํ ํ๋ จ ์ต์ ์ค ํ๋๋ ๋ชจ๋ธ์ ํ๋ธ๋ก ์ง์ ํธ์ํ๋ ๊ธฐ๋ฅ์ ํฌํจํฉ๋๋ค. [`TrainingArguments`]์์ `push_to_hub=True`๋ฅผ ์ค์ ํ์ธ์: | |
```py | |
>>> training_args = TrainingArguments(output_dir="my-awesome-model", push_to_hub=True) | |
``` | |
ํ์์ ๊ฐ์ด ํ๋ จ ์ธ์๋ฅผ [`Trainer`]์ ์ ๋ฌํฉ๋๋ค: | |
```py | |
>>> trainer = Trainer( | |
... model=model, | |
... args=training_args, | |
... train_dataset=small_train_dataset, | |
... eval_dataset=small_eval_dataset, | |
... compute_metrics=compute_metrics, | |
... ) | |
``` | |
๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ ํ, [`Trainer`]์์ [`~transformers.Trainer.push_to_hub`]๋ฅผ ํธ์ถํ์ฌ ํ๋ จ๋ ๋ชจ๋ธ์ ํ๋ธ๋ก ํธ์ํ์ธ์. ๐ค Transformers๋ ํ๋ จ ํ์ดํผํ๋ผ๋ฏธํฐ, ํ๋ จ ๊ฒฐ๊ณผ ๋ฐ ํ๋ ์์ํฌ ๋ฒ์ ์ ๋ชจ๋ธ ์นด๋์ ์๋์ผ๋ก ์ถ๊ฐํฉ๋๋ค! | |
```py | |
>>> trainer.push_to_hub() | |
``` | |
</pt> | |
<tf> | |
[`PushToHubCallback`]์ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ ํ๋ธ์ ๊ณต์ ํ๋ ค๋ฉด, [`PushToHubCallback`]์ ๋ค์ ์ธ์๋ฅผ ์ ์ํ์ธ์: | |
- ์ถ๋ ฅ๋ ๋ชจ๋ธ์ ํ์ผ ๊ฒฝ๋ก | |
- ํ ํฌ๋์ด์ | |
- `{Hub ์ฌ์ฉ์ ์ด๋ฆ}/{๋ชจ๋ธ ์ด๋ฆ}` ํ์์ `hub_model_id` | |
```py | |
>>> from transformers import PushToHubCallback | |
>>> push_to_hub_callback = PushToHubCallback( | |
... output_dir="./your_model_save_path", tokenizer=tokenizer, hub_model_id="your-username/my-awesome-model" | |
... ) | |
``` | |
[`fit`](https://keras.io/api/models/model_training_apis/)์ ์ฝ๋ฐฑ์ ์ถ๊ฐํ๋ฉด, ๐ค Transformers๊ฐ ํ๋ จ๋ ๋ชจ๋ธ์ ํ๋ธ๋ก ํธ์ํฉ๋๋ค: | |
```py | |
>>> model.fit(tf_train_dataset, validation_data=tf_validation_dataset, epochs=3, callbacks=push_to_hub_callback) | |
``` | |
</tf> | |
</frameworkcontent> | |
## `push_to_hub` ํจ์ ์ฌ์ฉํ๊ธฐ[[use-the-pushtohub-function]] | |
๋ชจ๋ธ์์ ์ง์ `push_to_hub`๋ฅผ ํธ์ถํ์ฌ ํ๋ธ์ ์ ๋ก๋ํ ์๋ ์์ต๋๋ค. | |
`push_to_hub`์ ๋ชจ๋ธ ์ด๋ฆ์ ์ง์ ํ์ธ์: | |
```py | |
>>> pt_model.push_to_hub("my-awesome-model") | |
``` | |
์ด๋ ๊ฒ ํ๋ฉด ์ฌ์ฉ์ ์ด๋ฆ ์๋์ ๋ชจ๋ธ ์ด๋ฆ `my-awesome-model`๋ก ์ ์ฅ์๊ฐ ์์ฑ๋ฉ๋๋ค. ์ด์ ์ฌ์ฉ์๋ `from_pretrained` ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค: | |
```py | |
>>> from transformers import AutoModel | |
>>> model = AutoModel.from_pretrained("your_username/my-awesome-model") | |
``` | |
์กฐ์ง์ ์ํ๊ณ ๋ชจ๋ธ์ ์กฐ์ง ์ด๋ฆ์ผ๋ก ๋์ ํธ์ํ๋ ค๋ฉด `repo_id`์ ์ถ๊ฐํ์ธ์: | |
```py | |
>>> pt_model.push_to_hub("my-awesome-org/my-awesome-model") | |
``` | |
`push_to_hub` ํจ์๋ ๋ชจ๋ธ ์ ์ฅ์์ ๋ค๋ฅธ ํ์ผ์ ์ถ๊ฐํ๋ ๋ฐ์๋ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ๋ชจ๋ธ ์ ์ฅ์์ ํ ํฌ๋์ด์ ๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค: | |
```py | |
>>> tokenizer.push_to_hub("my-awesome-model") | |
``` | |
๋๋ ๋ฏธ์ธ ์กฐ์ ๋ PyTorch ๋ชจ๋ธ์ TensorFlow ๋ฒ์ ์ ์ถ๊ฐํ ์๋ ์์ต๋๋ค: | |
```py | |
>>> tf_model.push_to_hub("my-awesome-model") | |
``` | |
์ด์ Hugging Face ํ๋กํ๋ก ์ด๋ํ๋ฉด, ์๋ก ์์ฑํ ๋ชจ๋ธ ์ ์ฅ์๊ฐ ํ์๋ฉ๋๋ค. **Files** ํญ์ ํด๋ฆญํ๋ฉด ์ ์ฅ์์ ์ ๋ก๋ํ ๋ชจ๋ ํ์ผ์ด ํ์๋ฉ๋๋ค. | |
์ ์ฅ์์ ํ์ผ์ ๋ง๋ค๊ณ ์ ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ ํ๋ธ ์ค๋ช ์ [์ฌ๊ธฐ](https://huggingface.co/docs/hub/how-to-upstream)๋ฅผ ์ฐธ์กฐํ์ธ์. | |
## ์น ์ธํฐํ์ด์ค๋ก ์ ๋ก๋ํ๊ธฐ[[upload-with-the-web-interface]] | |
์ฝ๋ ์๋ ์ ๊ทผ ๋ฐฉ์์ ์ ํธํ๋ ์ฌ์ฉ์๋ ํ๋ธ์ ์น ์ธํฐํ์ด์ค๋ฅผ ํตํด ๋ชจ๋ธ์ ์ ๋ก๋ํ ์ ์์ต๋๋ค. [huggingface.co/new](https://huggingface.co/new)๋ฅผ ๋ฐฉ๋ฌธํ์ฌ ์๋ก์ด ์ ์ฅ์๋ฅผ ์์ฑํ์ธ์: | |
 | |
์ฌ๊ธฐ์ ๋ชจ๋ธ์ ๋ํ ๋ช ๊ฐ์ง ์ ๋ณด๋ฅผ ์ถ๊ฐํ์ธ์: | |
- ์ ์ฅ์์ **์์ ์**๋ฅผ ์ ํํฉ๋๋ค. ์ด๋ ์ฌ์ฉ์ ๋๋ ์ฌ์ฉ์๊ฐ ์ํ ์กฐ์ง์ผ ์ ์์ต๋๋ค. | |
- ์ ์ฅ์ ์ด๋ฆ์ด ๋ ๋ชจ๋ธ์ ์ด๋ฆ์ ์ ํํฉ๋๋ค. | |
- ๋ชจ๋ธ์ด ๊ณต๊ฐ์ธ์ง ๋น๊ณต๊ฐ์ธ์ง ์ ํํฉ๋๋ค. | |
- ๋ชจ๋ธ์ ๋ผ์ด์ผ์ค ์ฌ์ฉ์ ์ง์ ํฉ๋๋ค. | |
์ด์ **Files** ํญ์ ํด๋ฆญํ๊ณ **Add file** ๋ฒํผ์ ํด๋ฆญํ์ฌ ์๋ก์ด ํ์ผ์ ์ ์ฅ์์ ์ ๋ก๋ํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ ์ ๋ก๋ํ ํ์ผ์ ๋์ด๋ค ๋๊ณ ์ปค๋ฐ ๋ฉ์์ง๋ฅผ ์ถ๊ฐํ์ธ์. | |
 | |
## ๋ชจ๋ธ ์นด๋ ์ถ๊ฐํ๊ธฐ[[add-a-model-card]] | |
์ฌ์ฉ์๊ฐ ๋ชจ๋ธ์ ๊ธฐ๋ฅ, ์ ํ, ์ ์ฌ์ ํธํฅ ๋ฐ ์ค๋ฆฌ์ ๊ณ ๋ ค ์ฌํญ์ ์ดํดํ ์ ์๋๋ก ์ ์ฅ์์ ๋ชจ๋ธ ์นด๋๋ฅผ ์ถ๊ฐํ์ธ์. ๋ชจ๋ธ ์นด๋๋ `README.md` ํ์ผ์ ์ ์๋์ด ์์ต๋๋ค. ๋ค์ ๋ฐฉ๋ฒ์ผ๋ก ๋ชจ๋ธ ์นด๋๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค: | |
* `README.md` ํ์ผ์ ์๋์ผ๋ก ์์ฑํ์ฌ ์ ๋ก๋ํฉ๋๋ค. | |
* ๋ชจ๋ธ ์ ์ฅ์์์ **Edit model card** ๋ฒํผ์ ํด๋ฆญํฉ๋๋ค. | |
๋ชจ๋ธ ์นด๋์ ํฌํจํ ์ ๋ณด ์ ํ์ ๋ํ ์ข์ ์๋ DistilBert [๋ชจ๋ธ ์นด๋](https://huggingface.co/distilbert-base-uncased)๋ฅผ ์ฐธ์กฐํ์ธ์. ๋ชจ๋ธ์ ํ์ ๋ฐ์๊ตญ์ด๋ ์์ ฏ ์์ ๋ฑ `README.md` ํ์ผ์์ ์ ์ดํ ์ ์๋ ๋ค๋ฅธ ์ต์ ์ ๋ํ ์์ธํ ๋ด์ฉ์ [์ฌ๊ธฐ](https://huggingface.co/docs/hub/models-cards) ๋ฌธ์๋ฅผ ์ฐธ์กฐํ์ธ์. | |