code: def download(url, path, fname, redownload=False, num_retries=5):
      """
      Download file using `requests`.
  
      If ``redownload`` is set to false, then will not download tar file again if it is
      present (default ``False``).
      """
      outfile = os.path.join(path, fname)
      download = not PathManager.exists(outfile) or redownload
      logging.info(f"Downloading {url} to {outfile}")
      retry = num_retries
      exp_backoff = [2**r for r in reversed(range(retry))]
  
      pbar = tqdm.tqdm(
          unit="B", unit_scale=True, desc="Downloading {}".format(fname)
      )
  
      while download and retry > 0:
          response = None
  
          with get_http_session() as session:
              try:
                  response = session.get(url, stream=True, timeout=5)
  
                  # negative reply could be 'none' or just missing
                  CHUNK_SIZE = 32768
                  total_size = int(
                      response.headers.get("Content-Length", -1)
                  )
                  # server returns remaining size if resuming, so adjust total
                  pbar.total = total_size
                  done = 0
  
                  with PathManager.open(outfile, "wb") as f:
                      for chunk in response.iter_content(CHUNK_SIZE):
                          if chunk:  # filter out keep-alive new chunks
                              f.write(chunk)
                          if total_size > 0:
                              done += len(chunk)
                              if total_size < done:
                                  # don't freak out if content-length was too small
                                  total_size = done
                                  pbar.total = total_size
                              pbar.update(len(chunk))
                      break
              except (
                  requests.exceptions.ConnectionError,
                  requests.exceptions.ReadTimeout,
              ):
                  retry -= 1
                  pbar.clear()
                  if retry > 0:
                      pl = "y" if retry == 1 else "ies"
                      logging.debug(
                          f"Connection error, retrying. ({retry} retr{pl} left)"
                      )
                      time.sleep(exp_backoff[retry])
                  else:
                      logging.error(
                          "Retried too many times, stopped retrying."
                      )
              finally:
                  if response:
                      response.close()
      if retry <= 0:
          raise RuntimeError(
              "Connection broken too many times. Stopped retrying."
          )
  
      if download and retry > 0:
          pbar.update(done - pbar.n)
          if done < total_size:
              raise RuntimeError(
                  f"Received less data than specified in Content-Length header for "
                  f"{url}. There may be a download problem."
              )
  
      pbar.close()
  
imports: import importlib
  import json
  import time
  import datetime
  import os
  import requests
  import shutil
  import hashlib
  import tqdm
  import gzip
  import math
  import contextlib
  import parlai.utils.logging
  from parlai.utils.io import PathManager
label_desc: Use image node_id 3 for calling a global function with example usage: download(url, path, fname, redownload, num_retries) without return types