pytc.vmc.sharding¶
Multi-GPU sharding utilities for VMC.
This module provides helpers for distributing VMC walkers across multiple devices (GPUs/TPUs) using JAX’s built-in sharding.
The strategy is data-parallel over walkers: each device holds N/D walkers and performs per-walker computations independently. Only lightweight reductions (mean energy, J^T @ δE, J^T @ J) trigger cross-device communication, which JAX inserts automatically.
Usage¶
from pytc.vmc.sharding import create_mesh, shard_walker, get_sharding
mesh = create_mesh() # auto-detect devices
walkers = shard_walker(walkers, mesh) # shard along walker axis
params = replicate(params, mesh) # replicate on all devices
After sharding, the existing jax.vmap and jax.jit code works
unchanged — JAX’s SPMD compiler infers the communication.
Notes
folx.batched_vmapdoes not preserve sharding (it gathers results to all devices). Whenmulti_gpu=Truethe code should fall back tojax.vmapso that per-walker outputs stay distributed.Walkers must have
n_walkersdivisible by the number of devices.pad_walkerscan add padding walkers to satisfy this.
Functions
Assemble per-device local pytrees into a globally sharded pytree. |
|
Slice a pytree along the leading axis for all non-scalar leaves. |
|
Create a 1-D device mesh for walker-parallel sharding. |
|
NamedSharding that replicates data on every device. |
|
Return the appropriate vmap implementation. |
|
NamedSharding that partitions the leading (walker) dimension. |
|
Initialize walkers independently per device and return globally sharded walkers. |
|
True if more than one local device is available. |
|
Number of local devices available to this process. |
|
Return the smallest multiple of n_devices >= n_walkers. |
|
Pad a Walker pytree along axis 0 to target_n_walkers. |
|
Replicate a pytree on every device. |
|
Apply |
|
A version of jax.vmap that works across multiple devices using shard_map. |
|
Place a Walker (or any pytree) with sharding along axis 0. |
|
A version of folx.batched_vmap that works across multiple devices. |