mixle.utils.parallel.torchrun module¶
torchrun SPMD backend for distributed estimation.
The handle mirrors MPIEncodedData using torch.distributed collectives:
each rank encodes its local data shard once, accumulates sufficient statistics
against that resident encoding, rank 0 folds/key-ties/runs the M-step, and the
result is broadcast back to every rank.
- class TorchRunEncodedData(data, estimator=None, model=None, encoder=None, sub_chunks=1, group=None, root=0, root_only=False, init_process_group=True, backend=None)[source]
Bases:
EncodedDataHandleEncoded-data handle sharded across torchrun ranks.
- Parameters:
data (Optional[Sequence]) – Raw observations. With
root_only=Falseevery rank passes the same full dataset and keepsdata[rank::world]. Withroot_only=Trueonly the root rank needs real data.estimator – Used to build the encoder when
encoderis not given.model – Optional model used to build the encoder.
encoder – Explicit data encoder.
sub_chunks (int) – Encoded sub-chunks per rank.
group (Any | None) – Optional torch.distributed process group.
root (int) – Rank that folds statistics and runs the M-step.
root_only (bool) – Root-only data input mode.
init_process_group (bool) – Initialize
torch.distributedfrom the torchrun environment when needed.backend (Optional[str]) – Process-group backend. Defaults to
ncclon CUDA andgloootherwise.
- pysp_seq_estimate(estimator, prev_estimate)[source]
One distributed EM step; every rank returns the identical model.
- pysp_seq_initialize(estimator, rng, p)[source]
Distributed randomized initialization; identical model on all ranks.
- Parameters:
rng (RandomState)
p (float)
- pysp_seq_log_density_sum(estimate)[source]
Allreduced count and summed log density.
- pysp_stream_accumulate(estimator, model)[source]
Globally folded batch sufficient statistics for streaming EM.
- close()[source]
Release worker resources owned by this handle, if any.
- Return type:
None