The optimum.neuron.distributed module provides a set of tools to perform distributed training and inference.
Each model that supports parallelization in optimum-neuron has its own derived Parallelizer class. The factory class ParallelizersManager allows you to retrieve such model-specific Parallelizers easily.
Provides the list of supported model types for parallelization.
( model_type_or_model: typing.Union[str, transformers.modeling_utils.PreTrainedModel, optimum.neuron.utils.peft_utils.NeuronPeftModel] )
Returns a tuple of 3 booleans where:
( model_type_or_model: typing.Union[str, transformers.modeling_utils.PreTrainedModel, optimum.neuron.utils.peft_utils.NeuronPeftModel] )
Returns the parallelizer class associated to the model.
Distributed training / inference is usually needed when the model is too big to fit in one device. Tools that allow for lazy loading of model weights and optimizer states are thus needed to avoid going out-of-memory before parallelization.
( tensor_parallel_size: int = 1 pipeline_parallel_size: int = 1 )
Context manager that makes the loading of a model lazy for model parallelism:
torch.nn.Linear is put on the torch.device("meta") device, meaning that it takes no memory to
instantiate.torch.nn.Embedding is also put on the torch.device("meta") device.optimum.neuron.distributed.utils.from_pretrained_for_mp docstring.If both tensor_parallel_size and pipeline_parallel_size are set to 1, no lazy loading is performed.
( optimizer_cls: typing.Type[ForwardRef('torch.optim.Optimizer')] )
Transforms an optimizer constructor (optimizer class) to make it lazy by not initializing the parameters. This makes the optimizer lightweight and usable to create a “real” optimizer once the model has been parallelized.