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

Function tp_model_init

deepspeed/__init__.py:751–818  ·  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

749
750
751def tp_model_init(model: torch.nn.Module,
752 tp_size: int,
753 dtype: torch.dtype,
754 config: Optional[Union[str, Dict[str, Any]]] = None,
755 **kwargs: Any) -> torch.nn.Module:
756 """
757 Record tensor-parallel initialization arguments for training.
758
759 Note (compatibility and initialization behavior):
760 AutoTP sharding is applied during ``deepspeed.initialize(...)``. This
761 function exists for backward compatibility and only records TP arguments so
762 they can be validated and merged with the DeepSpeed config at initialization.
763 When you use both (i.e., calling ``set_autotp_mode(training=True)`` and
764 ``deepspeed.tp_model_init`` while also passing the config to
765 ``deepspeed.initialize``), DeepSpeed merges the settings at initialization.
766 Conflicting settings raise an error. The table below summarizes the behavior
767 across input combinations.
768
769 Inputs:
770 - TPI: tp_model_init was called? (Y/N)
771 - TPG: tp_model_init provided tp_group? (Y/N)
772 - CFG: tensor_parallel in DeepSpeed config? (Y/N)
773 - MPU: mpu passed to deepspeed.initialize()? (Y/N)
774
775 | TPI | TPG | CFG | MPU | Outcome | Notes |
776 |-----|-----|-----|-----|----------------------------------------|-------|
777 | N | N | N | N | Error | No TP intent; nothing to initialize |
778 | N | N | N | Y | No AutoTP | mpu may be used for other MP, but TP not enabled |
779 | N | N | Y | N | Init AutoTP from config | Use config; need TP group via config-driven init |
780 | N | N | Y | Y | Init AutoTP from config | mpu used to build TP group |
781 | Y | N | N | N | Error | No TP group source |
782 | Y | N | N | Y | Init AutoTP from tp_model_init | Use recorded args + mpu for TP group |
783 | Y | N | Y | N | Init AutoTP from config | Fill missing from TPI; error on mismatches; need TP group source |
784 | Y | N | Y | Y | Init AutoTP from config | Fill missing from TPI; error on mismatches |
785 | Y | Y | N | N | Init AutoTP from tp_model_init | Use recorded tp_group; config absent |
786 | Y | Y | N | Y | Error | tp_group + mpu conflict |
787 | Y | Y | Y | N | Init AutoTP from config | Error on mismatches; use tp_group from TPI; reject mpu |
788 | Y | Y | Y | Y | Error | tp_group + mpu conflict |
789
790 Field-level merge rules when both tp_model_init and config exist:
791 - Canonical source: config
792 - Allowed: fill missing config fields from tp_model_init
793 - Error on mismatch: autotp_size, dtype, tp_group size or identity
794
795 Extra checks:
796 - If tp_group is provided, reject mpu.
797 - If tp_group is not provided, require mpu (or another TP group source).
798 - If tensor_parallel is absent and only tp_model_init was called, require
799 a TP group source (direct tp_group or mpu).
800
801 Args:
802 model (torch.nn.Module): The model to be initialized.
803 tp_size (int): The tensor parallelism size.
804 dtype (torch.dtype): The data type to be used for the model.
805
806 Returns:
807 torch.nn.Module: The original model (no sharding applied here).
808 """

Callers

nothing calls this directly

Calls 4

set_autotp_modeFunction · 0.85
warningMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected