Skip to main content

A type system for distributed (SPMD) tensor computations in PyTorch

Project description

spmd_types

A type system for distributed (SPMD) tensor computations in PyTorch.

spmd_types tracks per-mesh-axis types on tensors -- Replicate (R), Invariant (I), Varying (V), Partial (P), and Shard (S) -- and enforces type-correct transitions through collective operations and local rewrites. It catches distributed programming errors at development time without requiring a GPU cluster.

Installation

pip install spmd_types

Quick start

import torch
import torch.distributed as dist
import spmd_types as spmd
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.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 MEGATRON_QUICKSTART.md for a guide on porting Megatron-derived training frameworks to use spmd_types.

See DESIGN.md for the full type system specification, including type inference rules, collective signatures, and forward-backward pairs.

License

BSD 3-Clause License. See LICENSE for details.

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

spmd_types-0.2.1.tar.gz (105.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spmd_types-0.2.1-py3-none-any.whl (118.4 kB view details)

Uploaded Python 3

File details

Details for the file spmd_types-0.2.1.tar.gz.

File metadata

  • Download URL: spmd_types-0.2.1.tar.gz
  • Upload date:
  • Size: 105.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spmd_types-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4a7364e22553384a5c94decb3a390945f9a880eaf42689cf48af836e9c928c36
MD5 2d460afc0b3330ef91c18960dbb0c9fa
BLAKE2b-256 d2d4adbc2fc5b9e5c5078c63dce783439236dfb9bc0fbb884c548be440acfaec

See more details on using hashes here.

Provenance

The following attestation bundles were made for spmd_types-0.2.1.tar.gz:

Publisher: publish_release.yml on meta-pytorch/spmd_types

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spmd_types-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: spmd_types-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 118.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spmd_types-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b7ba23a73b9c2a86a24d517880867a9d9d03da32c1aef74445a49c22b135891
MD5 046e6d20098afe4d427042793ed256cf
BLAKE2b-256 20da332e1ff31f68b6425baabf035652b4ae784e3e3aa483d93e27baf83cf2b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for spmd_types-0.2.1-py3-none-any.whl:

Publisher: publish_release.yml on meta-pytorch/spmd_types

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page