Title: Issue with Running Hugging Face Pipeline via SSH on Ubuntu in China
Content:
I am located in mainland China and have encountered an issue when running a script on my Ubuntu machine. Here is the script, named show.py
:
from transformers import pipeline
# Create zero-shot classifier
classifier = pipeline("zero-shot-classification")
# Perform classification
res = classifier(
"this is a course about python list comprehension",
candidate_labels=["education", "politics", "business"]
)
# Print classification results
print(res)
When I run python show.py
directly on my Ubuntu machine (which has Clash configured to resolve internet access issues in China, allowing access to Google and other external websites), it can successfully download libraries from Hugging Face and produce results.
However, if the script show.py
has not been run on the Ubuntu machine before, and I SSH into this Ubuntu machine to execute python show.py
, I encounter the following error:
OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like facebook/bart-large-mnli is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
Interestingly, if the script has been run on the Ubuntu machine before, and I SSH into the machine again to execute the script, it works fine and produces results.
Logically, the results from SSH execution should be the same as running it directly on the machine, given that both are being executed for the first time. Why does running it directly on the machine produce results while SSH execution fails?
中文版本
标题:在中国通过 SSH 在 Ubuntu 上运行 Hugging Face Pipeline 的问题
内容:
我位于中国大陆,在运行一个脚本时遇到了问题。以下是名为 show.py
的脚本:
from transformers import pipeline
# 创建零样本分类器
classifier = pipeline("zero-shot-classification")
# 进行分类
res = classifier(
"this is a course about python list comprehension",
candidate_labels=["education", "politics", "business"]
)
# 打印分类结果
print(res)
当我直接在配置了 Clash 的 Ubuntu 机子上运行 python show.py
(Clash 的配置是为了在中国解决访问谷歌等外网的问题),它可以成功从 Hugging Face 下载库并生成结果。
但是,如果 Ubuntu 机子上没有运行过 show.py
,而是通过 SSH 登录到这台 Ubuntu 机子上,执行 python show.py
时会出现以下错误:
OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like facebook/bart-large-mnli is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
有趣的是,如果该脚本已经在 Ubuntu 机子上运行过,然后我再次通过 SSH 登录并执行该脚本,则能够正常运行并生成结果。
按理说,SSH 的执行结果应该和直接在机器上运行相同,毕竟两者都是第一次执行。为什么直接在机器上运行能生成结果,而通过 SSH 执行却会失败呢?