code: def download(
      name: str | None = None,
      version: str | None = None,
      bundle_dir: PathLike | None = None,
      source: str = DEFAULT_DOWNLOAD_SOURCE,
      repo: str | None = None,
      url: str | None = None,
      remove_prefix: str | None = "monai_",
      progress: bool = True,
      args_file: str | None = None,
  ) -> None:
      """
      download bundle from the specified source or url. The bundle should be a zip file and it
      will be extracted after downloading.
      This function refers to:
      https://pytorch.org/docs/stable/_modules/torch/hub.html
  
      Typical usage examples:
  
      .. code-block:: bash
  
          # Execute this module as a CLI entry, and download bundle from the model-zoo repo:
          python -m monai.bundle download --name <bundle_name> --version "0.1.0" --bundle_dir "./"
  
          # Execute this module as a CLI entry, and download bundle from specified github repo:
          python -m monai.bundle download --name <bundle_name> --source "github" --repo "repo_owner/repo_name/release_tag"
  
          # Execute this module as a CLI entry, and download bundle from ngc with latest version:
          python -m monai.bundle download --name <bundle_name> --source "ngc" --bundle_dir "./"
  
          # Execute this module as a CLI entry, and download bundle from monaihosting with latest version:
          python -m monai.bundle download --name <bundle_name> --source "monaihosting" --bundle_dir "./"
  
          # Execute this module as a CLI entry, and download bundle from Hugging Face Hub:
          python -m monai.bundle download --name "bundle_name" --source "huggingface_hub" --repo "repo_owner/repo_name"
  
          # Execute this module as a CLI entry, and download bundle via URL:
          python -m monai.bundle download --name <bundle_name> --url <url>
  
          # Set default args of `run` in a JSON / YAML file, help to record and simplify the command line.
          # Other args still can override the default args at runtime.
          # The content of the JSON / YAML file is a dictionary. For example:
          # {"name": "spleen", "bundle_dir": "download", "source": ""}
          # then do the following command for downloading:
          python -m monai.bundle download --args_file "args.json" --source "github"
  
      Args:
          name: bundle name. If `None` and `url` is `None`, it must be provided in `args_file`.
              for example:
              "spleen_ct_segmentation", "prostate_mri_anatomy" in model-zoo:
              https://github.com/Project-MONAI/model-zoo/releases/tag/hosting_storage_v1.
              "monai_brats_mri_segmentation" in ngc:
              https://catalog.ngc.nvidia.com/models?filters=&orderBy=scoreDESC&query=monai.
          version: version name of the target bundle to download, like: "0.1.0". If `None`, will download
              the latest version (or the last commit to the `main` branch in the case of Hugging Face Hub).
          bundle_dir: target directory to store the downloaded data.
              Default is `bundle` subfolder under `torch.hub.get_dir()`.
          source: storage location name. This argument is used when `url` is `None`.
              In default, the value is achieved from the environment variable BUNDLE_DOWNLOAD_SRC, and
              it should be "ngc", "monaihosting", "github", or "huggingface_hub".
          repo: repo name. This argument is used when `url` is `None` and `source` is "github" or "huggingface_hub".
              If `source` is "github", it should be in the form of "repo_owner/repo_name/release_tag".
              If `source` is "huggingface_hub", it should be in the form of "repo_owner/repo_name".
          url: url to download the data. If not `None`, data will be downloaded directly
              and `source` will not be checked.
              If `name` is `None`, filename is determined by `monai.apps.utils._basename(url)`.
          remove_prefix: This argument is used when `source` is "ngc". Currently, all ngc bundles
              have the ``monai_`` prefix, which is not existing in their model zoo contrasts. In order to
              maintain the consistency between these two sources, remove prefix is necessary.
              Therefore, if specified, downloaded folder name will remove the prefix.
          progress: whether to display a progress bar.
          args_file: a JSON or YAML file to provide default values for all the args in this function.
              so that the command line inputs can be simplified.
  
      """
      _args = update_kwargs(
          args=args_file,
          name=name,
          version=version,
          bundle_dir=bundle_dir,
          source=source,
          repo=repo,
          url=url,
          remove_prefix=remove_prefix,
          progress=progress,
      )
  
      _log_input_summary(tag="download", args=_args)
      (
          source_,
          progress_,
          remove_prefix_,
          repo_,
          name_,
          version_,
          bundle_dir_,
          url_,
      ) = _pop_args(
          _args,
          "source",
          "progress",
          remove_prefix=None,
          repo=None,
          name=None,
          version=None,
          bundle_dir=None,
          url=None,
      )
  
      bundle_dir_ = _process_bundle_dir(bundle_dir_)
      if repo_ is None:
          repo_ = "Project-MONAI/model-zoo/hosting_storage_v1"
      if len(repo_.split("/")) != 3 and source_ != "huggingface_hub":
          raise ValueError(
              "repo should be in the form of `repo_owner/repo_name/release_tag`."
          )
      elif len(repo_.split("/")) != 2 and source_ == "huggingface_hub":
          raise ValueError(
              "Hugging Face Hub repo should be in the form of `repo_owner/repo_name`"
          )
      if url_ is not None:
          if name_ is not None:
              filepath = bundle_dir_ / f"{name_}.zip"
          else:
              filepath = bundle_dir_ / f"{_basename(url_)}"
          download_url(
              url=url_,
              filepath=filepath,
              hash_val=None,
              progress=progress_,
          )
          extractall(
              filepath=filepath, output_dir=bundle_dir_, has_base=True
          )
      else:
          if name_ is None:
              raise ValueError(
                  f"To download from source: {source_}, `name` must be provided."
              )
          if version_ is None:
              version_ = _get_latest_bundle_version(
                  source=source_, name=name_, repo=repo_
              )
          if source_ == "github":
              if version_ is not None:
                  name_ = "_v".join([name_, version_])
              _download_from_github(
                  repo=repo_,
                  download_path=bundle_dir_,
                  filename=name_,
                  progress=progress_,
              )
          elif source_ == "monaihosting":
              _download_from_monaihosting(
                  download_path=bundle_dir_,
                  filename=name_,
                  version=version_,
                  progress=progress_,
              )
          elif source_ == "ngc":
              _download_from_ngc(
                  download_path=bundle_dir_,
                  filename=name_,
                  version=version_,
                  remove_prefix=remove_prefix_,
                  progress=progress_,
              )
          elif source_ == "huggingface_hub":
              extract_path = os.path.join(bundle_dir_, name_)
              huggingface_hub.snapshot_download(
                  repo_id=repo_,
                  revision=version_,
                  local_dir=extract_path,
              )
          else:
              raise NotImplementedError(
                  "Currently only download from `url`, source 'github', 'monaihosting', 'huggingface_hub' or 'ngc' are implemented,"
                  f"got source: {source_}."
              )
  
imports: from __future__ import annotations
  import ast
  import json
  import os
  import re
  import warnings
  from collections.abc import Mapping, Sequence
  from pathlib import Path
  from pydoc import locate
  from shutil import copyfile
  from textwrap import dedent
  from typing import Any, Callable
  import torch
  from torch.cuda import is_available
  from monai.apps.mmars.mmars import _get_all_ngc_models
  from monai.apps.utils import _basename, download_url, extractall, get_logger
  from monai.bundle.config_item import ConfigComponent
  from monai.bundle.config_parser import ConfigParser
  from monai.bundle.utils import DEFAULT_INFERENCE, DEFAULT_METADATA
  from monai.bundle.workflows import BundleWorkflow, ConfigWorkflow
  from monai.config import IgniteInfo, PathLike
  from monai.data import load_net_with_metadata, save_net_with_metadata
  from monai.networks import convert_to_onnx, convert_to_torchscript, convert_to_trt, copy_model_state, get_state_dict, save_state
  from monai.utils import check_parent_dir, deprecated_arg, ensure_tuple, get_equivalent_dtype, min_version, optional_import, pprint_edges
label_desc: Use image node_id 17 for calling a global function with example usage: download(name, version, bundle_dir, source, repo, url, remove_prefix, progress, args_file) without return types