code: def deepspeed_optim_sched(
      trainer,
      hf_deepspeed_config,
      args,
      num_training_steps,
      model_parameters,
  ):
      """
      A convenience wrapper that deals with optimizer and lr scheduler configuration.
      """
      from accelerate.utils import DummyOptim, DummyScheduler
  
      config = hf_deepspeed_config.config
  
      # Mixing and matching DS schedulers and optimizers is supported unless Offload is enabled in which case it's:
      # 1. DS scheduler + DS optimizer: Yes
      # 2. HF scheduler + HF optimizer: Mostly*
      # 3. DS scheduler + HF optimizer: Mostly*
      # 4. HF scheduler + DS optimizer: Yes
      #
      # Mostly*: All non-native DeepSpeed optimizers that have both CPU and GPU implementation should work (except LAMB)
  
      optimizer = None
      if "optimizer" in config:
          if args.adafactor:
              raise ValueError(
                  "--adafactor was passed, but also found `optimizer` configured in the DeepSpeed config. "
                  "Only one optimizer can be configured."
              )
          optimizer = DummyOptim(params=model_parameters)
      else:
          if hf_deepspeed_config.is_offload():
              logger.info(
                  "Detected ZeRO Offload and non-DeepSpeed optimizers: This combination should work as long as the"
                  " custom optimizer has both CPU and GPU implementation (except LAMB)"
              )
  
          # ds supports Adam, OneBitAdam, and Lamb optimizers and can import other optimizers from torch.
          # But trainer uses AdamW by default.
          optimizer = trainer.create_optimizer()
          # To use other optimizers requires voiding warranty with: `zero_allow_untested_optimizer`
          config["zero_allow_untested_optimizer"] = True
  
      lr_scheduler = None
      if "scheduler" in config:
          lr_scheduler = DummyScheduler(optimizer)
      else:
          if isinstance(optimizer, DummyOptim):
  
              def _lr_scheduler_callable(optimizer):
                  return get_scheduler(
                      trainer.args.lr_scheduler_type,
                      optimizer=optimizer,
                      num_warmup_steps=trainer.args.get_warmup_steps(
                          num_training_steps
                      ),
                      num_training_steps=num_training_steps,
                  )
  
              lr_scheduler = DummyScheduler(
                  optimizer,
                  lr_scheduler_callable=_lr_scheduler_callable,
              )
          else:
              lr_scheduler = trainer.create_scheduler(
                  num_training_steps=num_training_steps,
                  optimizer=optimizer,
              )
  
      return optimizer, lr_scheduler
  
imports: import importlib.metadata
  import importlib.util
  import weakref
  from functools import partialmethod
  from ..dependency_versions_check import dep_version_check
  from ..utils import is_accelerate_available, is_torch_available, logging
label_desc: Use image node_id 6 for calling a global function with example usage: deepspeed_optim_sched(trainer, hf_deepspeed_config, args, num_training_steps, model_parameters) and returns: optimizer,  lr_scheduler, get_scheduler