Skip to main content

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 the SPMD Types documentation for the complete user and API 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 Rules for how to write an spmd_typecheck typing rule for your own custom autograd functions by composing spmd_types.rules, and how to test it numerically with rulecheck.

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.

Metadata

Release files for spmd-types 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spmd-types 0.3.2
File Size Uploaded Provenance Actions
spmd_types-0.3.2.tar.gz 142.7 kB With provenance Details for spmd_types-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spmd-types 0.3.2
File Interpreter ABI Platform Actions
spmd_types-0.3.2-py3-none-any.whl Python 3 none any Details for spmd_types-0.3.2-py3-none-any.whl

Total release size: 299.5 kB

Release files / spmd_types-0.3.2.tar.gz

Download URL spmd_types-0.3.2.tar.gz
Size 142.7 kB
Tags Source
SHA-256 checksum
How to use checksums
654c72e8211de8de5fe1a0dcb82e4337d21d2243cdf3c89064ef915ac8cfd689
BLAKE2b-256 checksum
How to use checksums
45b36da713f20bf6bcce9e11d7185a94dc5db7dd257e41506cb6d03dd6396ca4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / spmd_types-0.3.2-py3-none-any.whl

Download URL spmd_types-0.3.2-py3-none-any.whl
Size 156.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c01cc11383dc53b42ac256bee0045d9926ebf103143de54f40570482215dabc4
BLAKE2b-256 checksum
How to use checksums
648b62ce4122232763efd13e19dc6c2d68ee47681e1447d281cf368eeca23f8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for spmd-types 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spmd_types-0.3.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page