I am getting error in downloading the pytorch

Sayed_Rizwan: <h2><a name="downloading-httpsdownloadpytorchorgmodelsalexnet-owt-7be5be79pth-to-rootcachetorchhubcheckpointsalexnet-owt-7be5be79pth-1" class="anchor" href="#downloading-httpsdownloadpytorchorgmodelsalexnet-owt-7be5be79pth-to-rootcachetorchhubcheckpointsalexnet-owt-7be5be79pth-1"></a>Downloading: “<a href="https://download.pytorch.org/models/alexnet-owt-7be5be79.pth" rel="noopener nofollow ugc">https://download.pytorch.org/models/alexnet-owt-7be5be79.pth</a>” to /root/.cache/torch/hub/checkpoints/alexnet-owt-7be5be79.pth</h2>
<p>gaierror                                  Traceback (most recent call last)<br>
File /opt/conda/lib/python3.10/urllib/request.py:1348, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)<br>
1347 try:<br>
 → 1348     h.request(req.get_method(), req.selector, req.data, headers,<br>
1349               encode_chunked=req.has_header(‘Transfer-encoding’))<br>
1350 except OSError as err: # timeout error</p>
<p>File /opt/conda/lib/python3.10/http/client.py:1283, in HTTPConnection.request(self, method, url, body, headers, encode_chunked)<br>
1282 “”“Send a complete request to the server.”“”<br>
 → 1283 self._send_request(method, url, body, headers, encode_chunked)</p>
<p>File /opt/conda/lib/python3.10/http/client.py:1329, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)<br>
1328     body = _encode(body, ‘body’)<br>
 → 1329 self.endheaders(body, encode_chunked=encode_chunked)</p>
<p>File /opt/conda/lib/python3.10/http/client.py:1278, in HTTPConnection.endheaders(self, message_body, encode_chunked)<br>
1277     raise CannotSendHeader()<br>
 → 1278 self._send_output(message_body, encode_chunked=encode_chunked)</p>
<p>File /opt/conda/lib/python3.10/http/client.py:1038, in HTTPConnection._send_output(self, message_body, encode_chunked)<br>
1037 del self._buffer[:]<br>
 → 1038 self.send(msg)<br>
1040 if message_body is not None:<br>
1041<br>
1042     # create a consistent interface to message_body</p>
<p>File /opt/conda/lib/python3.10/http/client.py:976, in HTTPConnection.send(self, data)<br>
975 if self.auto_open:<br>
 → 976     self.connect()<br>
977 else:</p>
<p>File /opt/conda/lib/python3.10/http/client.py:1448, in HTTPSConnection.connect(self)<br>
1446 “Connect to a host on a given (SSL) port.”<br>
 → 1448 super().connect()<br>
1450 if self._tunnel_host:</p>
<p>File /opt/conda/lib/python3.10/http/client.py:942, in HTTPConnection.connect(self)<br>
941 sys.audit(“http.client.connect”, self, self.host, self.port)<br>
 → 942 self.sock = self._create_connection(<br>
943     (self.host,self.port), self.timeout, self.source_address)<br>
944 # Might fail in OSs that don’t implement TCP_NODELAY</p>
<p>File /opt/conda/lib/python3.10/socket.py:824, in create_connection(address, timeout, source_address)<br>
823 err = None<br>
 → 824 for res in getaddrinfo(host, port, 0, SOCK_STREAM):<br>
825     af, socktype, proto, canonname, sa = res</p>
<p>File /opt/conda/lib/python3.10/socket.py:955, in getaddrinfo(host, port, family, type, proto, flags)<br>
954 addrlist = <span class="chcklst-box fa fa-square-o fa-fw"></span><br>
 → 955 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):<br>
956     af, socktype, proto, canonname, sa = res</p>
<p>gaierror: [Errno -3] Temporary failure in name resolution</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>URLError                                  Traceback (most recent call last)<br>
Cell In[21], line 2<br>
1 # Initialize the model, criterion, and optimizer<br>
----&gt; 2 model = AlexNet(num_classes=2)<br>
3 criterion = nn.CrossEntropyLoss()<br>
4 optimizer = torch.optim.Adam(model.parameters(), lr=0.001)</p>
<p>Cell In[13], line 5, in AlexNet.<strong>init</strong>(self, num_classes)<br>
3 def <strong>init</strong>(self, num_classes=2):<br>
4     super(AlexNet, self).<strong>init</strong>()<br>
----&gt; 5     self.features = models.alexnet(pretrained=True).features<br>
6     self.classifier = nn.Sequential(<br>
7         nn.Dropout(),<br>
8         nn.Linear(256 * 6 * 6, 4096),<br>
(…)<br>
13         nn.Linear(4096, num_classes),<br>
14     )</p>
<p>File /opt/conda/lib/python3.10/site-packages/torchvision/models/_utils.py:142, in kwonly_to_pos_or_kw..wrapper(*args, **kwargs)<br>
135     warnings.warn(<br>
136         f"Using {sequence_to_str(tuple(keyword_only_kwargs.keys()), separate_last='and ')} as positional "<br>
137         f"parameter(s) is deprecated since 0.13 and may be removed in the future. Please use keyword parameter(s) "<br>
138         f"instead."<br>
139     )<br>
140     kwargs.update(keyword_only_kwargs)<br>
 → 142 return fn(*args, **kwargs)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torchvision/models/_utils.py:228, in handle_legacy_interface..outer_wrapper..inner_wrapper(*args, **kwargs)<br>
225     del kwargs[pretrained_param]<br>
226     kwargs[weights_param] = default_weights_arg<br>
 → 228 return builder(*args, **kwargs)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torchvision/models/alexnet.py:117, in alexnet(weights, progress, **kwargs)<br>
114 model = AlexNet(**kwargs)<br>
116 if weights is not None:<br>
 → 117     model.load_state_dict(weights.get_state_dict(progress=progress, check_hash=True))<br>
119 return model</p>
<p>File /opt/conda/lib/python3.10/site-packages/torchvision/models/_api.py:90, in WeightsEnum.get_state_dict(self, *args, **kwargs)<br>
89 def get_state_dict(self, *args: Any, **kwargs: Any) → Mapping[str, Any]:<br>
—&gt; 90     return load_state_dict_from_url(self.url, *args, **kwargs)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/hub.py:766, in load_state_dict_from_url(url, model_dir, map_location, progress, check_hash, file_name, weights_only)<br>
764         r = HASH_REGEX.search(filename)  # r is Optional[Match[str]]<br>
765         hash_prefix = r.group(1) if r else None<br>
 → 766     download_url_to_file(url, cached_file, hash_prefix, progress=progress)<br>
768 if _is_legacy_zip_format(cached_file):<br>
769     return _legacy_zip_load(cached_file, model_dir, map_location, weights_only)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/hub.py:620, in download_url_to_file(url, dst, hash_prefix, progress)<br>
618 file_size = None<br>
619 req = Request(url, headers={“User-Agent”: “torch.hub”})<br>
 → 620 u = urlopen(req)<br>
621 meta = u.info()<br>
622 if hasattr(meta, ‘getheaders’):</p>
<p>File /opt/conda/lib/python3.10/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)<br>
214 else:<br>
215     opener = _opener<br>
 → 216 return opener.open(url, data, timeout)</p>
<p>File /opt/conda/lib/python3.10/urllib/request.py:519, in OpenerDirector.open(self, fullurl, data, timeout)<br>
516     req = meth(req)<br>
518 sys.audit(‘urllib.Request’, req.full_url, req.data, req.headers, req.get_method())<br>
 → 519 response = self._open(req, data)<br>
521 # post-process response<br>
522 meth_name = protocol+“_response”</p>
<p>File /opt/conda/lib/python3.10/urllib/request.py:536, in OpenerDirector._open(self, req, data)<br>
533     return result<br>
535 protocol = req.type<br>
 → 536 result = self._call_chain(self.handle_open, protocol, protocol +<br>
537                           ‘_open’, req)<br>
538 if result:<br>
539     return result</p>
<p>File /opt/conda/lib/python3.10/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)<br>
494 for handler in handlers:<br>
495     func = getattr(handler, meth_name)<br>
 → 496     result = func(*args)<br>
497     if result is not None:<br>
498         return result</p>
<p>File /opt/conda/lib/python3.10/urllib/request.py:1391, in HTTPSHandler.https_open(self, req)<br>
1390 def https_open(self, req):<br>
 → 1391     return self.do_open(http.client.HTTPSConnection, req,<br>
1392         context=self._context, check_hostname=self._check_hostname)</p>
<p>File /opt/conda/lib/python3.10/urllib/request.py:1351, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)<br>
1348         h.request(req.get_method(), req.selector, req.data, headers,<br>
1349                   encode_chunked=req.has_header(‘Transfer-encoding’))<br>
1350     except OSError as err: # timeout error<br>
 → 1351         raise URLError(err)<br>
1352     r = h.getresponse()<br>
1353 except:</p>
<p>URLError: &lt;urlopen error [Errno -3] Temporary failure in name resolution&gt;</p>

ptrblck: <p>I cannot reproduce the issue using <code>model = models.alexnet(pretrained=True)</code> so it might have been a temporary issue.</p>