I am getting error in downloading the pytorch

Downloading: “https://download.pytorch.org/models/alexnet-owt-7be5be79.pth” to /root/.cache/torch/hub/checkpoints/alexnet-owt-7be5be79.pth

gaierror Traceback (most recent call last)
File /opt/conda/lib/python3.10/urllib/request.py:1348, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
1347 try:
→ 1348 h.request(req.get_method(), req.selector, req.data, headers,
1349 encode_chunked=req.has_header(‘Transfer-encoding’))
1350 except OSError as err: # timeout error

File /opt/conda/lib/python3.10/http/client.py:1283, in HTTPConnection.request(self, method, url, body, headers, encode_chunked)
1282 “”“Send a complete request to the server.”“”
→ 1283 self._send_request(method, url, body, headers, encode_chunked)

File /opt/conda/lib/python3.10/http/client.py:1329, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)
1328 body = _encode(body, ‘body’)
→ 1329 self.endheaders(body, encode_chunked=encode_chunked)

File /opt/conda/lib/python3.10/http/client.py:1278, in HTTPConnection.endheaders(self, message_body, encode_chunked)
1277 raise CannotSendHeader()
→ 1278 self._send_output(message_body, encode_chunked=encode_chunked)

File /opt/conda/lib/python3.10/http/client.py:1038, in HTTPConnection._send_output(self, message_body, encode_chunked)
1037 del self._buffer[:]
→ 1038 self.send(msg)
1040 if message_body is not None:
1041
1042 # create a consistent interface to message_body

File /opt/conda/lib/python3.10/http/client.py:976, in HTTPConnection.send(self, data)
975 if self.auto_open:
→ 976 self.connect()
977 else:

File /opt/conda/lib/python3.10/http/client.py:1448, in HTTPSConnection.connect(self)
1446 “Connect to a host on a given (SSL) port.”
→ 1448 super().connect()
1450 if self._tunnel_host:

File /opt/conda/lib/python3.10/http/client.py:942, in HTTPConnection.connect(self)
941 sys.audit(“http.client.connect”, self, self.host, self.port)
→ 942 self.sock = self._create_connection(
943 (self.host,self.port), self.timeout, self.source_address)
944 # Might fail in OSs that don’t implement TCP_NODELAY

File /opt/conda/lib/python3.10/socket.py:824, in create_connection(address, timeout, source_address)
823 err = None
→ 824 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
825 af, socktype, proto, canonname, sa = res

File /opt/conda/lib/python3.10/socket.py:955, in getaddrinfo(host, port, family, type, proto, flags)
954 addrlist =
→ 955 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
956 af, socktype, proto, canonname, sa = res

gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

URLError Traceback (most recent call last)
Cell In[21], line 2
1 # Initialize the model, criterion, and optimizer
----> 2 model = AlexNet(num_classes=2)
3 criterion = nn.CrossEntropyLoss()
4 optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

Cell In[13], line 5, in AlexNet.init(self, num_classes)
3 def init(self, num_classes=2):
4 super(AlexNet, self).init()
----> 5 self.features = models.alexnet(pretrained=True).features
6 self.classifier = nn.Sequential(
7 nn.Dropout(),
8 nn.Linear(256 * 6 * 6, 4096),
(…)
13 nn.Linear(4096, num_classes),
14 )

File /opt/conda/lib/python3.10/site-packages/torchvision/models/_utils.py:142, in kwonly_to_pos_or_kw..wrapper(*args, **kwargs)
135 warnings.warn(
136 f"Using {sequence_to_str(tuple(keyword_only_kwargs.keys()), separate_last='and ')} as positional "
137 f"parameter(s) is deprecated since 0.13 and may be removed in the future. Please use keyword parameter(s) "
138 f"instead."
139 )
140 kwargs.update(keyword_only_kwargs)
→ 142 return fn(*args, **kwargs)

File /opt/conda/lib/python3.10/site-packages/torchvision/models/_utils.py:228, in handle_legacy_interface..outer_wrapper..inner_wrapper(*args, **kwargs)
225 del kwargs[pretrained_param]
226 kwargs[weights_param] = default_weights_arg
→ 228 return builder(*args, **kwargs)

File /opt/conda/lib/python3.10/site-packages/torchvision/models/alexnet.py:117, in alexnet(weights, progress, **kwargs)
114 model = AlexNet(**kwargs)
116 if weights is not None:
→ 117 model.load_state_dict(weights.get_state_dict(progress=progress, check_hash=True))
119 return model

File /opt/conda/lib/python3.10/site-packages/torchvision/models/_api.py:90, in WeightsEnum.get_state_dict(self, *args, **kwargs)
89 def get_state_dict(self, *args: Any, **kwargs: Any) → Mapping[str, Any]:
—> 90 return load_state_dict_from_url(self.url, *args, **kwargs)

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)
764 r = HASH_REGEX.search(filename) # r is Optional[Match[str]]
765 hash_prefix = r.group(1) if r else None
→ 766 download_url_to_file(url, cached_file, hash_prefix, progress=progress)
768 if _is_legacy_zip_format(cached_file):
769 return _legacy_zip_load(cached_file, model_dir, map_location, weights_only)

File /opt/conda/lib/python3.10/site-packages/torch/hub.py:620, in download_url_to_file(url, dst, hash_prefix, progress)
618 file_size = None
619 req = Request(url, headers={“User-Agent”: “torch.hub”})
→ 620 u = urlopen(req)
621 meta = u.info()
622 if hasattr(meta, ‘getheaders’):

File /opt/conda/lib/python3.10/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
214 else:
215 opener = _opener
→ 216 return opener.open(url, data, timeout)

File /opt/conda/lib/python3.10/urllib/request.py:519, in OpenerDirector.open(self, fullurl, data, timeout)
516 req = meth(req)
518 sys.audit(‘urllib.Request’, req.full_url, req.data, req.headers, req.get_method())
→ 519 response = self._open(req, data)
521 # post-process response
522 meth_name = protocol+“_response”

File /opt/conda/lib/python3.10/urllib/request.py:536, in OpenerDirector._open(self, req, data)
533 return result
535 protocol = req.type
→ 536 result = self._call_chain(self.handle_open, protocol, protocol +
537 ‘_open’, req)
538 if result:
539 return result

File /opt/conda/lib/python3.10/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
494 for handler in handlers:
495 func = getattr(handler, meth_name)
→ 496 result = func(*args)
497 if result is not None:
498 return result

File /opt/conda/lib/python3.10/urllib/request.py:1391, in HTTPSHandler.https_open(self, req)
1390 def https_open(self, req):
→ 1391 return self.do_open(http.client.HTTPSConnection, req,
1392 context=self._context, check_hostname=self._check_hostname)

File /opt/conda/lib/python3.10/urllib/request.py:1351, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
1348 h.request(req.get_method(), req.selector, req.data, headers,
1349 encode_chunked=req.has_header(‘Transfer-encoding’))
1350 except OSError as err: # timeout error
→ 1351 raise URLError(err)
1352 r = h.getresponse()
1353 except:

URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

I cannot reproduce the issue using model = models.alexnet(pretrained=True) so it might have been a temporary issue.