4949from deepmd .pt .train .wrapper import (
5050 ModelWrapper ,
5151)
52+ from deepmd .pt .utils .compile_compat import (
53+ build_inductor_compile_options ,
54+ )
5255from deepmd .pt .utils .env import (
5356 DEVICE ,
5457)
@@ -219,6 +222,7 @@ def _collect_metadata(
219222 model : torch .nn .Module ,
220223 output_keys : list [str ],
221224 is_spin : bool | None = None ,
225+ do_atomic_virial : bool = False ,
222226) -> dict :
223227 """Assemble the flat metadata dict expected by :class:`DeepPotPTExpt`.
224228
@@ -261,6 +265,8 @@ def _collect_metadata(
261265 "mixed_types" : bool (model .mixed_types ()),
262266 "has_message_passing" : _model_has_message_passing (model ),
263267 "has_comm_artifact" : False ,
268+ "do_atomic_virial" : bool (do_atomic_virial ),
269+ "nnei" : int (sum (model .get_sel ())),
264270 "has_default_fparam" : bool (model .has_default_fparam ()),
265271 "default_fparam" : _to_py_list (model .get_default_fparam ()),
266272 "default_chg_spin" : _to_py_list (model .get_default_chg_spin ()),
@@ -468,6 +474,7 @@ def freeze_sezm_to_pt2(
468474 * ,
469475 device : torch .device | None = None ,
470476 head : str | None = None ,
477+ atomic_virial : bool = False ,
471478) -> None :
472479 """Freeze a SeZM checkpoint into an AOTInductor ``.pt2`` archive.
473480
@@ -484,6 +491,9 @@ def freeze_sezm_to_pt2(
484491 Model head to export from a multi-task checkpoint. If omitted, the
485492 ``Default`` head is used when present; otherwise multi-task checkpoints
486493 must pass an explicit head. Single-task checkpoints must pass ``None``.
494+ atomic_virial
495+ Whether to include per-atom virial outputs in the exported graph.
496+ Disable this for fastest LAMMPS force/energy/total-virial inference.
487497 """
488498 from torch ._inductor import (
489499 aoti_compile_and_package ,
@@ -515,9 +525,6 @@ def freeze_sezm_to_pt2(
515525 has_spin = is_spin ,
516526 )
517527
518- # do_atomic_virial=True pulls every key that DeepPotPTExpt may read
519- # (energy, energy_redu, energy_derv_r, energy_derv_c, energy_derv_c_redu)
520- # into the traced graph.
521528 if is_spin :
522529 (
523530 ext_coord ,
@@ -538,7 +545,7 @@ def freeze_sezm_to_pt2(
538545 fparam = fparam ,
539546 aparam = aparam ,
540547 charge_spin = charge_spin ,
541- do_atomic_virial = True ,
548+ do_atomic_virial = atomic_virial ,
542549 )
543550 else :
544551 (
@@ -558,7 +565,7 @@ def freeze_sezm_to_pt2(
558565 fparam = fparam ,
559566 aparam = aparam ,
560567 charge_spin = charge_spin ,
561- do_atomic_virial = True ,
568+ do_atomic_virial = atomic_virial ,
562569 )
563570
564571 # Output key order is taken from a concrete run; Python dict order
@@ -588,14 +595,19 @@ def freeze_sezm_to_pt2(
588595 exported = move_to_device_pass (exported , target_device )
589596
590597 out_path_str = str (out_path )
591- # Match the runtime eval compile path's Inductor option: triton.max_tiles=1
592- # keeps pointwise grids 1D so the data-dependent compact-edge axis stays on
593- # Triton's x grid (limit 2**31); the default tiling places it on the y/z
594- # grid (limit 65535), which overflows for large systems .
595- with inductor_config .patch ({"triton.max_tiles" : 1 }):
598+ compile_options = build_inductor_compile_options ()
599+ # Keep AOTInductor aligned with the eval compile path. ``triton.max_tiles=1``
600+ # keeps data-dependent edge axes on Triton's x grid, whose bound is large
601+ # enough for production-scale neighbor lists .
602+ with inductor_config .patch ({** compile_options , "triton.max_tiles" : 1 }):
596603 aoti_compile_and_package (exported , package_path = out_path_str )
597604
598- metadata = _collect_metadata (model , output_keys = output_keys , is_spin = is_spin )
605+ metadata = _collect_metadata (
606+ model ,
607+ output_keys = output_keys ,
608+ is_spin = is_spin ,
609+ do_atomic_virial = atomic_virial ,
610+ )
599611 with zipfile .ZipFile (out_path_str , "a" ) as zf :
600612 zf .writestr ("model/extra/metadata.json" , json .dumps (metadata ))
601613 # The raw training params are preserved so `dp change-bias` and
0 commit comments