Repository navigation
Speed up SNP scoring: vectorize dna_1hot, keep the CUDA cache between clusters - #5
Draft
chansoo-calico wants to merge 1 commit into
Draft
chansoo-calico wants to merge 1 commit into
chansoo-calico wants to merge 1 commit into
Conversation
dna_1hot encoded each base in a Python loop, about 200 ms per 524 kb window. hound_snp runs it in a prefetch thread, where it holds the GIL while the eager model launches kernels. A lookup table takes about 10 ms and gives the same output, including trimming, padding, n_uniform and n_sample's random draws. score_snps and score_gene_snps emptied the CUDA cache after every cluster, so each cluster allocated its memory again. The caching allocator already frees unused cached blocks and retries before it reports out of memory. Scores are bit-identical. Borzoi human on one A100: 1.02 to 1.22 SNPs/s in float32, and 2.81 to 4.5 with -m float16 --compile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
Profiling
hound_snpon Borzoi human (one A100,--rc --shifts 0) turned up two costs around the model. They grow as the model gets faster: with-m float16 --compile, they took about 40% of each SNP.What
dna_1hotuses a lookup table instead of a per-base Python loop: 200 ms down to 9 ms per 524 kb window. The loop runs inscore_snps' prefetch thread and holds the GIL while the eager model launches kernels. The output is identical, including trimming, padding,n_uniform, andn_sample'srandomdraws (same calls, same order).score_snpsandscore_gene_snpsno longer empty the CUDA cache after every cluster. Each cluster had to allocate its memory again. On an allocation failure, the caching allocator already frees unused cached blocks and retries before raising out of memory.Results
Trained Borzoi human fold 0 (
releases/borzoi/download.sh), 200 random hg38 chr21 SNPs, A100 40GB, steady-state SNPs/s:-m float16 --compilescore_gene_snpsgets the same change but wasn't timed.Related:
--mix_dtypeprecision on trained weightsThis is the kind of validation the new warning asks for. Same SNPs, measured against strict fp32 (TF32 off); the median |logSUM| is 0.10:
--compile+ this PR-m float16 --compile+ this PR-m bfloat16 --compile+ this PRbf16 noise exceeds a typical SNP effect, so the warning is right about it. fp16 may be acceptable, but that's your call. Two more notes:
--compilecosts about 60 s of warm-up per process. On 200-SNP slices, that cancelled the float32 gain. It pays off from roughly 1,000–2,000 SNPs per job, or with a persistentTORCHINDUCTOR_CACHE_DIR.Test plan
pytest -m "not slow": 472 passed, 7 skipped (with bedtools installed, as in CI).test_dna.pytests comparedna_1hotwith the original loop across trim, pad,n_uniformandn_sample(seeded).ruff format --check .: clean.hound_snpon an A100, 200 SNPs:scores.h5matches main bit for bit (logSUM,logD2and their quantiles), for float32 and for-m float16 --compile.🤖 Generated with Claude Code