code: def get_hf_args_with_overwrites(
      args: List[str], hparams: Dict[str, Any]
  ) -> List[str]:
      """Updates the submitted HF CLI Args to account for overwrite values.
  
      Primarily intended as a helper function for Determined AI DeepSpeed (DS) Autotune which provides
      overwrite values through the `hparams["overwrite_deepspeed_args"]` which possibly include DS
      batch-size related arguments (`train_batch_size`, `train_micro_batch_size_per_gpu`, and
      `gradient_accumulation_steps`) which are in conflict with the corresponding HF CLI batch-size
      related arguments(`--per_device_train_batch_size` and `--gradient_accumulation_steps`). This
      function updates the HF CLI args to relect any such overwrite values. This process also requires
      overwriting the corresponding DS json file on-cluster.
  
      Args:
          args: the original HF CLI arguments
          hparams: hyperparameter dictionary generated through Determined AI
  
      Returns:
          args: updated HF CLI arguments
      """
      if _defaults.OVERWRITE_KEY not in hparams:
          logger.info(
              f"{_defaults.OVERWRITE_KEY} key not found in hparams, `get_hf_args_with_overwrites` "
              "is a no-op"
          )
          return args
  
      ds_config_path = get_hf_ds_config_path_from_args(args)
      assert (
          ds_config_path is not None
      ), "--deepspeed flag not found in HuggingFace args!"
  
      # A file lock is required during both the writing and reading.
      with filelock.FileLock(ds_config_path + ".lock"):
          with open(ds_config_path, "r") as f:
              ds_config_dict = json.load(f)
  
          # Then merge all overwrites into the ds_config
          overwritten_ds_config_dict = merge_dicts(
              ds_config_dict, hparams[_defaults.OVERWRITE_KEY]
          )
  
          # We need to actually overwrite the ds json config file, due to how HF processes args.
          with open(ds_config_path, "w") as f:
              json.dump(overwritten_ds_config_dict, f)
          # Finally overwrite the CLI args
          args = update_hf_args(args, overwritten_ds_config_dict)
  
      return args
  
imports: import argparse
  import copy
  import json
  import logging
  import pathlib
  import random
  from contextlib import contextmanager
  from typing import Any, Dict, Generator, List, Optional, Union
  import filelock
  import torch
  import determined
  from determined.common import util
  from determined.pytorch.dsat import _defaults
  from determined.util import merge_dicts
label_desc: Use image node_id 15 for calling a global function with example usage: get_hf_args_with_overwrites(args, hparams) and returns: args, args