perf(sampler): batched AR decoding + shape bucketing (~4x on the AR path)#3
Open
trvachov wants to merge 1 commit into
Open
perf(sampler): batched AR decoding + shape bucketing (~4x on the AR path)#3trvachov wants to merge 1 commit into
trvachov wants to merge 1 commit into
Conversation
Batch autoregressive decoding across active states with right-padded shape buckets and gather-at-true-length logits. Include the review fixes: check deadlines before batch and lock work, default REASYN_BF16 off, use CPU integer-list bookkeeping to reduce device transfers, and add 13 pytest-collected production-helper tests gated on probability total variation and reaction ranking. Reviewed-and-tested: A100 GPU pytest plus five-molecule FP32 A/B sampling.
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
Batches the autoregressive decoder forward across all active search states in one call, instead of one state at a time. The 166M AR decoder was running at batch=1 (~40× under the GPU's compute floor).
ReaSyn.samplegainsgather_idxto return per-row last-real-token logits for right-padded batches.Sampler._forward_ar_batched/_predict_ar_batchedbatch the outer next-token draw and the inner building-block-SMILES loop (lane-masked), keeping the per-state RDKit/chemistry branching on CPU.Results
~4× end-to-end on the AR-heavy path (20-mol ZINC250k), with reconstruction-rate parity vs the per-state path.
Correctness
REASYN_BF16=0) so enabling batching does not change precision —REASYN_BATCHED_AR=0vs1differs only by batching/RNG.time_limit) is checked before the batch and lock acquisition.Tests
tests/test_batched_ar.py— 13 pytest-collected tests on the shipped helpers, gated on probability total-variation and reaction top-K ordering (not argmax). 13 passed on A100.Toggles
REASYN_BATCHED_AR(default on;=0= original per-state path),REASYN_BF16(default off),REASYN_BUCKET(default on).Independently reviewed and fixed (deadline ordering, BF16 default, collected tests) before opening.
Testing environment⚠️
All test/benchmark results above were produced on the review container: Python 3.12 / PyTorch 2.11 / CUDA 13.2 — not 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.