A type system for distributed (SPMD) tensor computations in PyTorch
Project description
spmd_types
A type system for distributed (SPMD) tensor computations in PyTorch. This package provides two type systems:
-
Local SPMD types, which allow you to use Megatron-style differentiable collectives in a safe way by tracking whether or not your backward gradients are pending reduction or not.
-
Global SPMD types, a DTensor-like abstraction for writing code that has the same semantics whether run on a single device or in a distributed fashion, but with explicit communication operations so you are never guessing when a redistribute occurs.
In both cases, the SPMD types makes it possible for you to check that your code computes correct gradients (local SPMD) or gives equivalent results across different parallelizations (global SPMD), without having to actually run a full E2E distributed training run to check for loss matching.
The goal of this package is to provide a flexible type system that can typecheck realistic training code. We have used local SPMD types to typecheck a realistic pretraining codebase, and global SPMD types is actively under construction!
Installation
pip install spmd_types
Quick start
import torch
import torch.distributed as dist
import spmd_types as spmd
import spmd_types.checker
from torch.distributed.device_mesh import init_device_mesh
# Set up a fake process group (no GPUs needed)
dist.init_process_group(backend="fake", rank=0, world_size=8)
mesh = init_device_mesh("cpu", (2, 4), mesh_dim_names=("dp", "tp"))
dp = mesh.get_group("dp")
tp = mesh.get_group("tp")
with spmd.set_current_mesh(mesh), spmd.checker.typecheck():
x = torch.randn(4)
spmd.assert_type(x, {dp: spmd.R, tp: spmd.P}) # R on dp, partial on tp
y = spmd.all_reduce(x, tp, src=spmd.P, dst=spmd.R) # sum across tp ranks
spmd.assert_type(y, {dp: spmd.R, tp: spmd.R}) # now replicated everywhere
z = torch.mul(y, y) # type inference: R * R -> R
spmd.assert_type(z, {dp: spmd.R, tp: spmd.R})
dist.destroy_process_group()
Documentation
See Local SPMD types for a hands-on guide on porting Megatron-derived training frameworks, including the Megatron-to-spmd_types function mapping table and advice on Invariant vs Replicate.
See Design for the full type system specification, including local vs global SPMD modes, collective signatures with diagrams, forward-backward pairs, expert mode, cross-mesh compatibility, and partition spec redistribute.
License
BSD 3-Clause License. See CONTRIBUTING.md for how to contribute.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spmd_types-0.2.2.tar.gz.
File metadata
- Download URL: spmd_types-0.2.2.tar.gz
- Upload date:
- Size: 107.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5278dd928224c0fc1d8d489163f5dc4bd81eaa4b2be97255701b629e9c1bcce1
|
|
| MD5 |
dbce0cf7e144d352ba7460f939a1ca35
|
|
| BLAKE2b-256 |
384de2a4ce1d569444c57f456cc1d3bc7102cfb95730f3244b86c9fca7969c3b
|
Provenance
The following attestation bundles were made for spmd_types-0.2.2.tar.gz:
Publisher:
publish_release.yml on meta-pytorch/spmd_types
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spmd_types-0.2.2.tar.gz -
Subject digest:
5278dd928224c0fc1d8d489163f5dc4bd81eaa4b2be97255701b629e9c1bcce1 - Sigstore transparency entry: 2174566105
- Sigstore integration time:
-
Permalink:
meta-pytorch/spmd_types@3fbbf5b91f41a779987cbe062d35f2e0c24c8d54 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/meta-pytorch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_release.yml@3fbbf5b91f41a779987cbe062d35f2e0c24c8d54 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spmd_types-0.2.2-py3-none-any.whl.
File metadata
- Download URL: spmd_types-0.2.2-py3-none-any.whl
- Upload date:
- Size: 120.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60c6f8b60f3767b09c5b63a9208bc4eb18758656bf3c6ab21085944fedad48a6
|
|
| MD5 |
4f5f893a76882c99b58b7335c0a12c73
|
|
| BLAKE2b-256 |
bc84336cab7ef7c53830f1563a4cdf0e015932c3e160306c0d3eef2eccd96a40
|
Provenance
The following attestation bundles were made for spmd_types-0.2.2-py3-none-any.whl:
Publisher:
publish_release.yml on meta-pytorch/spmd_types
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spmd_types-0.2.2-py3-none-any.whl -
Subject digest:
60c6f8b60f3767b09c5b63a9208bc4eb18758656bf3c6ab21085944fedad48a6 - Sigstore transparency entry: 2174566185
- Sigstore integration time:
-
Permalink:
meta-pytorch/spmd_types@3fbbf5b91f41a779987cbe062d35f2e0c24c8d54 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/meta-pytorch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_release.yml@3fbbf5b91f41a779987cbe062d35f2e0c24c8d54 -
Trigger Event:
workflow_dispatch
-
Statement type: