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)
| 406 | |
| 407 | |
| 408 | def tp_model_init(model: torch.nn.Module, |
| 409 | tp_size: int, |
| 410 | dtype: torch.dtype, |
| 411 | config: Optional[Union[str, Dict[str, Any]]] = None, |
| 412 | **kwargs: Any) -> torch.nn.Module: |
| 413 | """ |
| 414 | Record tensor-parallel initialization arguments for training. |
| 415 | |
| 416 | Note (compatibility and initialization behavior): |
| 417 | AutoTP sharding is applied during ``deepspeed.initialize(...)``. This |
| 418 | function exists for backward compatibility and only records TP arguments so |
| 419 | they can be validated and merged with the DeepSpeed config at initialization. |
| 420 | When you use both (i.e., calling ``set_autotp_mode(training=True)`` and |
| 421 | ``deepspeed.tp_model_init`` while also passing the config to |
| 422 | ``deepspeed.initialize``), DeepSpeed merges the settings at initialization. |
| 423 | Conflicting settings raise an error. The table below summarizes the behavior |
| 424 | across input combinations. |
| 425 | |
| 426 | Inputs: |
| 427 | - TPI: tp_model_init was called? (Y/N) |
| 428 | - TPG: tp_model_init provided tp_group? (Y/N) |
| 429 | - CFG: tensor_parallel in DeepSpeed config? (Y/N) |
| 430 | - MPU: mpu passed to deepspeed.initialize()? (Y/N) |
| 431 | |
| 432 | | TPI | TPG | CFG | MPU | Outcome | Notes | |
| 433 | |-----|-----|-----|-----|----------------------------------------|-------| |
| 434 | | N | N | N | N | Error | No TP intent; nothing to initialize | |
| 435 | | N | N | N | Y | No AutoTP | mpu may be used for other MP, but TP not enabled | |
| 436 | | N | N | Y | N | Init AutoTP from config | Use config; need TP group via config-driven init | |
| 437 | | N | N | Y | Y | Init AutoTP from config | mpu used to build TP group | |
| 438 | | Y | N | N | N | Error | No TP group source | |
| 439 | | Y | N | N | Y | Init AutoTP from tp_model_init | Use recorded args + mpu for TP group | |
| 440 | | Y | N | Y | N | Init AutoTP from config | Fill missing from TPI; error on mismatches; need TP group source | |
| 441 | | Y | N | Y | Y | Init AutoTP from config | Fill missing from TPI; error on mismatches | |
| 442 | | Y | Y | N | N | Init AutoTP from tp_model_init | Use recorded tp_group; config absent | |
| 443 | | Y | Y | N | Y | Error | tp_group + mpu conflict | |
| 444 | | Y | Y | Y | N | Init AutoTP from config | Error on mismatches; use tp_group from TPI; reject mpu | |
| 445 | | Y | Y | Y | Y | Error | tp_group + mpu conflict | |
| 446 | |
| 447 | Field-level merge rules when both tp_model_init and config exist: |
| 448 | - Canonical source: config |
| 449 | - Allowed: fill missing config fields from tp_model_init |
| 450 | - Error on mismatch: autotp_size, dtype, tp_group size or identity |
| 451 | |
| 452 | Extra checks: |
| 453 | - If tp_group is provided, reject mpu. |
| 454 | - If tp_group is not provided, require mpu (or another TP group source). |
| 455 | - If tensor_parallel is absent and only tp_model_init was called, require |
| 456 | a TP group source (direct tp_group or mpu). |
| 457 | |
| 458 | Args: |
| 459 | model (torch.nn.Module): The model to be initialized. |
| 460 | tp_size (int): The tensor parallelism size. |
| 461 | dtype (torch.dtype): The data type to be used for the model. |
| 462 | |
| 463 | Returns: |
| 464 | torch.nn.Module: The original model (no sharding applied here). |
| 465 | """ |
nothing calls this directly
no test coverage detected