Value error : Connection error

Hello,
I am new in this forum and Hugging face models. Could someone help with this:
I want to use model ‘Helsinki-NLP/opus-mt-en-sla’. I am using code from the site:

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained(“Helsinki-NLP/opus-mt-en-sla”)

model = AutoModelForSeq2SeqLM.from_pretrained(“Helsinki-NLP/opus-mt-en-sla”)

but I get this error: 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.

I have installed all necessary libraries and my internet connection is good…could someone help with this?
Thanks

Hello @Katarina, I was able to run your code snippet without any problems on my machine, so I wonder whether there is some firewall / proxy you need to configure on your end?

A simple test that your connection is fine would be to spin up a Google Colab notebook and see if your code works there. Alternatively, you could try upgrading to the latest version of transformers just to be sure it’s not an old bug that got fixed recently.

Hi Lewis, thank you on answer. I checked on Google Colab and there is working fine.
I am traying from Watson Studio, so probably then I have some blockades. Do you maybe know how is possible to incorporate that part - defining a proxy into this code?

1 Like

Hmm I am not familiar with Watson Studio so perhaps you need to do some special login to establish a connection?

If you’re running on a Linux machine, you can edit the no_proxy environment variable in the same shell that you’re running your code from, e.g. bash - Set a network range in the no_proxy environment variable - Unix & Linux Stack Exchange

However, my guess is that you might have more luck getting in touch with the IBM support to help you solve the problem :slight_smile:

Ok, I will try first with no proxy ev…thank you very much! Many regards…:slight_smile:

1 Like

Hi, I just have update on this topic…I found a solution. See code below:
import os

#proxy = ‘http://:@:’
proxy = “https://x.x.xx.x:xxxx”

os.environ[‘http_proxy’] = proxy
os.environ[‘HTTP_PROXY’] = proxy
os.environ[‘https_proxy’] = proxy
os.environ[‘HTTPS_PROXY’] = proxy

3 Likes

I have a related question. I have an environment that doesn’t have internet. I downloaded the model inside of a docker container and moved the docker imaged into the no-internet environment.
It’s still giving me the Connection Error even if I pointed to the cached_dir. Is there anyway to stop the code from requiring a internet connection and just use the cached_dir?

        model_name = f'Helsinki-NLP/opus-mt-mul-en'
        # Download the model and the tokenizer
        cache_dir = "/root/.cache/huggingface/transformers"
        model = MarianMTModel.from_pretrained(model_name, cache_dir=cache_dir)
        tokenizer = MarianTokenizer.from_pretrained(model_name, cache_dir=cache_dir)

hey @yangliu2 what happens if you set the TRANSFORMERS_OFFLINE=1 as an environment variable in your docker container?

see more info here

@lewtun What you suggested seems to work. Although this has to be set before
from transformers import MarianMTModel, MarianTokenizer if I want to use os package to set environmental variables.
Other than it doesn’t follow PEP8, models seem to be loading okay.

1 Like