nvalchemi.distributed.trace_and_validate#
- nvalchemi.distributed.trace_and_validate(model_factory, sample_batch, *, world_size=2, device='cuda:0', atol=1e-5, rtol=1e-4, auto_fix=True, max_fix_attempts=8, backend='auto', timeout_sec=120.0, watched_helper_packages=None, helper_sample_every=8, layer_diagnostic=True)[source]#
Infer a distribution spec, validate it on a single-GPU multi-process run, and (optionally) auto-fix when validation fails.
- Parameters:
model_factory (Callable[[], Any]) – Callable returning a freshly-constructed wrapper. Called once in the launcher process for the reference run, and once per rank in each spawned worker. Pristine state every time — no shared module graph between processes.
sample_batch (Any) – A
Batch(or compatible) carrying positions / cell / pbc on the targetdevice. Small enough thatworld_sizecopies fit in memory at once.world_size (int) – Virtual ranks to spawn on the same GPU. The default (2) is sufficient to flush the dispatch logic; larger values catch partition-dependent bugs but cost spawn overhead linearly.
device (str | device) – CUDA device all ranks bind to. Default
"cuda:0". CPU validation is not supported by this entry point — CPU/GPU numerical drift makes it unreliable; if you need it, call the harness intest_dispatch_trace_gloo.pydirectly.atol (float) – Per-output absolute tolerance. Pass criterion (per output) is
abs_diff <= atol OR rel_diff <= rtol— same conventiontorch.testing.assert_close()uses, so extensive quantities (energy scales linearly with atom count) compare correctly across system sizes.rtol (float) – Per-output relative tolerance. Default
1e-4covers fp32 round-off accumulation across collective reductions on thecpu:gloo,cuda:gloobackend; tighten to e.g.1e-5when running NCCL or fp64.auto_fix (bool) – When the initial inferred spec fails validation, try rule-based mutations. Disable to get a single-attempt report.
max_fix_attempts (int) – Cap on the number of distinct specs auto-fix will try.
backend (str) –
"nccl","gloo", or"auto"(NCCL when CUDA is available, else Gloo). Both correctly route over CUDA tensors; NCCL is faster.timeout_sec (float) – Per-spawn join timeout.
watched_helper_packages (Sequence[str] | None) – Fully-qualified module paths whose top-level Python helpers get instrumented during the reference and per-rank runs. The
helper_traceproxy records each call’s input / output shapes + sums; thehelper_diagnosisclassifier then flags helpers that look like distribution gaps (per-system reductions whose per-rank outputs sum to the reference output but aren’t declared inspec.distribution.third_party_helpers). Defaults to("aimnet.nbops",). Pass an explicit empty tuple to disable. Unimportable packages are skipped silently.helper_sample_every (int) – Record every Nth call after the first call per
(module, function). Default 8 keeps overhead bounded for hot helpers (mol_sumruns multiple times per layer); set to 1 for exhaustive recording (debug only).layer_diagnostic (bool)
- Returns:
Carries the working (or best-guess) spec, every attempt’s diff/handler-counts, and a one-line
next_action.- Return type:
TraceReport