Auto-distillation¶
loupgym distill (and loupgym.auto_distill(...)) automatically builds, trains, selects, exports, and verifies a compact FastLR-SK (arch=ilmlip) student potential tailored to your chemical system.
All three data sources (--structure, --md-data, --dft-data) are optional — provide any combination and LoupGYM adapts the pipeline automatically:
# Structure-only: runs teacher MD across temperatures, labels frames, trains & gates the best student
loupgym distill --teacher omat0-medium --structure cell.cif --speed fast50 --output ./student_out
# Existing MD trajectories + DFT frames (teacher labels MD frames, aligns energy offset to DFT)
loupgym distill --teacher mh1 --head matpes_r2scan --md-data md.extxyz --dft-data dft.extxyz --output ./student_out
# Direct DFT-only training (no teacher needed)
loupgym distill --dft-data dft_train.extxyz --speed balanced --output ./student_out
Pipeline stages¶
- System analysis (
loupgym.distill.analyze): Inspects the input structures to classify the system (ionic_crystal,molecular_liquid,isolated_molecule, etc.), detects covalent molecular units and hydrogen bonds, measures neighbor densities, and proposes a tailored candidate pool ofFastLR-SKstudent architectures. - Dataset preparation (
loupgym.data): - If
--structureis given without enough frames, runs short multi-temperature teacher MD trajectories (plus mild volume strains for periodic crystals) usingloupmdon GPU to generate diverse training, validation, and held-out test frames. - Normalizes energy, forces, and 3×3 stress (auto-detecting
REF_energy/energy,REF_forces/forces,SinglePointCalculator, or custom--energy-key/--forces-key/--stress-key). - When both
--teacherand--dft-dataare provided, fits per-species E0 alignment between teacher labels and DFT references so both datasets train coherently. - Attaches
mol_idarrays automatically for molecular liquids so net-force and torque losses can be applied. - Candidate tournament (
loupgym.distill.cuda_trainer): Trains candidateFastLR-SKstudents in pure CUDA (build/libloup_lrsk_full_train_v3.so), benchmarks each candidate's actual inference speed inlibloupmd.so, and picks the most accurate student that meets the target speed budget. - Optional active learning (
--active-learning-rounds): Runs short MD with the winning student, selects high-error/novel frames, relabels them with the teacher, and refines the student. - Export & verification: Exports the winning student to
student.loup(arch=ilmlip) vialoupmd.export.ilmlip.export_ilmlip_checkpoint, runs the 3× float32-vs-float64 accuracy gate againstlibloupmd.so, and writesreport.json.
Speed presets & budgets¶
Preset (--speed) |
Target MD step cost | Typical architecture |
|---|---|---|
fast50 (default) |
<= 0.05 µs/atom (~0.25 ms on 5,000 atoms) |
Compact 2-layer FastLR-SK (c=(4,4,0) or c=(2,2,0), nb=(8,4)/(8,8)) |
balanced |
<= 0.10 µs/atom |
Wider radial/angular basis and higher cutoff |
accurate |
<= 0.25 µs/atom |
Largest candidate basis for maximum fidelity |
Budget (--budget) |
Scope |
|---|---|
quick |
Fast screening & shorter training epochs (smoke runs / prototyping) |
standard (default) |
Full candidate tournament + full training schedule |
thorough |
Extended epochs + larger candidate sweep + active learning refinement |
Verified Phase 2 distilled student benchmarks (RTX 5060 Ti, sm_120)¶
| System | FastLR-SK Architecture |
Atoms (N) |
NVE (µs/at) |
Langevin (µs/at) |
3× Gate (E / F / S) |
Accuracy (float64) |
|---|---|---|---|---|---|---|
| SrTiO₃ | c=(4,4,0) t=[16,16,12,8] nb=(8,4) r=4.6 |
5,000 | 0.0462 |
0.0490 |
PASS (0.02× / 0.17× / 0.06×) |
960/960 phonons; test F = 7.28 meV/Å |
| Molten Salt | c=(4,4,0) t=[24,16,8,4] nb=(8,4) r=6.2 |
3,888 | 0.0451 |
0.0474 |
PASS (0.00× / 0.12× / 0.05×) |
test F = 8.22–8.40 meV/Å |
n3tbu_v1 |
c=(4,4,0) t=[16,16,8,4] nb=(8,4) r=(4.2,4.8) |
4,320 | 0.0464 |
0.0493 |
PASS (0.01× / 0.17× / 0.30×) |
test F = 20.81 meV/Å |
| Water | c=(2,2,0) t=[16,16,16] nb=(8,8) r=(4.2,5.8) |
5,184 | 0.0464 |
0.0497 |
PASS (0.11× / 0.31× / 0.59×) |
target F = 19.78 meV/Å (COM 18.1, torque 12.8) |
The water student was replaced¶
The water student in the table above has deep wells below its training data's closest pairs: for two rigid waters it gives -59 eV at an O–H distance of 1.25 Å, where the teacher (MACE-OFF24-medium) gives +0.8 eV. About one 2 ps Langevin block in ten blew up at 5,184 atoms (300 K, 0.5 fs), and at 1.31M atoms the cell collapsed within 60 steps. The engine matched the PyTorch float64 student there, so this was a model defect, not an engine one.
Its replacement, water_zG, has the same architecture and was trained on labels that include close-contact frames
(weight 0.03, 1,200 epochs), with ZBL radii of 1.1 Å (H–H), 0.8 Å (O–H) and 2.0 Å (O–O) and a ZBL switch of 2 eV.
On the validation frames its force RMSE is 23.0 meV/Å, against 21.0 for the student above, and its largest force
error is lower (0.150 against 0.207 eV/Å). It ran 100 of 100 Langevin blocks of 2 ps at 5,184 atoms and 8,000 steps
at 1.31M atoms (4,000 NVE, then 4,000 Langevin) without a blow-up. One dip remains: -2.0 eV for two oxygens 1.6 Å
apart, behind a barrier of +1.9 eV at 1.8 Å; no run brought two oxygens closer than 2.35 Å.
Short range: close-contact frames and ZBL radii¶
water_zG's recipe is a set of loupgym distill options (auto_distill takes the same names in Python, below).
Their defaults keep the earlier behaviour: no contact frames, ZBL radii of 0.65 times the sum of the two covalent
radii, and the switch at 10 eV.
| Option | Default | What it does |
|---|---|---|
--contact-frames N |
0 |
Adds N close-contact frames, made from the training frames and labelled by the teacher (needs --teacher) |
--contact-weight W |
0.03 |
Per-frame loss weight of the contact frames (teacher frames have 1, DFT frames --dft-weight) |
--contact-sites N |
3 |
Contacts per contact frame |
--contact-range KIND=LO:HI |
from the data | Distance range (Å) of one contact kind, e.g. inter:O-O=1.8:2.4; repeatable |
--zbl-switch EV |
10 |
Per-atom ZBL energy (eV) at which the learned energy is switched off |
--zbl-radii SPEC |
covalent |
ZBL radius per element pair: covalent, data, or H-H=1.1,O-H=0.8,O-O=2.0 (Å) |
For a molecular liquid:
loupgym distill --teacher off24-medium --md-data water.extxyz --contact-frames 240 --zbl-switch 2 \
--zbl-radii data --epochs 1200 --output ./water_student
Each contact frame starts from a training frame and pushes up to --contact-sites sites, at least 7 Å apart, below
the closest pairs of the training frames. There are three kinds of site:
inter:A-B: an A…B contact between two molecules, or between two atoms in a system without molecules. The molecule that holds B is rotated rigidly about B, by up to 60°, and moved along the contact line to the target distance.bond:A-B: a compressed A–B bond; the bond's terminal atom moves along the bond.angle:A-B: two atoms bonded to a common centre (the H–O–H of water) brought closer by closing the angle; the bond lengths stay as they were.
A kind's range ends at 1.02 times the closest such pair in the training frames. It starts at 0.45 times that for
intermolecular pairs with hydrogen, 0.76 for other intermolecular pairs, 0.82 for bonds and 0.78 for angles. Three
quarters of the sites are intermolecular, and no other intermolecular pair may end closer than 0.92 times the lower
end of its kind. A frame is rejected when the teacher puts it more than 0.5 eV below the frame it was made from (a
well of the teacher's own, which the student must not learn) or gives a force above 80 eV/Å. For the water data of
the benchmarks these rules give the shares of the hand-made frames that water_zG was trained on and ranges within
0.05 Å of theirs, e.g. 0.65–1.45 Å for intermolecular O–H (hand-made: 0.70–1.45) and 1.83–2.41 Å for O–O (1.80–2.40).
The contact frames are left out of the E0 fit, the descriptor calibration and the force and molecular loss scales,
so they do not rescale the model. --zbl-radii data sets each pair's radius to 0.85 times its closest distance in
the training frames (never below the covalent default), so ZBL stays off in normal MD and takes over below the data:
1.09 Å (H–H), 0.74 Å (O–H) and 2.01 Å (O–O) for the water data, where water_zG had 1.1, 0.8 and 2.0.
A fifth as many contact frames are made from the test frames for the report. contact_frames.extxyz and
contact_test.extxyz are written next to the bundle, and report.json's short_range section holds the kinds and
ranges, the rejections, the teacher's energies against the base frames and the student's errors on the test contacts.
The bundle carries the radii and the switch.
A screen on the benchmarks' water data (RTX 4000 Ada, sm_89; a stability screen, so no times) trained two
students with auto_distill's quick budget and MACE-OFF24-medium as the teacher, on the same frames, seed and
architecture (c=(2,2,0) t=[16,16,16] nb=(8,8) r=(3.7,5.8), the tournament's pick in both): one with the options of the example above, one with the
defaults. The contacts came out as 240 training and 48 test frames with no rejection. In 100 Langevin blocks of
2 ps at 5,184 atoms (300 K, 0.5 fs):
| Student | Blocks blown | Force RMSE, validation (meV/Å) | Force RMSE, test contacts (meV/Å) | Contact energy RMSE against the teacher (eV) |
|---|---|---|---|---|
| With the options | 0 of 100 | 24.6 | 81 | 0.16 |
| Defaults | 10 of 100 | 20.6 | 18,778 | 25.8 |
water_zG |
0 of 100 | 22.9 | 73 | 0.18 |
| The student in the table above | 13 of 100 | 21.0 | 2,753 | 13.3 |
The options cost accuracy on normal water (24.6 against 20.6 meV/Å; water_zG paid 22.9 against 21.0), and
both new students passed the gate and the MD parity check. For two rigid waters the student with the options is
repulsive down to 0.3 Å (H–H) and 0.4 Å (O–H), as water_zG is. For O–O it keeps a dip of -10.1 eV at 1.5 Å behind
a barrier of +3.9 eV at 1.7 Å (water_zG: -2.0 eV at 1.6 Å behind +1.9 eV), below the 1.85 Å where its O–O
contacts end; a wider range (--contact-range inter:O-O=1.4:2.4) is the option for that, and has not been screened.
The validation frames were in the pool auto_distill split, so the two new students' accuracies compare with each
other, not with water_zG's held-out figures.
Students on the A100 (A100-SXM4-40GB, sm_80)¶
The 0.0.4 library tunes the students' kernels and launch settings for compute capability 8.0. The same four benchmark students (water: the student in the table above, so the numbers compare with earlier screens), NVE at the real time step, after the MD loop's graph-reuse fix. "One call" is a single 500-step call, rebuilds and graph captures included; "sustained" is the median of 1 s blocks after it:
| System | Atoms (N) |
µs per atom-step, one call | sustained |
|---|---|---|---|
| SrTiO₃ | 5,000 | 0.0367 |
0.0366 |
| Molten Salt | 3,888 | 0.0416 |
0.0411 |
n3tbu_v1 |
4,320 | 0.0449 |
0.0415 |
| Water | 5,184 | 0.0405 |
0.0401 |
The next release takes another 1 to 3% off these steps with kernel changes for compute capability 8.0 and 9.0
(sustained, at the real time step: SrTiO₃ 0.983, salt 0.994, n3tbu_v1 0.991, water 0.972 of 0.0.4's). One 500-step
call then runs at 0.0358, 0.0413, 0.0442 and 0.0392 µs per atom-step.
At these sizes every per-step kernel runs at 0.24 to 1.93 waves on the A100's 108 multiprocessors, so a step is a
chain of latencies more than of throughput. From about 320,000 atoms on the time per atom is flat, at 0.024 to 0.027
µs per atom-step (NVE at a time step of 1e-4 fs, so without neighbour rebuilds; measured with an earlier build of
the library). The largest whole systems on the 40 GB card: water
1.53M atoms (stable student), SrTiO₃ 2.37M, salt 2.74M, n3tbu_v1 2.56M; water needs about 27 KB per atom, the
others 14 to 18 KB.
Students on the H200 (sm_90)¶
The compute capability 9.0 code is compiled from the same changes. In 0.0.4 the A100's launch settings and neighbour-list kernels apply on compute capability 8.0 only. On an H200 they are faster too, and the next release makes them the default on compute capability 9.0 (with programmatic dependent launch).
With 0.0.4 on an H100 or H200, set these variables to get the same:
export LOUP_LRSK_MLP4=1 LOUP_LRSK_HEADS_PER_SM=8,5.33 LOUP_H2ROW_BM=64 LOUP_NVE_BLK=64 LOUP_ILMLIP_PRE_SW16=0
export LOUP_NB_GROUPS=1 LOUP_NL_LANES=32 LOUP_NL_ONEPASS=1 LOUP_PDL=1
Timings come from the 0.0.4 wheel on an NVIDIA H200 141 GB (Modal), with the same students and benchmark: NVE at the real time step, sustained, nanoseconds per atom-step.
| System | Atoms (N) |
0.0.4 defaults | With the variables | Against the A100's sustained |
|---|---|---|---|---|
| SrTiO₃ | 5,000 | 26.3 | 22.0 | 0.60× |
| Molten Salt | 3,888 | 41.7 | 26.0 | 0.63× |
n3tbu_v1 |
4,320 | 34.5 | 26.5 | 0.64× |
| Water | 5,184 | 32.9 | 23.9 | 0.59× |
These bench-size cells fill less than one wave of the H200's 132 multiprocessors. Larger cells use it better: at
about 320,000 atoms (no rebuilds, a time step of 1e-4 fs) the step is 12.9 (SrTiO₃), 12.3 (salt), 13.7
(n3tbu_v1) and 13.8 (water) nanoseconds per atom-step with the variables, against 14.4 to 15.8 without them.
Beyond that the cost per atom stays flat: 12.7 ns for SrTiO₃ at 5,000,000 atoms (about 85 GB) and 13.6 ns for water
at 2.65M. The accuracy gate and the MD parity check pass with the variables. From about 40,000 atoms on, adding
LOUP_LRSK_MLP4=0 (the two-warp polarisation MLP) takes another 1.7-2.0% off the step on all four students; at
the bench sizes it costs 2.3-2.6%. The next release does this by itself on compute capability 9.0
(LOUP_LRSK_MLP2_MIN_N, default 40,000). The H100 has not been timed.
Built-in fast dispersion (Options B, C, and D)¶
Standard engine D3 (dispersion="d3bj") costs ~8.4 ms on 5,000 atoms (~35× a fast50 student step). Distilled arch=ilmlip bundles support three built-in GPU D3(BJ) options (--dispersion) that run on a dedicated side stream, use a C¹ force-shifted cutoff (exact zero energy and force at r_cut), and automatically refuse accidental double-counting if dispersion="d3bj" is passed on top:
| Option | CLI flag | Method | 5,000-at SrTiO₃ (ms/eval) |
GPU Parity vs float64 (dE / dF / dS) |
Best for |
|---|---|---|---|---|---|
| B (fixed C6 + tail) | --dispersion d3bj |
Force-shifted fixed-C6 D3(BJ) over student neighbour list + live-volume K/V tail |
1.104 (+0.130 ms vs 0.974 base) |
6.5e-9 / 8.8e-9 / 6.1e-11 |
Bulk periodic crystals, salts, liquids (65× faster than exact D3) |
| C (CN-dependent C6 + tail) | --dispersion d3bj-cn |
3-pass coordination-dependent C6 + exact CN chain-rule forces/virial + K/V tail |
1.385 (+0.411 ms) |
9.2e-9 / 8.9e-9 / 1.6e-10 |
Molecules / liquids needing exact local CN-dependent dispersion |
| D (explicit far pairs) | --dispersion d3bj-far --dispersion-rcut 10.0 |
On-device spatial cell-bin walk out to r_disp (9–12 Å) + optional tail beyond r_disp |
3.862 (r_disp = 9 Å) |
5.2e-9 / 2.1e-8 / 9.3e-10 |
Slabs, interfaces, adsorbates, and fibres/clusters in vacuum (use_tail=False) |
Set LOUP_ILMLIP_DISP=0 at runtime to toggle built-in dispersion off (zero overhead when off). On n3tbu_v1 (ωB97M-D3BJ, 120-epoch matched A/B retrain), subtracting built-in D3(BJ) during training reduced held-out test force RMSE from 62.17 meV/Å (baseline) to 57.23 meV/Å (Option B), 58.65 meV/Å (Option C, best energy 0.554 meV/at), and 58.53 meV/Å (Option D 10 Å).
Using the distilled student in LoupMD¶
import loupmd as lm
res = lm.md("cell.cif", model="./student_out/student.loup", temperature_K=300, steps=100_000, output="md_student")
print(res.summary)