A context to enable massive model construction for training with ZeRO-3. Models are automatically partitioned (or, sharded) across the system and converted to half precision. Args: module (``torch.nn.Module``, optional): If provided, partition the model as
(self,
module=None,
data_parallel_group=None,
mem_efficient_linear=True,
remote_device=None,
pin_memory=False,
config_dict_or_path=None,
config=None,
enabled=True,
dtype=None,
mpu=None)
| 609 | apply_param_persistence = False |
| 610 | |
| 611 | def __init__(self, |
| 612 | module=None, |
| 613 | data_parallel_group=None, |
| 614 | mem_efficient_linear=True, |
| 615 | remote_device=None, |
| 616 | pin_memory=False, |
| 617 | config_dict_or_path=None, |
| 618 | config=None, |
| 619 | enabled=True, |
| 620 | dtype=None, |
| 621 | mpu=None): |
| 622 | """A context to enable massive model construction for training with |
| 623 | ZeRO-3. Models are automatically partitioned (or, sharded) across the |
| 624 | system and converted to half precision. |
| 625 | |
| 626 | Args: |
| 627 | module (``torch.nn.Module``, optional): If provided, partition the model as |
| 628 | if it was constructed in the context. |
| 629 | data_parallel_group (``deepspeed.comm`` process group, optional): |
| 630 | The group of processes to partition among. Defaults to all processes. |
| 631 | mem_efficient_linear (bool, optional): Replace |
| 632 | torch.nn.functional.linear with an implementation that allows |
| 633 | DeepSpeed to partition parameters. Defaults to ``True``. |
| 634 | remote_device (string, optional): The initial device to store model |
| 635 | weights e.g., ``cpu``, ``nvme``. Passing ``"cpu"`` will create the model in CPU |
| 636 | memory. The model may still be moved to GPU based on the |
| 637 | offload settings for training. Defaults to param offload device if a config is |
| 638 | defined, otherwise GPU. |
| 639 | pin_memory (bool, optional): Potentially increase performance by |
| 640 | using pinned memory for model weights. ``remote_device`` must be |
| 641 | ``"cpu"``. Defaults to pin_memory value in config, otherwise ``False``. |
| 642 | config_dict_or_path (dict or ``json file``, optional): If provided, provides configuration |
| 643 | for swapping fp16 params to NVMe. |
| 644 | config (dict or ``json file``, optional): Deprecated, use config_dict_or_path instead. |
| 645 | enabled (bool, optional): If ``False``, this context has no |
| 646 | effect. Defaults to ``True``. |
| 647 | dtype (``dtype``, optional): Can be used to change the data type of the parameters. |
| 648 | Supported options are ``torch.half`` and ``torch.float``. Defaults to ``None`` |
| 649 | mpu (``object``, optional): A model parallelism unit object that implements get_{model,data}_parallel_{rank,group,world_size}. |
| 650 | |
| 651 | This context accelerates model initialization and enables models that |
| 652 | are too large to allocate in their entirety in CPU memory. It has the |
| 653 | following effects: |
| 654 | |
| 655 | #. allocates tensors to either GPU or CPU memory or NVMe |
| 656 | #. converts floating point tensors to half precision |
| 657 | #. immediately partitions tensors among the group of data-parallel devices |
| 658 | #. (*optional*) replaces ``torch.nn.functional.linear`` with a more |
| 659 | memory-efficient implementation |
| 660 | |
| 661 | These modifications allow for models that exceed the size of local CPU/GPU |
| 662 | memory/NVMe, but fit within the total NVMe capacity (*i.e.*, aggregate CPU |
| 663 | or GPU memory or NVMe) across all nodes. Consider initializing a model with one |
| 664 | trillion parameters, whose weights occupy two terabytes (TB) in half |
| 665 | precision. The initial CPU allocation in full precision requires 4TB of |
| 666 | memory *per process*, and so a system with 8 GPUs per node would need 32TB of |
| 667 | CPU memory due to data-parallel redundancies. Instead, by immediately |
| 668 | partitioning tensors we remove the redundancies. The result is that |
nothing calls this directly
no test coverage detected