Repository navigation
Compile potentials with their derivatives, and generative cleanups - #811
Merged
Merged
Conversation
The sampler's calculator now only runs the model: FieldCalculator (formerly JointCalculator) returns the raw outputs at time t. Each update reads its variable's head and converts it with the variable's parametrization into the field it steps on, and adds its own guidance to that field as it is. - dynamics/calculator: JointCalculator renamed FieldCalculator, without guidance; GenerativeCalculator and the Score/Noise/Velocity/X0/ PseudoForce calculators removed; guidance moved from the Calculator base onto ForceCalculator. - dynamics/sample/sampler: updates take no field key; head() reads variable.output_key, field() converts it (to_score for SDEUpdate, to_velocity for ODEUpdate, to_x0 for AncestralUpdate), guide() adds the weighted guidance. The sampler writes the stage time into the batch before each model call. ODEUpdate refuses a non-velocity head on a non-Gaussian interpolant at assembly. - dynamics/guidance: a term returns a tensor shaped like the field it is added to, for any variable; no position unit handling. guidance_terms() and weighted_sum() shared by ForceCalculator and the updates. - generative/parametrizations: ParametrizedModel removed. - dynamics/base, dynamics/__init__, differential_equations, docs/api: docstrings and API listing follow. - tests: ported to FieldCalculator and update guidance; new tests for the per-update conversion, guidance on every field and on a per-structure variable, and the shape check. docs_new/generation/generation.md §3.2 (guidance converted through the score) and new_variables.md §3.6 (guidance on the calculator, positions only) no longer match the code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ReverseODE was used nowhere: ODEUpdate steps along the velocity itself, its drift the velocity and no diffusion. What is left of the module is the SDE of a Gaussian schedule and its reversal, so it is now generative/sde.py. - generative/sde (was differential_equations): ReverseODE removed; module docstring covers SDE and ReverseSDE only. - generative/__init__, generative/parametrizations, dynamics/sample/sampler: import from schnetpack.generative.sde. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The generative package imports are sorted on v3 and use the renamed sde module from sh/v3. The new generative API page no longer lists ReverseODE and ParametrizedModel, which sh/v3 removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generative training goes through the Diffuse transform and an ordinary supervised loss per variable; the tensor-level MatchingLoss is gone. - generative: delete losses.py and its package import; the docstrings of noising, times and transforms no longer point to it - docs/api/generative.rst: drop MatchingLoss from the training section - tests: the toy training helper in tests/dynamics/test_sampling.py writes the weighted target regression out; the VE score weighting test moves to test_parametrizations.py; the MatchingLoss tests are removed docs_new/legacy/ still describes MatchingLoss. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compile_potential traces a model's forward together with the autograd.grad of its response modules (forces, stress) and compiles the graph with dynamic shapes, so training on forces needs one backward and inference runs without autograd. Off by default everywhere. - model.compile: CompiledPotential / compile_potential / compile_supported (torch >= 2.14); one graph per train/eval mode, postprocessing flag, input keys/dtypes/devices and sizes 0 or 1; no shared symbols for sizes that happen to be equal; pickles without its graphs - lightning.AtomisticTask and spktrain: compile (task.compile=True); eager with a teacher and on older torch, with a warning - spkpredict: compile=True - calculators: compile_model on the spkmd SchNetPackCalculator (config calculator.compile_model) and the ASE SpkCalculator, compile on dynamics.Calculator - Coulomb, Ewald, ZBL: count molecules from n_atoms instead of int(idx_m[-1]) + 1 (a GPU sync and a data-dependent size) - docs: model API page, configs and MD user guide - tests: compiled vs eager in float64 for SchNet, PaiNN and SO3net, stress on periodic cells, one-molecule batches, the task's training step and pickling, the three calculators; every test that compiles is marked slow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ntial CompiledPotential now raises a TypeError for a model that is not an AtomisticModel and a RuntimeError on torch < 2.14, instead of warning and compiling anyway. The call sites no longer check on their own, and compile_potential, which only constructed the class, is gone. - model.compile: both checks in CompiledPotential.__init__; remove compile_potential - AtomisticTask, spkpredict: no version fallback; compile=True on older torch raises. Distillation still runs uncompiled with a warning - calculators (spkmd, ASE, dynamics): construct CompiledPotential; the dynamics calculator drops its own type check - docs: model API page and configs guide - tests: one fast test per check; the compiling tests use the class Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Compiled potentials with their derivatives, plus generative cleanups from sh/v3.
Compile (opt-in everywhere).
torch.compilealone cannot train on forces (the force loss needs the gradient of the forces).CompiledPotentialrecords the forward together with the response modules'autograd.gradinto one graph, then compiles it:AtomisticTask/spktraintask.compile=True(distillation runs uncompiled, with a warning)spkpredictcompile=TrueSchNetPackCalculatorcalculator.compile_model=TrueSpkCalculatorcompile_model=Truespk.dynamics.Calculatorcompile=TrueCoulomb, Ewald and ZBL count molecules from
n_atomsinstead ofint(idx_m[-1]) + 1(a GPU sync and a data-dependent size).Generative.
e8855064: the sampler's calculator only runs the model (JointCalculatorrenamedFieldCalculator); updates convert their head and add guidance.GenerativeCalculator, the Score/Noise/Velocity/X0/PseudoForce calculators andParametrizedModelare removed.05903841:ReverseODEremoved,differential_equationsrenamedsde.688e6cb2:MatchingLossremoved; training goes throughDiffuse.040aca4f): the newdocs/api/generative.rstdrops the removed names.Evidence
tests/atomistic/test_compile.py(float64, defaultassert_close), all markedslow. These checks passed on 2026-10-26 (laptop GPU, torch 2.14.1); they have not been rerun since the last commit (2f2a1033):AtomisticTask.training_stepgradients equal eager; the task pickles.2f2a1033: 788 passed, 0 failed, 13 skipped (12 need mace-torch, 1 by design).spktrain experiment=md17, synthetic 80-molecule db, 3 epochs: Before (eager) val_loss 190646 / 161211 / 152163, test_forces_mae 332.089; After (task.compile=True) identical to 6 digits.spkpredictcompiled vs eager: max relative difference 2e-8 for energy and 3e-7 for forces (float32).Merge Danger
Door: two-way
Compile is off by default, and the code paths are unchanged unless an option is set.
Blast Radius: generative API
Code that uses the removed generative classes breaks:
MatchingLoss,ReverseODE,ParametrizedModel,GenerativeCalculator,JointCalculatorand the per-field score calculators. The new compile options need torch ≥ 2.14 when switched on; the package floor stays at torch 2.5.🤖 Generated with Claude Code