Skip to content

Pool crystals with scatter_reduce over a flat crystal index - #164

Open
jcwang587 wants to merge 1 commit into
perf/data-fast-graphfrom
perf/scatter-pooling
Open

Pool crystals with scatter_reduce over a flat crystal index#164
jcwang587 wants to merge 1 commit into
perf/data-fast-graphfrom
perf/scatter-pooling

Conversation

@jcwang587

Copy link
Copy Markdown
Owner

Summary

  • collate_pool now emits crystal_atom_idx as a single (N,) LongTensor mapping each atom to its crystal, replacing the list of per-crystal index tensors.
  • CrystalGraphConvNet.pooling aggregates with one scatter_reduce_(reduce="mean") call instead of a Python loop over crystals (previously one kernel launch per crystal - 256 per batch at the default batch size). This also removes the main obstacle to torch.compile.
  • Call sites (cgcnn_test, cgcnn_descriptor, both training loops) move the index to the device with a single copy instead of one transfer per crystal.

Breaking change

The model forward interface changes for code that builds batches manually; anything using collate_pool with a DataLoader (the documented pattern) is unaffected.

Verification

  • Pooled features match the previous loop implementation to 1e-6; end-to-end cgcnn-tr smoke run passes.

Part 2/4, stacked on #163 (perf/data-fast-graph).

🤖 Generated with Claude Code

collate_pool now emits crystal_atom_idx as a single (N,) LongTensor
mapping each atom to its crystal, and CrystalGraphConvNet.pooling
aggregates with one scatter_reduce_(reduce="mean") call instead of a
Python loop over crystals (one kernel launch per crystal, 256 per batch
at the default batch size). Call sites move the index to the device
with a single copy instead of one transfer per crystal.

This is a breaking change to the model's forward interface for code
that builds batches manually; code using collate_pool with a DataLoader
is unaffected. Pooled features match the previous implementation to
1e-6.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: effbcc8d-15f1-4283-95fc-76073d5640a9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant