Repository navigation
perf(drug_discovery): build molecular graphs on the host with NumPy - #44
Merged
Merged
Conversation
smiles_to_graph built each graph from RDKit with eager JAX ops: one jnp.array per atom, then four .at[].set scatters per bond, each copying the whole adjacency or edge-feature array. A BBBP molecule cost about 105 device dispatches. The graph is host data, so it is now assembled with NumPy and converted once per array; batch_smiles_to_graphs pads in NumPy the same way. The arrays are bit-identical to before for all 1,640 BBBP molecules, and get_atom_features and get_bond_features keep their signatures. The batch arrays are now float32 under JAX's x64 mode too, as the single graph's already were, and an empty batch or a SMILES string with no atoms is refused by name instead of failing inside stack or max. Measured on one CPU process, alternating runs: the MolNet quick benchmark fixture takes 13.0 s and 13.4 s against main's 59.3 s and 60.8 s.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
smiles_to_graphbuilt every graph with eager JAX ops on host data: about 105 device dispatches per BBBP molecule, each bond's scatter copying the whole adjacency or edge-feature array. The graph is now assembled with NumPy and converted once per array.get_atom_featuresandget_bond_featureskeep their signatures and share the host-side feature lists with the graph builders.Evidence
Same output. Over all 1,640 BBBP SMILES, the NumPy path gives the same dtype, shape, values and
num_nodesas the shipped code for the 1,629 valid molecules, and rejects the same 11.Tests.
tests/operators/drug_discovery/test_molecular_graphs.py, written first:max(), and an atomless SMILES failed insidejnp.stack.The guard tests passed before and after the change. The 113 drug-discovery tests (
tests/operators/drug_discovery,tests/operators/test_drug_discovery.py) and the MolNet and DTI benchmark tests (15) pass, andpre-commit run --all-filespasses all 24 hooks.Speed.
MolNetBenchmark(quick=True).run(), the fixture that sets the CI benchmarks shard's floor, timed in one fresh CPU process per run, alternating main and this branch: main 59.3 s and 60.8 s, this branch 13.0 s and 13.4 s. In CI's last two benchmark-shard runs that fixture took 110.1 s and 249.2 s.Merge Danger
Door: two-way.
Blast Radius: drug-discovery graph inputs.
The graphs are unchanged for every molecule checked. The behaviour changes are: a batch under x64 is float32 instead of float64 (DiffBio's tests run without x64), and an empty batch or an atomless SMILES raises a
ValueErrornaming its cause instead of one frommax()orjnp.stack. No repository outside DiffBio calls these functions (all 3,916 workspace repositories checked).