-
Notifications
You must be signed in to change notification settings - Fork 640
feat(pt_expt): call-time DeepEval auto ladder with nf==1 vesin gate #5903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,83 @@ | |
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def resolve_auto_graph_builder( | ||
| device: torch.device | str, | ||
| nf: int = 1, | ||
| ) -> str: | ||
| """Resolve ``neighbor_graph_method="auto"`` to a concrete inference builder. | ||
|
Shaurya2k06 marked this conversation as resolved.
|
||
|
|
||
| Single owner of the inference / DeepEval auto ladder. Training uses | ||
| :func:`resolve_neighbor_graph_method`, which never selects ``vesin``. | ||
|
|
||
| Mirrors :func:`deepmd.pt.model.model.sezm_model._select_neighbor_builder`: | ||
| ``vesin`` is eligible only for a single-frame batch (``nf == 1``), because | ||
| its API loops frames in Python (~1 ms/frame). Multi-frame batches stay on | ||
| ``nv`` (CUDA) or ``dense`` so ``auto_batch_size`` / ``dp test`` do not | ||
| regress to the per-frame loop. | ||
|
|
||
| Policy | ||
| ------ | ||
| * CUDA + ``nvalchemiops``: ``nv`` (any ``nf``). | ||
| * ``nf == 1`` + ``vesin.torch``: ``vesin``. | ||
| * otherwise: ``dense``. | ||
|
|
||
| ``ase`` is never chosen automatically. All builders emit the same carry-all | ||
| neighbor set; the choice is performance-only. Builders run eagerly outside | ||
| traced / compiled regions, so this does not change ``.pt2`` artifacts. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| device : torch.device or str | ||
| Device the coordinates live on (or will be moved to). Controls whether | ||
| the CUDA-only ``nv`` builder is eligible. | ||
| nf : int, default: 1 | ||
| Number of frames in the batch. ``vesin`` is selected only when | ||
| ``nf == 1`` and ``vesin.torch`` is importable. | ||
|
|
||
| Returns | ||
| ------- | ||
| str | ||
| One of ``"nv"``, ``"vesin"``, or ``"dense"``. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If ``nf`` is not a positive ``int`` (``bool`` is rejected). | ||
| """ | ||
| from deepmd.pt.utils.nv_nlist import ( | ||
| is_nv_available, | ||
| ) | ||
| from deepmd.pt_expt.utils.vesin_neighbor_list import ( | ||
| is_vesin_torch_available, | ||
| ) | ||
|
|
||
| # ``bool`` is a subclass of ``int``; reject it explicitly. | ||
| if type(nf) is not int: | ||
| raise ValueError(f"nf must be a positive int, got {nf!r}") | ||
| if nf < 1: | ||
| raise ValueError(f"nf must be >= 1, got {nf}") | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| dev = torch.device(device) | ||
| if dev.type == "cuda" and is_nv_available(): | ||
| return "nv" | ||
| if nf == 1 and is_vesin_torch_available(): | ||
| return "vesin" | ||
| if dev.type == "cuda" and not is_nv_available(): | ||
| log.warning( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This warning now fires once per batch instead of once per Moving resolution to call time is right, but it also moved this log line onto the per-batch path. The message is also the more useful of the two things happening here, so burying it in repetition is a real loss: the point is "install nvalchemi-toolkit-ops", which is a one-time action, not a per-batch one. A module-level warn-once flag is the smallest fix: _warned_no_nv = False
...
if dev.type == "cuda" and not nv:
global _warned_no_nv
if not _warned_no_nv:
_warned_no_nv = True
log.warning(...)Caching the whole resolver per None of this affects results -- all builders emit the same carry-all neighbor set -- so it is not a correctness concern, just something that belongs with this change rather than after it. |
||
| "nvalchemi-toolkit-ops is unavailable; falling back from " | ||
| "neighbor_graph_method='auto' to the dense graph builder" | ||
| + ( | ||
| "" | ||
| if nf == 1 | ||
| else " (vesin is not used for nf>1; its API loops frames in Python)" | ||
| ) | ||
| + ". Install it with `pip install nvalchemi-toolkit-ops` to enable " | ||
| "the NV graph builder." | ||
| ) | ||
| return "dense" | ||
|
|
||
|
|
||
| def resolve_neighbor_graph_method( | ||
| requested: str, | ||
| device: torch.device, | ||
|
|
@@ -36,6 +113,8 @@ def resolve_neighbor_graph_method( | |
| ------- | ||
| str | ||
| The concrete builder name, either ``"dense"`` or ``"nv"``. | ||
| Training auto never selects ``vesin`` (per-frame Python loop); use | ||
| :func:`resolve_auto_graph_builder` for inference auto selection. | ||
|
|
||
| Raises | ||
| ------ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.