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

Function tp_model_init

deepspeed/__init__.py:781–848  ·  view source on GitHub ↗

Record tensor-parallel initialization arguments for training. Note (compatibility and initialization behavior): AutoTP sharding is applied during ``deepspeed.initialize(...)``. This function exists for backward compatibility and only records TP arguments so they can be validate

(model: torch.nn.Module,
                  tp_size: int,
                  dtype: torch.dtype,
                  config: Optional[Union[str, Dict[str, Any]]] = None,
                  **kwargs: Any)

Source from the content-addressed store, hash-verified

779
780
781def tp_model_init(model: torch.nn.Module,
782 tp_size: int,
783 dtype: torch.dtype,
784 config: Optional[Union[str, Dict[str, Any]]] = None,
785 **kwargs: Any) -> torch.nn.Module:
786 """
787 Record tensor-parallel initialization arguments for training.
788
789 Note (compatibility and initialization behavior):
790 AutoTP sharding is applied during ``deepspeed.initialize(...)``. This
791 function exists for backward compatibility and only records TP arguments so
792 they can be validated and merged with the DeepSpeed config at initialization.
793 When you use both (i.e., calling ``set_autotp_mode(training=True)`` and
794 ``deepspeed.tp_model_init`` while also passing the config to
795 ``deepspeed.initialize``), DeepSpeed merges the settings at initialization.
796 Conflicting settings raise an error. The table below summarizes the behavior
797 across input combinations.
798
799 Inputs:
800 - TPI: tp_model_init was called? (Y/N)
801 - TPG: tp_model_init provided tp_group? (Y/N)
802 - CFG: tensor_parallel in DeepSpeed config? (Y/N)
803 - MPU: mpu passed to deepspeed.initialize()? (Y/N)
804
805 | TPI | TPG | CFG | MPU | Outcome | Notes |
806 |-----|-----|-----|-----|----------------------------------------|-------|
807 | N | N | N | N | Error | No TP intent; nothing to initialize |
808 | N | N | N | Y | No AutoTP | mpu may be used for other MP, but TP not enabled |
809 | N | N | Y | N | Init AutoTP from config | Use config; need TP group via config-driven init |
810 | N | N | Y | Y | Init AutoTP from config | mpu used to build TP group |
811 | Y | N | N | N | Error | No TP group source |
812 | Y | N | N | Y | Init AutoTP from tp_model_init | Use recorded args + mpu for TP group |
813 | Y | N | Y | N | Init AutoTP from config | Fill missing from TPI; error on mismatches; need TP group source |
814 | Y | N | Y | Y | Init AutoTP from config | Fill missing from TPI; error on mismatches |
815 | Y | Y | N | N | Init AutoTP from tp_model_init | Use recorded tp_group; config absent |
816 | Y | Y | N | Y | Error | tp_group + mpu conflict |
817 | Y | Y | Y | N | Init AutoTP from config | Error on mismatches; use tp_group from TPI; reject mpu |
818 | Y | Y | Y | Y | Error | tp_group + mpu conflict |
819
820 Field-level merge rules when both tp_model_init and config exist:
821 - Canonical source: config
822 - Allowed: fill missing config fields from tp_model_init
823 - Error on mismatch: autotp_size, dtype, tp_group size or identity
824
825 Extra checks:
826 - If tp_group is provided, reject mpu.
827 - If tp_group is not provided, require mpu (or another TP group source).
828 - If tensor_parallel is absent and only tp_model_init was called, require
829 a TP group source (direct tp_group or mpu).
830
831 Args:
832 model (torch.nn.Module): The model to be initialized.
833 tp_size (int): The tensor parallelism size.
834 dtype (torch.dtype): The data type to be used for the model.
835
836 Returns:
837 torch.nn.Module: The original model (no sharding applied here).
838 """

Callers

nothing calls this directly

Calls 4

set_autotp_modeFunction · 0.85
warningMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected