Skip to content

perf(fpindex): GPU fingerprint queries + RapidFuzz edit-distance#2

Open
trvachov wants to merge 1 commit into
reasyn_v2from
trvachov/fpindex-gpu-rapidfuzz-tested
Open

perf(fpindex): GPU fingerprint queries + RapidFuzz edit-distance#2
trvachov wants to merge 1 commit into
reasyn_v2from
trvachov/fpindex-gpu-rapidfuzz-tested

Conversation

@trvachov

@trvachov trvachov commented Jul 18, 2026

Copy link
Copy Markdown

Summary

Accelerates the building-block fingerprint lookup in get_reactants — the single largest cost in ReaSyn inference (~60% of wall time in profiling).

Two changes to FingerprintIndex.query_cuda:

  1. Run the fingerprint cdist on the model's GPU. The query fingerprint arrives as a CPU tensor, so despite the query_cuda name the distance search was executing on the CPU over the 211k×2048 matrix (~53 ms/query). Routed to the model's assigned cuda:<id>~53 → 1.4 ms.
  2. RapidFuzz for the invalid-SMILES fallback. Invalid generated SMILES fall back to Levenshtein matching over all 211k building-block strings, previously a Python editdistance loop (~335–460 ms/call — the true dominant cost). Replaced with rapidfuzz.process.cdist (batched C++/SIMD) → ~9–15×, identical distances.

Correctness / safety

  • Results preserved exactly. GPU cdist distances are bit-identical to CPU; to also preserve the selected indices at tied distances, the distance vector is copied back to CPU for topk (GPU/CPU topk break ties differently). RapidFuzz distances are identical to editdistance.
  • Multi-GPU safe. Query is routed to the model's explicit cuda:<gpu_id> (not the process-default GPU 0); fp_cuda cache key canonicalized.
  • RapidFuzz pinned in both pyproject.toml and env.yml; workers=1.

Tests

tests/test_fpindex.py — GPU/CPU parity (incl. the real 211k index), device routing, cache behavior, fallback paths, RapidFuzz↔editdistance identity. 9 passed on A100.

Toggles

REASYN_GPU_QUERY (default on), REASYN_RAPIDFUZZ (default on); set =0 to restore legacy behavior.

Independently reviewed and fixed (multi-GPU device routing, topk tie identity, manifest pinning) before opening.

Testing environment ⚠️

All test/benchmark results above were produced on the review container: Python 3.12 / PyTorch 2.11 / CUDA 13.2not the repo-pinned stack (Python 3.10 / PyTorch 2.7 / CUDA 11.8 per env.yml / pyproject.toml). Kernel selection, SDPA backends, and tie-breaking are version-sensitive, so these results should be re-confirmed on the pinned stack / CI before merge.

Run fingerprint cdist on the model-assigned GPU and accelerate invalid-SMILES Levenshtein lookup with RapidFuzz.

Thread explicit multi-GPU device routing, canonicalize CUDA cache keys, restore legacy CPU topk tie identity, pin RapidFuzz in both manifests, and use workers=1. Add tests/test_fpindex.py for GPU/CPU parity, device routing, cache behavior, fallback paths, and the real index.

Reviewed-and-tested: adversarially verified on the 211k fingerprint index with an A100, on CPU-only paths, and against both model checkpoints.
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