MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / initialize

Function initialize

deepspeed/__init__.py:433–610  ·  view source on GitHub ↗

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: Any = 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,
    distributed_port: int = TORCH_DISTRIBUTED_DEFAULT_PORT,
    mpu: Any = None,
    dist_init_required: Optional[bool] = None,
    collate_fn: Optional[Callable] = None,
    config: Optional[Union[str, Dict[str, Any]]] = None,
    mesh_param: Any = None,
    config_params: Optional[Union[str, Dict[str, Any]]] = None
)

Source from the content-addressed store, hash-verified

431
432
433def initialize(
434 args: Any = None,
435 model: torch.nn.Module = None,
436 optimizer: Optional[Union[Optimizer, DeepSpeedOptimizerCallable]] = None,
437 model_parameters: Optional[torch.nn.Module] = None,
438 training_data: Optional[torch.utils.data.Dataset] = None,
439 lr_scheduler: Optional[Union[_LRScheduler, DeepSpeedSchedulerCallable]] = None,
440 distributed_port: int = TORCH_DISTRIBUTED_DEFAULT_PORT,
441 mpu: Any = None,
442 dist_init_required: Optional[bool] = None,
443 collate_fn: Optional[Callable] = None,
444 config: Optional[Union[str, Dict[str, Any]]] = None,
445 mesh_param: Any = None,
446 config_params: Optional[Union[str, Dict[str, Any]]] = None
447) -> Tuple[DeepSpeedEngine, Optional[Union[Optimizer, DeepSpeedOptimizer]], Optional[DeepSpeedDataLoader], Any]:
448 """Initialize the DeepSpeed Engine.
449
450 Arguments:
451 args: an object containing local_rank and deepspeed_config fields.
452 This is optional if `config` is passed.
453
454 model: Required: nn.module class before apply any wrappers
455
456 optimizer: Optional: a user defined Optimizer or Callable that returns an Optimizer object.
457 This overrides any optimizer definition in the DeepSpeed json config.
458
459 model_parameters: Optional: An iterable of torch.Tensors or dicts.
460 Specifies what Tensors should be optimized.
461
462 training_data: Optional: Dataset of type torch.utils.data.Dataset
463
464 lr_scheduler: Optional: Learning Rate Scheduler Object or a Callable that takes an Optimizer and returns a Scheduler object.
465 The scheduler object should define a get_lr(), step(), state_dict(), and load_state_dict() methods
466
467 distributed_port: Optional: Master node (rank 0)'s free port that needs to be used for communication during distributed training
468
469 mpu: Optional: A model parallelism unit object that implements
470 get_{model,data}_parallel_{rank,group,world_size}()
471
472 dist_init_required: Optional: None will auto-initialize torch distributed if needed,
473 otherwise the user can force it to be initialized or not via boolean.
474
475 collate_fn: Optional: Merges a list of samples to form a
476 mini-batch of Tensor(s). Used when using batched loading from a
477 map-style dataset.
478
479 config: Optional: Instead of requiring args.deepspeed_config you can pass your deepspeed config
480 as an argument instead, as a path or a dictionary.
481
482 config_params: Optional: Same as `config`, kept for backwards compatibility.
483
484 Returns:
485 A tuple of ``engine``, ``optimizer``, ``training_dataloader``, ``lr_scheduler``
486
487 * ``engine``: DeepSpeed runtime engine which wraps the client model for distributed training.
488
489 * ``optimizer``: Wrapped optimizer if a user defined ``optimizer`` is supplied, or if
490 optimizer is specified in json config else ``None``.

Calls 14

_configure_python_gcMethod · 0.95
log_distFunction · 0.85
get_acceleratorFunction · 0.85
load_ds_configFunction · 0.85
set_autotp_modeFunction · 0.85
DeepSpeedConfigClass · 0.85
set_optimizer_flagsFunction · 0.85
DeepSpeedEngineClass · 0.85
warningMethod · 0.80
mpuMethod · 0.80