torch.hub.load() raises HTTPError: HTTP Error 404: Not Found when loading model

2.2k Views Asked by At

I had this simple piece of code found on the fairseq GitHub repository which basically loads the bart.base PyTorch model from torch.hub:

bart = torch.hub.load('pytorch/fairseq', 'bart.base')

This code was working perfectly around two weeks ago, now it raises the following error despite the fact that I didn't change anything:

HTTPError                                 Traceback (most recent call last)
<ipython-input-7-68181b5f094c> in <module>()
      1 # torch.cuda.empty_cache()
----> 2 bart = torch.hub.load('pytorch/fairseq', 'bart.base') #takes around two minutes
      3 # bart.cuda()  # use GPU
...
...
/usr/lib/python3.7/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    647 class HTTPDefaultErrorHandler(BaseHandler):
    648     def http_error_default(self, req, fp, code, msg, hdrs):
--> 649         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    650 
    651 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 404: Not Found

Also, I found out that this happens with other models on fairseq. All the following models raise the same error:

>>> torch.hub.load('pytorch/fairseq', 'transformer.wmt16.en-de')
# ERROR!

>>> torch.hub.load('pytorch/fairseq', 'camembert')
# ERROR!

So, there must be something in common among all of them.

1

There are 1 best solutions below

0
On BEST ANSWER

Apparently, the fairseq folks decided to change the default branch of their GitHub repository from master to main exactly 7 days ago. (check this commit).

So, adding the main branch to the repo info will fix the problem:

bart = torch.hub.load('pytorch/fairseq:main', 'bart.base') #<--- added :main

And that's because in torch.hub.load() function the default branch name is master. So actually, you were calling pytorch/fairseq:master which doesn't exist anymore.

And all other models are working now:

torch.hub.load('pytorch/fairseq:main', 'transformer.wmt16.en-de')
# WORKS!

>>> torch.hub.load('pytorch/fairseq:main', 'camembert')
# WORKS!