Skip to content

fix(neighbors): harden selective cluster-tile state - #141

Open
zubatyuk wants to merge 4 commits into
NVIDIA:mainfrom
zubatyuk:fix/cluster-tile-selective-state
Open

fix(neighbors): harden selective cluster-tile state#141
zubatyuk wants to merge 4 commits into
NVIDIA:mainfrom
zubatyuk:fix/cluster-tile-selective-state

Conversation

@zubatyuk

Copy link
Copy Markdown
Collaborator

ALCHEMI Toolkit-Ops Pull Request

Description

Harden selective cluster-tile neighbor-list state handling across PyTorch and JAX, including fixed-capacity COO validation, empty-system semantics, and compiled single-system reuse.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement
  • Documentation update
  • Refactoring (no functional changes)
  • CI/CD or infrastructure change

Related Issues

None.

Changes Made

  • Validate PyTorch segmented COO topology, offsets, counts, and tile-state capacities before Warp launches.
  • Support caller-owned selective tile state and fullgraph single-system COO steady-state reuse.
  • Preserve JAX false-flag empty selective state and clear only true-flag active counts.

Testing

  • Unit tests pass locally (make pytest)
  • Linting passes (make lint)
  • New tests added for new functionality meets coverage expectations?

Checklist

  • I have read and understand the Contributing Guidelines
  • I have updated the CHANGELOG.md
  • I have performed a self-review of my code
  • I have added docstrings to new functions/classes
  • I have updated the documentation (if applicable)

Additional Notes

None.

Tip

This repository uses Greptile, an AI code review service, to help conduct
pull request reviews. We encourage contributors to read and consider suggestions
made by Greptile, but note that human maintainers will provide the necessary
reviews for merging: Greptile's comments are not a qualitative judgement
of your code, nor is it an indication that the PR will be accepted/rejected.
We encourage the use of emoji reactions to Greptile comments, depending on
their usefulness and accuracy.

zubatyuk added 2 commits July 29, 2026 22:26
Dispatch the existing wrapped PBC kernels after position wrapping for normal and selective rebuilds. Add parity coverage against single-cutoff results for both dtypes and wrap modes.

Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
Validate fixed-capacity COO state before launches, preserve JAX empty selective state, and support fullgraph single-system COO reuse.

Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Comment thread nvalchemiops/torch/neighbors/_dispatch.py
Comment thread nvalchemiops/torch/neighbors/neighbor_utils.py
@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR hardens selective cluster-tile state handling across PyTorch, JAX, and Warp.

  • Adds caller-owned PyTorch tile-state returns and fixed-capacity selective COO reuse.
  • Adds segmented COO metadata checks and physical write bounds.
  • Preserves or clears JAX empty-system state according to rebuild flags.
  • Fixes the wrapped-PBC JAX naive dual-cutoff fill path and expands documentation and tests.

Important Files Changed

Filename Overview
nvalchemiops/torch/neighbors/_dispatch.py Changes compiled cluster-tile PBC handling, but the runtime guard remains bypassed for false PBC entries.
nvalchemiops/torch/neighbors/neighbor_utils.py Adds comprehensive eager segmented-COO validation while compiled execution still omits metadata value checks.
nvalchemiops/neighbors/cluster_tile/kernels.py Bounds COO writes by physical storage, but count updates can still exceed or survive invalid segments.
nvalchemiops/torch/neighbors/cluster_tile.py Adds single-system selective COO reuse and state returns, with compiled correctness still dependent on caller-maintained metadata.
nvalchemiops/torch/neighbors/batch_cluster_tile.py Adds eager validation and caller-owned state support for batched selective cluster-tile output.
nvalchemiops/jax/neighbors/cluster_tile.py Preserves false-flag empty selective state and clears active counts for true flags.
nvalchemiops/jax/neighbors/batch_cluster_tile.py Applies rebuild flags consistently to empty batched pair and tile counts.
nvalchemiops/jax/neighbors/naive_dual_cutoff.py Restores the omitted periodic fill launch after wrapping positions.

Reviews (2): Last reviewed commit: "update changelog." | Re-trigger Greptile

zubatyuk added 2 commits July 30, 2026 18:48
Prevent malformed segmented COO metadata from writing past physical output capacity. Document the compiled cluster-tile requirement for eagerly validated, fully periodic PBC.

Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>
Signed-off-by: Roman Zubatyuk <rzubatiuk@nvidia.com>

@laserkelvin laserkelvin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several correctness and state-lifecycle issues remain; details are inline. F1 already had an existing inline thread, so I did not duplicate it.


if (
rebuild_flags is not None
and format == "coo"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: This prior-state guard only covers COO. A matrix call with any false flag can allocate fresh outputs and tile state, then skip that system, so there is no previous topology to preserve. I assume False preserves the prior result for every supported format; please require the matrix triples (including dual-cutoff outputs) and tile state before launch when any flag is false.

"neighbor_list_shifts": neighbor_list_shifts,
"pair_offsets": pair_offsets,
"pair_counts": pair_counts,
"rebuild_flags": rebuild_flags,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Valid nonselective segmented COO reaches this helper with rebuild_flags=None; adding it to tensors makes the loop below dereference None.device and raise AttributeError. I assume pair_offsets/pair_counts may select segmented mode without selective rebuilding. Please make rebuild_flags optional here and validate it only when present.

internally without replacing those state buffers.

Use two phases for PyTorch selective COO. First make an eager bootstrap call with
every flag true; it may allocate omitted topology and tile buffers and returns the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: This bootstrap path is not currently implementable: cluster_tile_neighbor_list requires every topology and tile buffer whenever rebuild_flags is set, even when all flags are true. I assume the first all-true call should allocate and return reusable state as documented. Please implement that path or replace this paragraph with complete explicit allocation/bootstrap steps.

return (
if (
selective
and not torch.compiler.is_compiling()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Excluding compiled calls from this fast return means a false fullgraph step still performs wrapping, Morton coding, argsort, gathers, and the query launch. I assume selective reuse should make an unchanged single system a no-op. Please gate preprocessing/query with a compiled conditional or flag-aware operation, and add a diagnostic or benchmark for the false path.

or neighbor_list_shifts is None
):
raise ValueError("selective COO requires fixed topology buffers")
max_pairs_from_buffers = _validate_segmented_coo_state(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This eager validation is repeated inside query_cluster_tile_coo, so a high-level call copies the same offsets and counts to CPU twice and serializes GPU work twice. I assume direct low-level callers still need validation, while the convenience path should pay for it once. Please split tile/pair validation or dispatch through an already-validated internal query path.

per_atom_cell_offsets,
launch_dims=(total_atoms,),
)
if rebuild_flags is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This new wrapped-PBC selective branch has no matching regression test: the PBC tests omit rebuild_flags, while the selective tests omit PBC. I assume False preserves both cutoffs and shifts, and True matches a fresh nonselective rebuild. Please add both flag cases against those references.

Explicit cluster-tile methods append their documented tile-state suffix
when ``return_state=True``.

Single-system selective COO calls to explicit ``method="cluster_tile"``

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This documents only the single-system selective exception. The batched route returns four topology tensors plus six state tensors, and the JAX matrix docstrings also omit their selective state suffixes. I assume the primary API docs should make tuple arity and ordering explicit; please add those missing return forms here and in the JAX Returns sections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants