mixle.utils.parallel.torch_training module

Executable PyTorch distributed-gradient backend.

This is the native path for arbitrary Mixle nn.Module objects. It uses public PyTorch APIs: DeviceMesh/DTensor tensor parallelism, FSDP2 (including HSDP), DDP, distributed checkpoint-compatible optimizer state, and the experimental context-parallel SDPA context manager. Pipeline and expert parallel transformer training belong to the Megatron backend, whose model partitioner owns those semantics.

class TorchDistributedBackend[source]

Bases: object

Native backend for Mixle modules that remain ordinary PyTorch modules.

prepare(module, *, plan, **kwargs)[source]

Materialize mesh, transforms, optimizer, and resumable session.

Parameters:
  • module (Any)

  • plan (ParallelPlan)

  • kwargs (Any)

Return type:

TorchDistributedSession

class TorchDistributedSession(module, *, plan, capabilities, mesh, device, optimizer, optimizer_receipt, parameter_layouts, precision, max_grad_norm, scheduler=None, manual_data_parallel=False)[source]

Bases: object

A transformed module plus optimizer and explicit process-mesh semantics.

Parameters:
  • module (Any)

  • plan (ParallelPlan)

  • capabilities (BackendCapabilities)

  • mesh (Any)

  • device (Any)

  • optimizer (Any)

  • optimizer_receipt (dict[str, Any])

  • parameter_layouts (tuple[ParameterLayout, ...])

  • precision (str)

  • max_grad_norm (float | None)

  • scheduler (Any)

  • manual_data_parallel (bool)

train_batch(inputs, targets)[source]

Accumulate one local batch and commit when the configured clock fires.

Parameters:
Return type:

StepReceipt

discard_accumulation()[source]

Explicitly discard pending gradients without changing parameters or optimizer state.

Return type:

StepReceipt | None

save_checkpoint(path, *, loader_state=None, typed_scheduler_state=None, extra=None, asynchronous=False)[source]

Save all state needed to resume this session.

Parameters:
Return type:

Any

load_checkpoint(path, *, allow_world_size_change=False)[source]

Restore this transformed model/optimizer and resume its step clock.

Parameters:
  • path (str)

  • allow_world_size_change (bool)

Return type:

dict[str, Any]

reduce_sums(*values)[source]

Sum scalar metrics over the two-dimensional data-parallel domain.

Parameters:

values (float)

Return type:

tuple[float, …]

class TorchSessionState(step, pending_accumulation, optimizer_receipt)[source]

Bases: object

Serializable non-tensor clocks owned by a native training session.

Parameters:
describe_parameter_layouts(module, plan)[source]

Capture stable logical identities before distributed wrappers rewrite parameters.

Parameters:
  • module (Any)

  • plan (ParallelPlan)

Return type:

tuple[ParameterLayout, …]