Initialize the DeepSpeed Engine. Arguments: args: an object containing local_rank and deepspeed_config fields. This is optional if `config` is passed. model: Required: nn.module class before apply any wrappers optimizer: Optional: a user defined Optimizer o
(args=None,
model: torch.nn.Module = None,
optimizer: Optional[Union[Optimizer, DeepSpeedOptimizerCallable]] = None,
model_parameters: Optional[torch.nn.Module] = None,
training_data: Optional[torch.utils.data.Dataset] = None,
lr_scheduler: Optional[Union[_LRScheduler, DeepSpeedSchedulerCallable]] = None,
mpu=None,
dist_init_required: Optional[bool] = None,
collate_fn=None,
config=None,
config_params=None)
| 56 | |
| 57 | |
| 58 | def initialize(args=None, |
| 59 | model: torch.nn.Module = None, |
| 60 | optimizer: Optional[Union[Optimizer, DeepSpeedOptimizerCallable]] = None, |
| 61 | model_parameters: Optional[torch.nn.Module] = None, |
| 62 | training_data: Optional[torch.utils.data.Dataset] = None, |
| 63 | lr_scheduler: Optional[Union[_LRScheduler, DeepSpeedSchedulerCallable]] = None, |
| 64 | mpu=None, |
| 65 | dist_init_required: Optional[bool] = None, |
| 66 | collate_fn=None, |
| 67 | config=None, |
| 68 | config_params=None): |
| 69 | """Initialize the DeepSpeed Engine. |
| 70 | |
| 71 | Arguments: |
| 72 | args: an object containing local_rank and deepspeed_config fields. |
| 73 | This is optional if `config` is passed. |
| 74 | |
| 75 | model: Required: nn.module class before apply any wrappers |
| 76 | |
| 77 | optimizer: Optional: a user defined Optimizer or Callable that returns an Optimizer object. |
| 78 | This overrides any optimizer definition in the DeepSpeed json config. |
| 79 | |
| 80 | model_parameters: Optional: An iterable of torch.Tensors or dicts. |
| 81 | Specifies what Tensors should be optimized. |
| 82 | |
| 83 | training_data: Optional: Dataset of type torch.utils.data.Dataset |
| 84 | |
| 85 | lr_scheduler: Optional: Learning Rate Scheduler Object or a Callable that takes an Optimizer and returns a Scheduler object. |
| 86 | The scheduler object should define a get_lr(), step(), state_dict(), and load_state_dict() methods |
| 87 | |
| 88 | mpu: Optional: A model parallelism unit object that implements |
| 89 | get_{model,data}_parallel_{rank,group,world_size}() |
| 90 | |
| 91 | dist_init_required: Optional: None will auto-initialize torch distributed if needed, |
| 92 | otherwise the user can force it to be initialized or not via boolean. |
| 93 | |
| 94 | collate_fn: Optional: Merges a list of samples to form a |
| 95 | mini-batch of Tensor(s). Used when using batched loading from a |
| 96 | map-style dataset. |
| 97 | |
| 98 | config: Optional: Instead of requiring args.deepspeed_config you can pass your deepspeed config |
| 99 | as an argument instead, as a path or a dictionary. |
| 100 | |
| 101 | config_params: Optional: Same as `config`, kept for backwards compatibility. |
| 102 | |
| 103 | Returns: |
| 104 | A tuple of ``engine``, ``optimizer``, ``training_dataloader``, ``lr_scheduler`` |
| 105 | |
| 106 | * ``engine``: DeepSpeed runtime engine which wraps the client model for distributed training. |
| 107 | |
| 108 | * ``optimizer``: Wrapped optimizer if a user defined ``optimizer`` is supplied, or if |
| 109 | optimizer is specified in json config else ``None``. |
| 110 | |
| 111 | * ``training_dataloader``: DeepSpeed dataloader if ``training_data`` was supplied, |
| 112 | otherwise ``None``. |
| 113 | |
| 114 | * ``lr_scheduler``: Wrapped lr scheduler if user ``lr_scheduler`` is passed, or |
| 115 | if ``lr_scheduler`` specified in JSON configuration. Otherwise ``None``. |
nothing calls this directly
no test coverage detected