Skip to content

Commit 3af4400

Browse files
committed
perf(inference): freeze all prepared model parameters
1 parent a2dca93 commit 3af4400

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

CLAUDE.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ configs/ # Hydra YAML configs (datasets, tasks, backbone, optimi
247247
- Tests that download registered checkpoints must declare their models with a
248248
`pretrained` marker. This lets base CI deselect them with `--exclude-models`
249249
and routes them to the matching model-sweep job.
250-
- Only freeze inference parameters for the `umas_fast_gpu` backend, after its
251-
module replacement. On the H100 perf check, freezing the general backend cut
252-
1000-atom QPS by about 50% with activation checkpointing either enabled or
253-
disabled. The fast backend retained its throughput while saving 11-13% peak
254-
memory. Its custom backward must preserve input derivatives independently of
255-
parameter gradients.
250+
- Freeze inference parameters after inference-specific module replacement.
251+
Main's folded-batch linear path removes the former general-backend regression:
252+
on one H100, freezing improved compiled general inference by 15-17% and cut
253+
peak allocated memory by 27-29% at 100-2,000 atoms. PyTorch 2.13 CPU checks
254+
improved by 4% at 32 atoms and were neutral at 1,000 atoms. Custom backward
255+
paths must preserve input derivatives independently of parameter gradients.
256256
- `umas_fast_gpu` custom backward operators do not implement `vmap` batching.
257257
Compute Hessians through the per-component loop (`hessian_vmap=False`) when
258258
exercising that backend, and ensure inference settings forward that option

src/fairchem/core/units/mlip_unit/predict.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
)
3838
from fairchem.core.components.batch_server import get_app_handle_with_retry
3939
from fairchem.core.datasets.atomic_data import AtomicData, warn_if_upcasting
40-
from fairchem.core.models.uma.nn.execution_backends import (
41-
ExecutionMode,
42-
maybe_update_settings_backend,
43-
)
40+
from fairchem.core.models.uma.nn.execution_backends import maybe_update_settings_backend
4441
from fairchem.core.units.mlip_unit import InferenceSettings
4542
from fairchem.core.units.mlip_unit.mlip_unit import OutputSpec, Task
4643
from fairchem.core.units.mlip_unit.single_atom_patch import (
@@ -462,9 +459,8 @@ def _lazy_init(self, data: AtomicData) -> None:
462459
"""
463460
# Model handles its own preparation (MOLE merge, eval mode, etc.)
464461
self.model.module.prepare_for_inference(data, self.inference_settings)
465-
if self.inference_settings.execution_mode == ExecutionMode.UMAS_FAST_GPU:
466-
# The fast backward only differentiates positions and cells.
467-
self.model.requires_grad_(False)
462+
# Inference differentiates outputs with respect to inputs, not weights.
463+
self.model.requires_grad_(False)
468464

469465
self.model.to(self.inference_settings.base_precision_dtype)
470466

tests/core/units/mlip_unit/test_predict.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,9 @@ def _test_untrained_hessian(checkpoint_path, device):
17961796
# Get predictions
17971797
preds = predictor.predict(batch)
17981798

1799-
assert any(parameter.requires_grad for parameter in predictor.model.parameters())
1799+
assert all(
1800+
not parameter.requires_grad for parameter in predictor.model.parameters()
1801+
)
18001802

18011803
# Verify energy, forces, and hessian are present
18021804
assert "energy" in preds, "Energy prediction missing"
@@ -1819,22 +1821,25 @@ def _test_untrained_hessian(checkpoint_path, device):
18191821

18201822

18211823
@pytest.mark.gpu()
1822-
def test_fast_gpu_frozen_parameters_preserve_input_derivatives(
1823-
conserving_mole_checkpoint, monkeypatch
1824+
@pytest.mark.parametrize("execution_mode", ["general", "umas_fast_gpu"])
1825+
def test_frozen_parameters_preserve_input_derivatives(
1826+
conserving_mole_checkpoint, monkeypatch, execution_mode
18241827
):
18251828
_test_frozen_parameters_preserve_input_derivatives(
1826-
conserving_mole_checkpoint[0], monkeypatch
1829+
conserving_mole_checkpoint[0], monkeypatch, execution_mode
18271830
)
18281831

18291832

1830-
def _test_frozen_parameters_preserve_input_derivatives(checkpoint_path, monkeypatch):
1833+
def _test_frozen_parameters_preserve_input_derivatives(
1834+
checkpoint_path, monkeypatch, execution_mode
1835+
):
18311836
settings = InferenceSettings(
18321837
predict_untrained_forces={"omol"},
18331838
predict_untrained_stress={"omol"},
18341839
predict_untrained_hessian={"omol"},
18351840
activation_checkpointing=False,
18361841
merge_mole=True,
1837-
execution_mode="umas_fast_gpu",
1842+
execution_mode=execution_mode,
18381843
hessian_vmap=False,
18391844
)
18401845

0 commit comments

Comments
 (0)