flair PermissionError: [Errno 13] Permission denied: '/root/.cache'
flair PermissionError: [Errno 13] Permission denied: '/root/.cache'
我正在调用带有 flair
程序包的 python 脚本和 www-data
用户(无 sudo
权限)。这些模型位于该用户具有访问权限的路径中,我已将其设置为 flair.cache_root = Path("tools/flair")
但是,当我 运行 与该用户的脚本时,我收到权限错误:
tagger = MultiTagger.load([\\"flair/ner-german-large\\", \\"de-pos\\"])\
File \\"/usr/local/lib/python3.7/dist-packages/flair/models/sequence_tagger_model.py\\", line 1330, in load\
model = SequenceTagger.load(model_name)\
File \\"/usr/local/lib/python3.7/dist-packages/flair/nn.py\\", line 88, in load\
state = torch.load(f, map_location='cpu')\
File \\"/usr/local/lib/python3.7/dist-packages/torch/serialization.py\\", line 594, in load\
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)\
File \\"/usr/local/lib/python3.7/dist-packages/torch/serialization.py\\", line 853, in _load\
result = unpickler.load()\
File \\"/usr/local/lib/python3.7/dist-packages/flair/embeddings/token.py\\", line 1297, in __setstate__\
state_dict=d[\\"model_state_dict\\"],\
File \\"/usr/local/lib/python3.7/dist-packages/flair/embeddings/token.py\\", line 818, in __init__\
self.tokenizer: PreTrainedTokenizer = AutoTokenizer.from_pretrained(model, **kwargs)\
File \\"/usr/local/lib/python3.7/dist-packages/transformers/models/auto/tokenization_auto.py\\", line 435, in from_pretrained\
return tokenizer_class_fast.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)\
File \\"/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py\\", line 1680, in from_pretrained\
user_agent=user_agent,\
File \\"/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py\\", line 1279, in cached_path\
local_files_only=local_files_only,\
File \\"/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py\\", line 1426, in get_from_cache\
os.makedirs(cache_dir, exist_ok=True)\
File \\"/usr/lib/python3.7/os.py\\", line 211, in makedirs\
makedirs(head, exist_ok=exist_ok)\
File \\"/usr/lib/python3.7/os.py\\", line 211, in makedirs\
makedirs(head, exist_ok=exist_ok)\
File \\"/usr/lib/python3.7/os.py\\", line 221, in makedirs\
mkdir(name, mode)\
PermissionError: [Errno 13] Permission denied: '/root/.cache'\
我可以避免使用 /root/.cache
吗?我不想编辑那个目录的读写权限。如果我 运行 脚本作为 root
它工作正常。我如何 运行 它作为其他用户?我 运行 在 Ubuntu 上发布它。
错误是由flair
加载的变压器模型引起的。必须通过设置环境变量 TRANSFORMERS_CACHE=/path/to/transformers
额外指定转换器的缓存目录
我正在调用带有 flair
程序包的 python 脚本和 www-data
用户(无 sudo
权限)。这些模型位于该用户具有访问权限的路径中,我已将其设置为 flair.cache_root = Path("tools/flair")
但是,当我 运行 与该用户的脚本时,我收到权限错误:
tagger = MultiTagger.load([\\"flair/ner-german-large\\", \\"de-pos\\"])\
File \\"/usr/local/lib/python3.7/dist-packages/flair/models/sequence_tagger_model.py\\", line 1330, in load\
model = SequenceTagger.load(model_name)\
File \\"/usr/local/lib/python3.7/dist-packages/flair/nn.py\\", line 88, in load\
state = torch.load(f, map_location='cpu')\
File \\"/usr/local/lib/python3.7/dist-packages/torch/serialization.py\\", line 594, in load\
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)\
File \\"/usr/local/lib/python3.7/dist-packages/torch/serialization.py\\", line 853, in _load\
result = unpickler.load()\
File \\"/usr/local/lib/python3.7/dist-packages/flair/embeddings/token.py\\", line 1297, in __setstate__\
state_dict=d[\\"model_state_dict\\"],\
File \\"/usr/local/lib/python3.7/dist-packages/flair/embeddings/token.py\\", line 818, in __init__\
self.tokenizer: PreTrainedTokenizer = AutoTokenizer.from_pretrained(model, **kwargs)\
File \\"/usr/local/lib/python3.7/dist-packages/transformers/models/auto/tokenization_auto.py\\", line 435, in from_pretrained\
return tokenizer_class_fast.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)\
File \\"/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py\\", line 1680, in from_pretrained\
user_agent=user_agent,\
File \\"/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py\\", line 1279, in cached_path\
local_files_only=local_files_only,\
File \\"/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py\\", line 1426, in get_from_cache\
os.makedirs(cache_dir, exist_ok=True)\
File \\"/usr/lib/python3.7/os.py\\", line 211, in makedirs\
makedirs(head, exist_ok=exist_ok)\
File \\"/usr/lib/python3.7/os.py\\", line 211, in makedirs\
makedirs(head, exist_ok=exist_ok)\
File \\"/usr/lib/python3.7/os.py\\", line 221, in makedirs\
mkdir(name, mode)\
PermissionError: [Errno 13] Permission denied: '/root/.cache'\
我可以避免使用 /root/.cache
吗?我不想编辑那个目录的读写权限。如果我 运行 脚本作为 root
它工作正常。我如何 运行 它作为其他用户?我 运行 在 Ubuntu 上发布它。
错误是由flair
加载的变压器模型引起的。必须通过设置环境变量 TRANSFORMERS_CACHE=/path/to/transformers