mixle.utils.parallel package¶
Distributed-estimation backends (multiprocessing, MPI, torchrun).
- class ModelParallelEstimator(inner, num_workers=None)[source]
Bases:
ParameterEstimatorWrap an estimator so EM distributes the model axis – composing with any
backend=for the data.optimize(ModelParallelEstimator(est), backend="spark"|"mpi"|"mp"|"local")shards the data through that backend while each partition’s E-step distributes the model axis. The M-step (estimate) and the accumulator’s value/combine contract are the wrapped estimator’s, unchanged.- Parameters:
inner (ParameterEstimator)
num_workers (int | None)
- accumulator_factory()[source]
- Return type:
ModelParallelAccumulatorFactory
- class ModelParallelEncodedData(data, *, estimator=None, model=None, encoder=None, num_workers=None, **_)[source]
Bases:
EncodedDataHandleReplicate the data, distribute the model’s shardable axis across threads (single machine).
- Parameters:
data (Any)
estimator (Any | None)
model (Any | None)
encoder (Any | None)
num_workers (int | None)
_ (Any)
- pysp_seq_log_density_sum(estimate)[source]
Return
(num_observations, summed_log_density)forestimate.
- pysp_seq_estimate(estimator, prev_estimate)[source]
Run one distributed/local sufficient-statistic fold and M-step.
- pysp_seq_initialize(estimator, rng, p)[source]
Initialize a model through the handle’s resident encoded data.
- Parameters:
estimator (Any)
rng (RandomState)
p (float)
- Return type:
- model_parallel_fold(acc, model, enc, weights, num_workers=None)[source]
Run a model-parallel E-step of
modelover encodedencinto accumulatoracc(in place).
- auto_parallel_estimator(estimator, model, resources=None, *, n_data=None, min_components_per_shard=1)[source]
Consult the C2 planner (
decompose_model()) and return(estimator, decomposition).When the planner picks model-parallelism for
modelonresources, the estimator is wrapped inModelParallelEstimatorsized to the planner’s cuts; otherwise the plain estimator is returned (replicate the model, shard the data – already optimal when N dominates). Either way, run the returned estimator throughoptimize(data, est, backend=<data backend>): the data axis is handled bybackendand the model axis, if any, by the wrapper – composing into the data x model split. Thedecomposition’srationaleexplains the choice.resourcesdefaults to the local CPU slots (useResources.from_spark(sc)/Resources.from_mpi()to size the split to a real cluster).
- class Resources(devices)[source]
Bases:
objectA collection of placement targets.
- Parameters:
devices (tuple[DeviceSpec, ...])
- devices: tuple[DeviceSpec, ...]
- classmethod single_cpu(memory_bytes=None, throughput=1.0, precision=None)[source]
Return a one-device CPU resource description.
- classmethod local(num_cpus=None, memory_bytes=None, precision=None)[source]
Return local CPU resources split into logical worker slots.
- classmethod discover(include_torch=True, cpu_workers=None, precision=None)[source]
Best-effort local resource discovery with no required extras.
- classmethod from_specs(specs)[source]
Build resources from an iterable of device specifications.
- Parameters:
specs (Iterable[DeviceSpec])
- Return type:
Resources
- classmethod from_mpi(comm=None, memory_bytes=None, throughput=1.0, precision=None)[source]
Return CPU resource slots for an MPI world without importing mpi4py.
commmay be an mpi4py-style communicator exposingGet_size. When it is omitted, common MPI launcher environment variables are used as a best-effort size hint, falling back to one slot.
- classmethod from_dask(client, precision=None)[source]
Return resource slots from a dask.distributed-like client.
The method relies only on
client.scheduler_info()and therefore does not introduce a dask dependency.
- classmethod from_spark(spark_context, memory_bytes=None, precision=None)[source]
Return CPU resource slots from a SparkContext-like object.
- classmethod from_torchrun(memory_bytes=None, precision=None)[source]
Return torchrun rank/device slots from launcher environment hints.
- fastest()[source]
Return the device with the largest advisory throughput weight.
- Return type:
DeviceSpec
- classmethod from_dict(payload)[source]
Build resources from
to_dictoutput.
- to_json(**kwargs)[source]
Serialize resources, including calibrated throughput, to JSON.
- classmethod from_json(text)[source]
Deserialize resources from JSON produced by
to_json.- Parameters:
text (str)
- Return type:
Resources
- save(path, **kwargs)[source]
Persist resources to a JSON file for reuse by later plans.
- encoded_data(data, estimator=None, model=None, encoder=None, placement=None, resources=None, engine=None, precision=None, num_chunks=None, sub_chunks=1, backend='local', num_workers=None, client=None, comm=None, root=0, root_only=False, parallel_chunks=False, chunk_workers=None)[source]
Return an encoded-data handle, preserving existing compatible handles.
Backend dispatch goes through a registry (see
register_encoded_data_backend()) rather than a hard-coded branch, so a new distributed framework (Lightning, Ray, JAX, …) plugs in by registering a factory – the same “register, don’t branch” pattern the compute engines use – without editing this function.- Parameters:
data (Any)
estimator (Any | None)
model (Any | None)
encoder (DataSequenceEncoder | None)
placement (Placement | None)
resources (Resources | None)
engine (Any | None)
precision (Any | None)
num_chunks (int | None)
sub_chunks (int)
backend (str)
num_workers (int | None)
client (Any | None)
comm (Any | None)
root (int)
root_only (bool)
parallel_chunks (bool)
chunk_workers (int | None)
- Return type:
EncodedDataHandle
- is_encoded_data_handle(obj)[source]
Return true when
objexposes the sequence-orchestrator contract.
- model_sharding_plan(model, resources, estimator=None, axis='components', min_components_per_shard=1)[source]
Return an advisory component-axis sharding plan.
This is the planning half of model parallelism. It does not create DTensor placements or move tensors; it answers which component range each device should own when a stacked/generated component kernel is available.
- plan(data=None, model=None, estimator=None, encoder=None, resources=None, engine=None, precision=None, num_chunks=None, sub_chunks=1, sample_size=256, safety_factor=1.25)[source]
Return an advisory placement for local or distributed orchestration.
Submodules¶
- mixle.utils.parallel.balance module
- mixle.utils.parallel.dcp_checkpoint module
- mixle.utils.parallel.lightning_data module
- mixle.utils.parallel.model_decomposition module
- mixle.utils.parallel.model_parallel module
- mixle.utils.parallel.mpi module
- mixle.utils.parallel.multiprocessing module
- mixle.utils.parallel.planner module
- mixle.utils.parallel.ray_data module
- mixle.utils.parallel.torch_neural module
- mixle.utils.parallel.torchrun module