Skip to content

perf(sampler): batched AR decoding + shape bucketing (~4x on the AR path)#3

Open
trvachov wants to merge 1 commit into
reasyn_v2from
trvachov/batched-ar-decode-tested
Open

perf(sampler): batched AR decoding + shape bucketing (~4x on the AR path)#3
trvachov wants to merge 1 commit into
reasyn_v2from
trvachov/batched-ar-decode-tested

Conversation

@trvachov

@trvachov trvachov commented Jul 18, 2026

Copy link
Copy Markdown

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.sample gains gather_idx to return per-row last-real-token logits for right-padded batches.
  • Sampler._forward_ar_batched / _predict_ar_batched batch the outer next-token draw and the inner building-block-SMILES loop (lane-masked), keeping the per-state RDKit/chemistry branching on CPU.
  • Shape bucketing: pad batch to a power-of-2 and sequence to a 64-multiple so cuBLAS/cuDNN reuse kernels across the search's constantly-varying shapes (~7.5× per-shape overhead otherwise).

Results

~4× end-to-end on the AR-heavy path (20-mol ZINC250k), with reconstruction-rate parity vs the per-state path.

Correctness

  • Numerically equivalent to per-row decoding: right-pad + gather-at-true-length + causal isolation. Validated over 100k randomized lane simulations + logit-equivalence tests.
  • BF16 defaults OFF (REASYN_BF16=0) so enabling batching does not change precision — REASYN_BATCHED_AR=0 vs 1 differs only by batching/RNG.
  • Deadline (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.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.

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.
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