nvalchemi.distributed.DistributedModel#
- class nvalchemi.distributed.DistributedModel(wrapper, domain_config, *, spec=None, compile=False, compile_kwargs=None)[source]#
Wrap an atomic single-process model wrapper for domain-decomposed inference.
- Parameters:
wrapper (BaseModelMixin) – Atomic
BaseModelMixin. Itsdistribution_specmust be non-None. Composite wrappers (PipelineModelWrapper) are rejected — useDistributedPipelineModelfor composition.domain_config (DomainConfig) – Shared simulation config carrying the cutoff, skin, mesh, and optional grid_dims. The partitioner and halo config are built lazily from the first
ShardedBatch’s geometry.spec (MLIPSpec, optional, keyword-only) – Explicit distribution spec (the joint model x strategy product). When
None(default), it is obtained fromwrapper.distribution_spec(domain_config.strategy); a wrapper withdistribution_spec=Nonerequires this argument.compile (bool, optional, keyword-only) – When
True, compile the energy-autograd forward path (fixed-shape padded, per-rank). The spec carries only the compile contract; this switch enables it. DefaultFalse.compile_kwargs (dict, optional, keyword-only) – Extra keyword arguments forwarded to the compile of the distributed forward, merged with the spec’s compile contract. Only consulted when
compile=True. DefaultNone.
Notes
Construction is side-effect-free. The first call to
__call__initializes the partitioner / halo config / world size from the suppliedShardedBatchand invokeswrapper.distributed_setup.close()— or__exit__/__del__— callswrapper.distributed_teardownto restore any module-level state. Use as a context manager for scoped lifecycle:with DistributedModel(wrapper, config) as dist_model: out = dist_model(sharded)
- close()[source]#
Release resources and restore any state setup mutated. Safe to call multiple times.
Restores all adapters installed by
adapter_registry(custom_ops + third_party_helpers), then defers to the wrapper’s optionaldistributed_teardownhook for any wrapper-side runtime state.- Return type:
None
- property config: DomainConfig#
The
DomainConfigheld by this adapter.
- from_batch(batch, *, src=0)[source]#
One-call distributed inference from a full
Batch.The convenience entry for one-off inference: shards
batchacross the scope’s mesh (viaShardedBatch.from_batch(), using the heldDomainConfig) and runs the distributed forward — so a caller never constructs aShardedBatchby hand. Collective: every rank calls it, with the full system on ranksrcandNoneelsewhere; every rank gets the consolidated output dict back.- Parameters:
- Returns:
The consolidated outputs (owned-shape per-atom + replicated per-system), identical to calling
__call__()on a hand-builtShardedBatch.- Return type:
dict[str, Any]
- property wrapper: BaseModelMixin#
The underlying single-process model wrapper.