tangermeme's PackedSequence: 2-bit packing cuts genomics sequence memory 16x
Genomics deep learning library tangermeme has merged PR #120, adding a PackedSequence structure that stores DNA sequences over the four-character alphabet at 2 bits per position, cutting memory usage 16x versus int8 one-hot encoding. More importantly, the entire computation can run in "packed space" without first decoding back to one-hot, yielding large simultaneous gains in both performance and memory in practice. The change grew out of a real bottleneck author jmschreiber91 hit while accelerating DeepLIFT/SHAP attribution analysis, and has now landed as an official capability of the library.
Confirmed
- tangermeme adds PackedSequence: 2 bits per position storage, a 16x memory reduction versus int8 one-hot, motivated by memory and disk footprint issues (m6)
- Encoding scheme: instead of storing one-hot, it stores locus position indices, loads packed sequences directly from disk, and only decodes to one-hot per batch, compressing overall memory further (m1)
- The toolchain supports running replacement, shuffle, and other ersatz operations directly on packed sequences rather than decoding first (m4)
- With computation entirely in packed space, 20x dinucleotide shuffles across 10,000 windows dropped from 7.86s to 0.85s and memory from 8.7GB to 0.7GB (m5); another measured scenario saw memory fall from 3.8GB to 755MB (m4)
- While accelerating DeepLIFT/SHAP, the author hit a bottleneck: shuffling sequences one by one was too slow, while shuffling all 100k sequences with 20x shuffles each at once caused memory blowups — hence moving to computation directly on packed sequences (m2)
- The author notes the same packing idea applies to board game position representations: uint8 instead of 32-bit integers saves 4x, and packing 4 adjacent squares (2 bits each for piece types 0-3) into a single uint8 saves another 4x (m3)
Why it matters
- In attribution analysis (DeepLIFT/SHAP), shuffle operations are typically both a performance and memory bottleneck; end-to-end packed-space computation makes operations at this scale "unlikely to be the bottleneck in any pipeline" (m5), a substantial speedup for large-scale genomics deep learning workflows
- 2-bit-per-position packing is a general technique transferable to any discrete data with a small alphabet and a single value per position (like board states); m1/m3 offer directly reusable implementation approaches
2026-10-20 ~ 2026-10-20 · 6 related posts
Primary sources
- tangermeme adds PackedSequence: 2 bits per base, 16x memory savings and 9x faster shuffling — jmschreiber91 ·
- Operating fully in packed space: 10k-window shuffle drops from 7.86s/8.7GB to 0.85s/0.7GB — jmschreiber91 ·
- Speeding up DeepLIFT/SHAP: packed-sequence dinucleotide shuffling avoids memory blowup — jmschreiber91 ·
- Pack four board positions into one uint8 for 16x memory savings — jmschreiber91 · 2026-10-20
- Packing four loci per uint8: a memory trick that slashes DNA sequence encoding by 4x — jmschreiber91 · 2026-10-20
- Tangermeme adds ersatz ops on packed sequences, cutting memory from 3.8GB to 755MB — jmschreiber91 · 2026-10-20
- [source] Speeding up DeepLIFT/SHAP: packed-sequence dinucleotide shuffling avoids memory blowup — jmschreiber91 · 2026-10-20
- [source] Operating fully in packed space: 10k-window shuffle drops from 7.86s/8.7GB to 0.85s/0.7GB — jmschreiber91 · 2026-10-20
- [source] tangermeme adds PackedSequence: 2 bits per base, 16x memory savings and 9x faster shuffling — jmschreiber91 · 2026-10-20