mixle.utils.parallel package¶
Distributed-estimation planning and model-parallel entry points.
Importing this namespace registers the model-parallel encoded-data backend and exposes resource planning, sharding, and estimator wrappers used by multi-process or multi-device estimation workflows.
- class ModelParallelEstimator(inner, num_workers=None)[source]
Bases:
ParameterEstimatorCompatibility wrapper for fully resident component-parallel EM.
optimize(ModelParallelEstimator(est), backend="spark"|"mpi"|"mp"|"local")shards the data through that backend while each partition’s E-step threads independent model work. The full model remains resident in every process. 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 a factory that wraps the inner estimator’s accumulator factory.
- Return type:
ModelParallelAccumulatorFactory
- class ModelParallelEncodedData(data, *, estimator=None, model=None, encoder=None, num_workers=None, **_)[source]
Bases:
EncodedDataHandleCompatibility name for a fully resident, component-threaded data handle.
- 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 the encoded-data size and total log likelihood under
estimate.
- pysp_seq_estimate(estimator, prev_estimate)[source]
Run one model-parallel E/M update from
prev_estimate.
- pysp_seq_initialize(estimator, rng, p)[source]
Initialize a model by randomly selecting observations with probability
p.- Parameters:
estimator (Any)
rng (RandomState)
p (float)
- Return type:
- ComponentParallelEstimator
alias of
ModelParallelEstimator
- ComponentParallelEncodedData
alias of
ModelParallelEncodedData
- model_parallel_fold(acc, model, enc, weights, num_workers=None, *, parallel_ids=None)[source]
Run a component-parallel E-step over a fully resident model.
- component_parallel_fold(acc, model, enc, weights, num_workers=None, *, parallel_ids=None)
Run a component-parallel E-step over a fully resident model.
- auto_parallel_estimator(estimator, model, resources=None, *, n_data=None, min_components_per_shard=1)[source]
Return a plain estimator when no distributed model placement is required.
The structural planner is advisory. If it selects cuts that require model storage to be partitioned across devices, this helper raises
UnrealizedModelPlacementError: the local component-thread runtime cannot truthfully realize those cuts. Callers may explicitly chooseComponentParallelEstimatorwhen the full model fits in each process.
- exception UnrealizedModelPlacementError(plan)[source]
Bases:
RuntimeErrorA planner selected model shards for which this runtime has no placement executor.
- Parameters:
plan (Any)
- Return type:
None
- class Resources(devices)[source]
Bases:
objectA collection of placement targets.
- Parameters:
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 globally identified slots from an attested torchrun topology.
- 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.
- exception EncodedDataControlConflictError[source]
Bases:
ValueErrorRaised when controls request mutation of an already encoded handle.
- encoded_data(data, estimator=None, model=None, encoder=None, placement=None, resources=None, engine=None, precision=None, num_chunks=None, sub_chunks=1, backend=None, num_workers=None, client=None, comm=None, root=0, root_only=False, parallel_chunks=False, chunk_workers=None, batch_size=None, shuffle=None, seed=None)[source]
Create an encoded-data handle or explicitly reuse an unchanged handle.
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 | None)
num_workers (int | None)
client (Any | None)
comm (Any | None)
root (int)
root_only (bool)
parallel_chunks (bool)
chunk_workers (int | None)
batch_size (int | None)
shuffle (bool | None)
seed (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.
- register_encoded_data_backend(name, factory, aliases=(), *, override=False)[source]
Register an encoded-data backend factory under
name(and anyaliases).factoryis called asfactory(data, **params)with the keyword arguments ofencoded_data(); it should accept**_for the parameters it ignores and return anEncodedDataHandle. This is the extension point for new parallel/distributed frameworks – registering is all that is needed, no core edits.Raises
ValueErrorifnameor anyaliasis already registered to a DIFFERENT factory, rather than silently shadowing it – a third-party package registering under a name that collides with a built-in (e.g.'local') or another package’s backend would otherwise hijack every subsequentbackend=namecall with no error, no warning, at whatever time that package happened to import. Passoverride=Trueto replace an existing registration deliberately (e.g. hot-swapping a backend in a test).
- class BackendCapabilities(name, axes, precisions=frozenset({'bf16', 'fp32'}), distributed_optimizer=False, reshardable_checkpoint=False, elastic_restart=False, requirements=(), incompatible_axis_sets=())[source]
Bases:
objectWhat a backend actually executes, rather than merely accepting as flags.
- class CollectiveKind(*values)[source]
Bases:
StrEnumCollective or point-to-point operation required by an update.
- class DistributedUpdate(node_id, payload, collective, mesh_axes, state_layout, exact, notes=(), contract_exact=False, determinism_observed=None, maximum_absolute_error=None, maximum_relative_error=None, numerics_evidence_id=None, numerics_sample_count=0)[source]
Bases:
objectExecutable communication declaration with explicit numerical evidence.
- Parameters:
node_id (str)
payload (PayloadKind)
collective (CollectiveKind)
mesh_axes (tuple[ParallelAxis, ...])
state_layout (StateLayout)
exact (bool)
contract_exact (bool)
determinism_observed (bool | None)
maximum_absolute_error (float | None)
maximum_relative_error (float | None)
numerics_evidence_id (str | None)
numerics_sample_count (int)
- class ParallelAxis(*values)[source]
Bases:
StrEnumNamed dimensions understood by Mixle and external training engines.
- class ParallelPlan(dp_replicate=1, dp_shard=1, tp=1, pp=1, cp=1, ep=1, etp=1, microbatches=1, gradient_accumulation_steps=1)[source]
Bases:
objectAn explicit N-D process mesh and batch schedule.
Every process belongs to exactly one coordinate in the product below. Keeping replicate and shard data-parallel dimensions separate permits HSDP without conflating it with tensor or context parallelism.
- Parameters:
- property world_size: int
Number of physical ranks.
EP and ETP are overlapping process groups cut from the data/model domains, not extra orthogonal DeviceMesh dimensions.
- class ParameterLayout(logical_id, global_shape, placements=(), shared_group=None, optimizer_state=StateLayout.REPLICATED)[source]
Bases:
objectStable logical identity and global layout for one parameter.
- class StepReceipt(step, loss, local_examples, local_tokens, microbatches, accumulation_steps, data_parallel_size, optimizer, precision, collective_bytes=0, skipped=False, extra=<factory>, global_examples_observed=None, global_tokens_observed=None)[source]
Bases:
objectUnambiguous accounting for one committed optimizer update.
- Parameters:
- get_training_backend(name)[source]
Resolve a registered backend, calling a zero-argument lazy factory once.
- register_training_backend(name, backend, *, override=False)[source]
Register a backend instance or lazy factory without importing optional dependencies.
- class LightningFabricLauncher[source]
Bases:
objectCreate Fabric for pure DDP or FSDP jobs.
Lightning is capability-gated to data parallelism here. Model parallel dimensions remain the responsibility of the native DeviceMesh or Megatron backend rather than being accepted and discarded by Fabric.
- class RayTrainLauncher[source]
Bases:
objectLaunch one worker per physical plan rank with
ray.train.torch.
- class WorkerTopologyAttestation(rank, world_size, coordinate)[source]
Bases:
objectRuntime proof binding one launched rank to one planned mesh coordinate.
- attest_worker_coordinate(plan, *, actual_world_size, rank)[source]
Validate a runtime rank and deterministically bind it to the plan mesh.
Submodules¶
- mixle.utils.parallel.balance module
- mixle.utils.parallel.dcp_checkpoint module
- mixle.utils.parallel.em_observability module
- mixle.utils.parallel.fault_tolerant_training module
- mixle.utils.parallel.lightning_data module
- mixle.utils.parallel.megatron_training 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.resilient_em module
- mixle.utils.parallel.sdc_audit module
- mixle.utils.parallel.torch_neural module
- mixle.utils.parallel.torch_training module
- mixle.utils.parallel.torchrun module
- mixle.utils.parallel.training_contracts module
- mixle.utils.parallel.training_health module
- mixle.utils.parallel.training_launchers module