今天刚开始学习huggingface,跑示例的时候出了不少错,在此记录一下:
(gpu) F:\transformer\transformers\examples\pytorch\image-classification>.\run.bat
Traceback (most recent call last):File "F:\transformer\transformers\examples\pytorch\image-classification\run_image_classification.py", line 451, in <module>main()File "F:\transformer\transformers\examples\pytorch\image-classification\run_image_classification.py", line 197, in mainmodel_args, data_args, training_args = parser.parse_args_into_dataclasses()File "F:\anaconda\envs\gpu\lib\site-packages\transformers-4.38.0.dev0-py3.9.egg\transformers\hf_argparser.py", line 338, in parse_args_into_dataclassesobj = dtype(**inputs)File "<string>", line 123, in __init__File "F:\anaconda\envs\gpu\lib\site-packages\transformers-4.38.0.dev0-py3.9.egg\transformers\training_args.py", line 1820, in __post_init__self.hub_model_id = get_full_repo_name(File "F:\anaconda\envs\gpu\lib\site-packages\huggingface_hub\utils\_validators.py", line 118, in _inner_fnreturn fn(*args, **kwargs)File "F:\anaconda\envs\gpu\lib\site-packages\huggingface_hub\hf_api.py", line 4888, in get_full_repo_nameusername = self.whoami(token=token)["name"] # type: ignoreFile "F:\anaconda\envs\gpu\lib\site-packages\huggingface_hub\utils\_validators.py", line 118, in _inner_fnreturn fn(*args, **kwargs)File "F:\anaconda\envs\gpu\lib\site-packages\huggingface_hub\hf_api.py", line 1140, in whoamiheaders=self._build_hf_headers(File "F:\anaconda\envs\gpu\lib\site-packages\huggingface_hub\hf_api.py", line 6943, in _build_hf_headersreturn build_hf_headers(File "F:\anaconda\envs\gpu\lib\site-packages\huggingface_hub\utils\_validators.py", line 118, in _inner_fnreturn fn(*args, **kwargs)File "F:\anaconda\envs\gpu\lib\site-packages\huggingface_hub\utils\_headers.py", line 121, in build_hf_headerstoken_to_send = get_token_to_send(token)File "F:\anaconda\envs\gpu\lib\site-packages\huggingface_hub\utils\_headers.py", line 153, in get_token_to_sendraise LocalTokenNotFoundError(
huggingface_hub.utils._headers.LocalTokenNotFoundError: Token is required (`token=True`), but no token found. You need to provide a token or be logged in to Hugging Face with `huggingface-cli login` or `huggingface_hub.login`. See https://huggingface.co/settings/tokens.
根据报错信息可以看到是没有提供token,token就是在huggingface官网上每个账号的标识,根据token可以追溯到账号。
如何提供token呢?首先我们要去huggingface官网注册一个账号(如果打不开网页需要使用VPN),然后来到设置这里,点击Access Tokens
注意,在设置token的时候,如果你想执行上传model之类的操作,需要新建一个write类型的token,不然可以使用read类型。
然后复制,到命令行输入下面的指令:
python -c "from huggingface_hub.hf_api import HfFolder; HfFolder.save_token('YOUR_TOKEN_HERE')"
如果你使用的是笔记本:
from huggingface_hub import notebook_login
notebook_login()
然后接着输入token就好了。
问题解决!