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. | |
--> | |
# ๋ฌธ์ ํด๊ฒฐ[[troubleshoot]] | |
๋๋๋ก ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ง๋ง, ์ ํฌ๊ฐ ๋์๋๋ฆฌ๊ฒ ์ต๋๋ค! ์ด ๊ฐ์ด๋๋ ํ์ฌ๊น์ง ํ์ธ๋ ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ๋ฌธ์ ๋ช ๊ฐ์ง์ ๊ทธ๊ฒ๋ค์ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ๋ํด ๋ค๋ฃน๋๋ค. ๊ทธ๋ฌ๋ ์ด ๊ฐ์ด๋๋ ๋ชจ๋ ๐ค Transformers ๋ฌธ์ ๋ฅผ ํฌ๊ด์ ์ผ๋ก ๋ค๋ฃจ๊ณ ์์ง ์์ต๋๋ค. ๋ฌธ์ ํด๊ฒฐ์ ๋ ๋ง์ ๋์์ ๋ฐ์ผ๋ ค๋ฉด ๋ค์์ ์๋ํด๋ณด์ธ์: | |
<Youtube id="S2EEG3JIt2A"/> | |
1. [ํฌ๋ผ](https://discuss.huggingface.co/)์์ ๋์์ ์์ฒญํ์ธ์. [Beginners](https://discuss.huggingface.co/c/beginners/5) ๋๋ [๐ค Transformers](https://discuss.huggingface.co/c/transformers/9)์ ๊ฐ์ ํน์ ์นดํ ๊ณ ๋ฆฌ์ ์ง๋ฌธ์ ๊ฒ์ํ ์ ์์ต๋๋ค. ์ฌํ ๊ฐ๋ฅํ ์ฝ๋์ ํจ๊ป ์ ์์ ๋ ํฌ๋ผ ๊ฒ์๋ฌผ์ ์์ฑํ์ฌ ์ฌ๋ฌ๋ถ์ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ ๊ฐ๋ฅ์ฑ์ ๊ทน๋ํํ์ธ์! | |
<Youtube id="_PAli-V4wj0"/> | |
2. ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๊ด๋ จ๋ ๋ฒ๊ทธ์ด๋ฉด ๐ค Transformers ์ ์ฅ์์์ [์ด์](https://github.com/huggingface/transformers/issues/new/choose)๋ฅผ ์์ฑํ์ธ์. ๋ฒ๊ทธ์ ๋ํด ์ค๋ช ํ๋ ์ ๋ณด๋ฅผ ๊ฐ๋ฅํ ๋ง์ด ํฌํจํ๋ ค๊ณ ๋ ธ๋ ฅํ์ฌ, ๋ฌด์์ด ์๋ชป ๋์๋์ง์ ์ด๋ป๊ฒ ์์ ํ ์ ์๋์ง ๋ ์ ํ์ ํ ์ ์๋๋ก ๋์์ฃผ์ธ์. | |
3. ์ด์ ๋ฒ์ ์ ๐ค Transformers์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ค์ํ ๋ณ๊ฒฝ ์ฌํญ์ด ๋ฒ์ ์ฌ์ด์ ๋์ ๋์๊ธฐ ๋๋ฌธ์ [๋ง์ด๊ทธ๋ ์ด์ ](migration) ๊ฐ์ด๋๋ฅผ ํ์ธํ์ธ์. | |
๋ฌธ์ ํด๊ฒฐ ๋ฐ ๋์ ๋งค๋ด์ผ์ ๋ํ ์์ธํ ๋ด์ฉ์ Hugging Face ๊ฐ์ข์ [8์ฅ](https://huggingface.co/course/chapter8/1?fw=pt)์ ์ฐธ์กฐํ์ธ์. | |
## ๋ฐฉํ๋ฒฝ ํ๊ฒฝ[[firewalled-environments]] | |
ํด๋ผ์ฐ๋ ๋ฐ ๋ด๋ถ๋ง(intranet) ์ค์ ์ ์ผ๋ถ GPU ์ธ์คํด์ค๋ ์ธ๋ถ ์ฐ๊ฒฐ์ ๋ํ ๋ฐฉํ๋ฒฝ์ผ๋ก ์ฐจ๋จ๋์ด ์ฐ๊ฒฐ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค. ์คํฌ๋ฆฝํธ๊ฐ ๋ชจ๋ธ ๊ฐ์ค์น๋ ๋ฐ์ดํฐ๋ฅผ ๋ค์ด๋ก๋ํ๋ ค๊ณ ํ ๋, ๋ค์ด๋ก๋๊ฐ ์ค๋จ๋๊ณ ๋ค์ ๋ฉ์์ง์ ํจ๊ป ์๊ฐ ์ด๊ณผ๋ฉ๋๋ค: | |
``` | |
ValueError: Connection error, and we cannot find the requested files in the cached path. | |
Please try again or make sure your Internet connection is on. | |
``` | |
์ด ๊ฒฝ์ฐ์๋ ์ฐ๊ฒฐ ์ค๋ฅ๋ฅผ ํผํ๊ธฐ ์ํด ๐ค Transformers๋ฅผ [์คํ๋ผ์ธ ๋ชจ๋](installation#offline-mode)๋ก ์คํํด์ผ ํฉ๋๋ค. | |
## CUDA ๋ฉ๋ชจ๋ฆฌ ๋ถ์กฑ(CUDA out of memory)[[cuda-out-of-memory]] | |
์๋ฐฑ๋ง ๊ฐ์ ๋งค๊ฐ๋ณ์๋ก ๋๊ท๋ชจ ๋ชจ๋ธ์ ํ๋ จํ๋ ๊ฒ์ ์ ์ ํ ํ๋์จ์ด ์์ด ์ด๋ ค์ธ ์ ์์ต๋๋ค. GPU ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋ถ์กฑํ ๊ฒฝ์ฐ ๋ฐ์ํ ์ ์๋ ์ผ๋ฐ์ ์ธ ์ค๋ฅ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
``` | |
CUDA out of memory. Tried to allocate 256.00 MiB (GPU 0; 11.17 GiB total capacity; 9.70 GiB already allocated; 179.81 MiB free; 9.85 GiB reserved in total by PyTorch) | |
``` | |
๋ค์์ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ์ ์ค์ด๊ธฐ ์ํด ์๋ํด ๋ณผ ์ ์๋ ๋ช ๊ฐ์ง ์ ์ฌ์ ์ธ ํด๊ฒฐ์ฑ ์ ๋๋ค: | |
- [`TrainingArguments`]์ [`per_device_train_batch_size`](main_classes/trainer#transformers.TrainingArguments.per_device_train_batch_size) ๊ฐ์ ์ค์ด์ธ์. | |
- [`TrainingArguments`]์ [`gradient_accumulation_steps`](main_classes/trainer#transformers.TrainingArguments.gradient_accumulation_steps)์ ์ ์ฒด ๋ฐฐ์น ํฌ๊ธฐ๋ฅผ ํจ๊ณผ์ ์ผ๋ก ๋๋ฆฌ์ธ์. | |
<Tip> | |
๋ฉ๋ชจ๋ฆฌ ์ ์ฝ ๊ธฐ์ ์ ๋ํ ์์ธํ ๋ด์ฉ์ ์ฑ๋ฅ [๊ฐ์ด๋](performance)๋ฅผ ์ฐธ์กฐํ์ธ์. | |
</Tip> | |
## ์ ์ฅ๋ TensorFlow ๋ชจ๋ธ์ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค(Unable to load a saved TensorFlow model)[[unable-to-load-a-saved-uensorFlow-model]] | |
TensorFlow์ [model.save](https://www.tensorflow.org/tutorials/keras/save_and_load#save_the_entire_model) ๋ฉ์๋๋ ์ํคํ ์ฒ, ๊ฐ์ค์น, ํ๋ จ ๊ตฌ์ฑ ๋ฑ ์ ์ฒด ๋ชจ๋ธ์ ๋จ์ผ ํ์ผ์ ์ ์ฅํฉ๋๋ค. ๊ทธ๋ฌ๋ ๋ชจ๋ธ ํ์ผ์ ๋ค์ ๊ฐ์ ธ์ฌ ๋ ๐ค Transformers๋ ๋ชจ๋ธ ํ์ผ์ ์๋ ๋ชจ๋ TensorFlow ๊ด๋ จ ๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์ค์ง ์์ ์ ์๊ธฐ ๋๋ฌธ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค. TensorFlow ๋ชจ๋ธ ์ ์ฅ ๋ฐ ๊ฐ์ ธ์ค๊ธฐ ๋ฌธ์ ๋ฅผ ํผํ๋ ค๋ฉด ๋ค์์ ๊ถ์ฅํฉ๋๋ค: | |
- ๋ชจ๋ธ ๊ฐ์ค์น๋ฅผ `h5` ํ์ผ ํ์ฅ์๋ก [`model.save_weights`](https://www.tensorflow.org/tutorials/keras/save_and_load#save_the_entire_model)๋ก ์ ์ฅํ ๋ค์ [`~TFPreTrainedModel.from_pretrained`]๋ก ๋ชจ๋ธ์ ๋ค์ ๊ฐ์ ธ์ต๋๋ค: | |
```py | |
>>> from transformers import TFPreTrainedModel | |
>>> from tensorflow import keras | |
>>> model.save_weights("some_folder/tf_model.h5") | |
>>> model = TFPreTrainedModel.from_pretrained("some_folder") | |
``` | |
- ๋ชจ๋ธ์ [`~TFPretrainedModel.save_pretrained`]๋ก ์ ์ฅํ๊ณ [`~TFPreTrainedModel.from_pretrained`]๋ก ๋ค์ ๊ฐ์ ธ์ต๋๋ค: | |
```py | |
>>> from transformers import TFPreTrainedModel | |
>>> model.save_pretrained("path_to/model") | |
>>> model = TFPreTrainedModel.from_pretrained("path_to/model") | |
``` | |
## ImportError[[importerror]] | |
ํนํ ์ต์ ๋ชจ๋ธ์ธ ๊ฒฝ์ฐ ๋ง๋ ์ ์๋ ๋ค๋ฅธ ์ผ๋ฐ์ ์ธ ์ค๋ฅ๋ `ImportError`์ ๋๋ค: | |
``` | |
ImportError: cannot import name 'ImageGPTImageProcessor' from 'transformers' (unknown location) | |
``` | |
์ด๋ฌํ ์ค๋ฅ ์ ํ์ ๊ฒฝ์ฐ ์ต์ ๋ชจ๋ธ์ ์ก์ธ์คํ ์ ์๋๋ก ์ต์ ๋ฒ์ ์ ๐ค Transformers๊ฐ ์ค์น๋์ด ์๋์ง ํ์ธํ์ธ์: | |
```bash | |
pip install transformers --upgrade | |
``` | |
## CUDA error: device-side assert triggered[[cuda-error-deviceside-assert-triggered]] | |
๋๋๋ก ์ฅ์น ์ฝ๋ ์ค๋ฅ์ ๋ํ ์ผ๋ฐ์ ์ธ CUDA ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค. | |
``` | |
RuntimeError: CUDA error: device-side assert triggered | |
``` | |
๋ ์์ธํ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์ป์ผ๋ ค๋ฉด ์ฐ์ ์ฝ๋๋ฅผ CPU์์ ์คํํฉ๋๋ค. ๋ค์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ฝ๋์ ์์ ๋ถ๋ถ์ ์ถ๊ฐํ์ฌ CPU๋ก ์ ํํ์ธ์: | |
```py | |
>>> import os | |
>>> os.environ["CUDA_VISIBLE_DEVICES"] = "" | |
``` | |
๋ ๋ค๋ฅธ ์ต์ ์ GPU์์ ๋ ๋์ ์ญ์ถ์ (traceback)์ ์ป๋ ๊ฒ์ ๋๋ค. ๋ค์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ฝ๋์ ์์ ๋ถ๋ถ์ ์ถ๊ฐํ์ฌ ์ญ์ถ์ ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ ์์ค๋ฅผ ๊ฐ๋ฆฌํค๋๋ก ํ์ธ์: | |
```py | |
>>> import os | |
>>> os.environ["CUDA_LAUNCH_BLOCKING"] = "1" | |
``` | |
## ํจ๋ฉ ํ ํฐ์ด ๋ง์คํน๋์ง ์์ ๊ฒฝ์ฐ ์๋ชป๋ ์ถ๋ ฅ(Incorrect output when padding tokens aren't masked)[[incorrect-output-when-padding-tokens-arent-masked]] | |
๊ฒฝ์ฐ์ ๋ฐ๋ผ `input_ids`์ ํจ๋ฉ ํ ํฐ์ด ํฌํจ๋ ๊ฒฝ์ฐ `hidden_state` ์ถ๋ ฅ์ด ์ฌ๋ฐ๋ฅด์ง ์์ ์ ์์ต๋๋ค. ๋ฐ๋ชจ๋ฅผ ์ํด ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ฅผ ๊ฐ์ ธ์ค์ธ์. ๋ชจ๋ธ์ `pad_token_id`์ ์ก์ธ์คํ์ฌ ํด๋น ๊ฐ์ ํ์ธํ ์ ์์ต๋๋ค. ์ผ๋ถ ๋ชจ๋ธ์ ๊ฒฝ์ฐ `pad_token_id`๊ฐ `None`์ผ ์ ์์ง๋ง ์ธ์ ๋ ์ง ์๋์ผ๋ก ์ค์ ํ ์ ์์ต๋๋ค. | |
```py | |
>>> from transformers import AutoModelForSequenceClassification | |
>>> import torch | |
>>> model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased") | |
>>> model.config.pad_token_id | |
0 | |
``` | |
๋ค์ ์์ ๋ ํจ๋ฉ ํ ํฐ์ ๋ง์คํนํ์ง ์์ ์ถ๋ ฅ์ ๋ณด์ฌ์ค๋๋ค: | |
```py | |
>>> input_ids = torch.tensor([[7592, 2057, 2097, 2393, 9611, 2115], [7592, 0, 0, 0, 0, 0]]) | |
>>> output = model(input_ids) | |
>>> print(output.logits) | |
tensor([[ 0.0082, -0.2307], | |
[ 0.1317, -0.1683]], grad_fn=<AddmmBackward0>) | |
``` | |
๋ค์์ ๋ ๋ฒ์งธ ์ํ์ค์ ์ค์ ์ถ๋ ฅ์ ๋๋ค: | |
```py | |
>>> input_ids = torch.tensor([[7592]]) | |
>>> output = model(input_ids) | |
>>> print(output.logits) | |
tensor([[-0.1008, -0.4061]], grad_fn=<AddmmBackward0>) | |
``` | |
๋๋ถ๋ถ์ ๊ฒฝ์ฐ ๋ชจ๋ธ์ `attention_mask`๋ฅผ ์ ๊ณตํ์ฌ ํจ๋ฉ ํ ํฐ์ ๋ฌด์ํด์ผ ์ด๋ฌํ ์กฐ์ฉํ ์ค๋ฅ๋ฅผ ๋ฐฉ์งํ ์ ์์ต๋๋ค. ์ด์ ๋ ๋ฒ์งธ ์ํ์ค์ ์ถ๋ ฅ์ด ์ค์ ์ถ๋ ฅ๊ณผ ์ผ์นํฉ๋๋ค: | |
<Tip> | |
์ผ๋ฐ์ ์ผ๋ก ํ ํฌ๋์ด์ ๋ ํน์ ํ ํฌ๋์ด์ ์ ๊ธฐ๋ณธ ๊ฐ์ ๊ธฐ์ค์ผ๋ก ์ฌ์ฉ์์ ๋ํ 'attention_mask'๋ฅผ ๋ง๋ญ๋๋ค. | |
</Tip> | |
```py | |
>>> attention_mask = torch.tensor([[1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0]]) | |
>>> output = model(input_ids, attention_mask=attention_mask) | |
>>> print(output.logits) | |
tensor([[ 0.0082, -0.2307], | |
[-0.1008, -0.4061]], grad_fn=<AddmmBackward0>) | |
``` | |
๐ค Transformers๋ ํจ๋ฉ ํ ํฐ์ด ์ ๊ณต๋ ๊ฒฝ์ฐ ํจ๋ฉ ํ ํฐ์ ๋ง์คํนํ๊ธฐ ์ํ `attention_mask`๋ฅผ ์๋์ผ๋ก ์์ฑํ์ง ์์ต๋๋ค. ๊ทธ ์ด์ ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
- ์ผ๋ถ ๋ชจ๋ธ์๋ ํจ๋ฉ ํ ํฐ์ด ์์ต๋๋ค. | |
- ์ผ๋ถ ์ฌ์ฉ ์ฌ๋ก์ ๊ฒฝ์ฐ ์ฌ์ฉ์๊ฐ ๋ชจ๋ธ์ด ํจ๋ฉ ํ ํฐ์ ๊ด๋ฆฌํ๊ธฐ๋ฅผ ์ํฉ๋๋ค. | |
## ValueError: ์ด ์ ํ์ AutoModel์ ๋ํด ์ธ์ํ ์ ์๋ XYZ ๊ตฌ์ฑ ํด๋์ค(ValueError: Unrecognized configuration class XYZ for this kind of AutoModel)[[valueerror-unrecognized-configuration-class-xyz-for-this-kind-of-automodel]] | |
์ผ๋ฐ์ ์ผ๋ก, ์ฌ์ ํ์ต๋ ๋ชจ๋ธ์ ์ธ์คํด์ค๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด [`AutoModel`] ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ต๋๋ค. | |
์ด ํด๋์ค๋ ๊ตฌ์ฑ์ ๋ฐ๋ผ ์ฃผ์ด์ง ์ฒดํฌํฌ์ธํธ์์ ์ฌ๋ฐ๋ฅธ ์ํคํ ์ฒ๋ฅผ ์๋์ผ๋ก ์ถ๋ก ํ๊ณ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค. | |
๋ชจ๋ธ์ ์ฒดํฌํฌ์ธํธ์์ ๊ฐ์ ธ์ฌ ๋ ์ด `ValueError`๊ฐ ๋ฐ์ํ๋ฉด, ์ด๋ Auto ํด๋์ค๊ฐ ์ฃผ์ด์ง ์ฒดํฌํฌ์ธํธ์ ๊ตฌ์ฑ์์ | |
๊ฐ์ ธ์ค๋ ค๋ ๋ชจ๋ธ ์ ํ๊ณผ ๋งคํ์ ์ฐพ์ ์ ์๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค. ๊ฐ์ฅ ํํ๊ฒ ๋ฐ์ํ๋ ๊ฒฝ์ฐ๋ | |
์ฒดํฌํฌ์ธํธ๊ฐ ์ฃผ์ด์ง ํ์คํฌ๋ฅผ ์ง์ํ์ง ์์ ๋์ ๋๋ค. | |
์๋ฅผ ๋ค์ด, ๋ค์ ์์ ์์ ์ง์์๋ต์ ๋ํ GPT2๊ฐ ์๊ธฐ ๋๋ฌธ์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค: | |
```py | |
>>> from transformers import AutoProcessor, AutoModelForQuestionAnswering | |
>>> processor = AutoProcessor.from_pretrained("gpt2-medium") | |
>>> model = AutoModelForQuestionAnswering.from_pretrained("gpt2-medium") | |
ValueError: Unrecognized configuration class <class 'transformers.models.gpt2.configuration_gpt2.GPT2Config'> for this kind of AutoModel: AutoModelForQuestionAnswering. | |
Model type should be one of AlbertConfig, BartConfig, BertConfig, BigBirdConfig, BigBirdPegasusConfig, BloomConfig, ... | |
``` | |