Metadata-Version: 2.5
Name: helix-lm
Version: 2.9.1
Summary: HELIX, ANANSI and TriStream-2: linear-scaling sequence architectures with exact long-range recall, the engine that trains them (Muon, muP, growth), a music stack (analysis, frisson critic, conductor, separation, singing voice conversion), and Pinxit, a painter that works stroke by stroke
Project-URL: Homepage, https://github.com/Wisk-inc/transformers/tree/main/helix-lm
Project-URL: Source, https://github.com/Wisk-inc/transformers/tree/main/helix-lm
Project-URL: Issues, https://github.com/Wisk-inc/transformers/issues
Author: Nathan
Maintainer: Nathan
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: animation,associative-recall,attention,audio-codec,coding-agent,delta-rule,linear-attention,long-context,music-information-retrieval,painting,pretraining,pytorch,singing-voice-synthesis,sparse-attention,state-space-model,stroke-based-rendering,style-transfer,text-to-video,transformer,voice-conversion
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: huggingface-hub>=0.25
Requires-Dist: numpy>=1.24
Requires-Dist: pyarrow>=15
Requires-Dist: safetensors>=0.4
Requires-Dist: tokenizers>=0.20
Requires-Dist: torch>=2.6
Requires-Dist: zstandard>=0.22
Provides-Extra: all
Requires-Dist: accelerate>=0.30; extra == 'all'
Requires-Dist: demucs>=4.0; extra == 'all'
Requires-Dist: diffusers>=0.32; extra == 'all'
Requires-Dist: evalplus>=0.3; extra == 'all'
Requires-Dist: flash-linear-attention>=0.3; extra == 'all'
Requires-Dist: imageio-ffmpeg>=0.5; extra == 'all'
Requires-Dist: lm-eval>=0.4.5; extra == 'all'
Requires-Dist: peft>=0.13; extra == 'all'
Requires-Dist: pillow>=9; extra == 'all'
Requires-Dist: pypdf>=4; extra == 'all'
Requires-Dist: soundfile>=0.12; extra == 'all'
Requires-Dist: transformers>=4.49; extra == 'all'
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: eval
Requires-Dist: evalplus>=0.3; extra == 'eval'
Requires-Dist: lm-eval>=0.4.5; extra == 'eval'
Provides-Extra: jamaica
Requires-Dist: pypdf>=4; extra == 'jamaica'
Provides-Extra: kernels
Requires-Dist: flash-linear-attention>=0.3; extra == 'kernels'
Provides-Extra: music
Requires-Dist: demucs>=4.0; extra == 'music'
Requires-Dist: soundfile>=0.12; extra == 'music'
Provides-Extra: paint
Requires-Dist: accelerate>=0.30; extra == 'paint'
Requires-Dist: diffusers>=0.32; extra == 'paint'
Requires-Dist: imageio-ffmpeg>=0.5; extra == 'paint'
Requires-Dist: peft>=0.13; extra == 'paint'
Requires-Dist: pillow>=9; extra == 'paint'
Requires-Dist: transformers>=4.49; extra == 'paint'
Description-Content-Type: text/markdown

# HELIX

**H**ierarchical **E**pisodic **L**inear **I**nde**X** — a sequence architecture that keeps what attention
is good at while dropping the quadratic bill.

```bash
pip install helix-lm
```

```python
import torch
from helix_lm import HelixConfig, HelixForCausalLM

model = HelixForCausalLM(HelixConfig(vocab_size=32000, hidden_size=1024, num_hidden_layers=12)).eval()
with torch.no_grad():  # nothing is trained here, so no activations are kept for a backward pass
    logits = model(torch.randint(0, 32000, (1, 8192))).logits
    text = model.generate(torch.randint(0, 32000, (1, 64)), max_new_tokens=32, temperature=0.8)
```

```bash
helix info      # what it is and what it costs
helix demo      # build a model, generate, verify the decode state
helix bench     # cost against context length
helix recall    # train with and without the index strand, and compare
```

---

## The idea

A transformer compares every token to every other token. Ten thousand tokens is fifty million
comparisons; double the input and you quadruple the work. Linear-time alternatives fix that by squeezing
the past into a fixed-size state — and then they cannot quote you a name they saw once, because a state of
`S` bits cannot tell apart more than `2^S` histories. That is a counting argument, not an engineering gap.

HELIX does not try to compress its way around it. It **separates memory capacity from memory bandwidth**.
Every block braids three mixers over the same residual stream:

| strand | reads | training cost | held at decode |
| --- | --- | --- | --- |
| **L** local | the last `local_blocks × block_size` tokens, exactly, with a different window per head | `O(N · span)` | a window-sized ring buffer |
| **R** recurrent | everything, compressed into a matrix-valued delta-rule state | `O(N · d_k · d_v)` | one matrix + two conv states per head |
| **I** index | `index_topk` blocks chosen anywhere in the past by a beam descent over a landmark tree | `O(N · topk · block_size)` + `O(N log N)` routing | the key/value history and a landmark tree, of which a step reads `O(topk · block_size + branching · log N)` |

Storage is `O(N)`, append-only, never rewritten, and can live in cold memory. What a single token *touches*
is bounded. So the claim is **`O(1)` hot state and `O(log N)` probes** — not `O(1)` total memory, which is
impossible for anything that can quote an exact name from a million tokens back.

## How the index works

The past is cut into blocks of `block_size` tokens. Each closed block gets a **landmark** — a learned pooled
summary that mixes a plain mean with an attention pool, because a mean alone erases the rare token a later
query will be hunting for. Landmarks are pooled again, `index_branching` at a time, into a tree, using one
weight-shared pooler at every internal level.

Two rules keep it causal *and* parallel:

1. **A node is eligible for query block `J` only if the whole span it summarizes ends at or before `J`.** A
   summary is never consulted by a query it partly describes, so a landmark is computed once and reused by
   every query.
2. **Routing for block `J` comes from the hidden state at the end of block `J − 1`.** Strictly past for
   every token of block `J`, so one gather serves `block_size` queries. Anything routing could not
   anticipate inside that block is covered exactly by strand L.

The descent keeps `index_beam_width` nodes per level. Candidates at each level are the beam's children
**plus** that level's *frontier* — eligible nodes whose parent is not eligible. At most `branching − 1` per
level, and the frontiers across all levels tile `[0, J)` exactly, so nothing reachable is cut off by a beam
that descended elsewhere. Selection scores are fed back as additive attention logits, accumulated along the
descent path, which is what lets gradient reach every level of the tree rather than just the leaves.

## What has been measured

On small models, 4 CPU cores. Reproduce with `helix bench` and `helix recall`.

**Cost against context length.** Attention pairs are exact — the query/key products the forward pass
actually forms, counted by instrumenting the attention call.

| tokens | HELIX pairs/token | full attention pairs/token | HELIX | full attention |
| ---: | ---: | ---: | ---: | ---: |
| 4 096 | 8 192 | 32 776 | 0.4 s | 0.2 s |
| 8 192 | 8 192 | 65 544 | 0.9 s | 0.6 s |
| 16 384 | 8 192 | 131 080 | 1.7 s | 1.9 s |
| 32 768 | 8 192 | 262 152 | 4.3 s | 6.7 s |

HELIX fits `N^1.00` in attention pairs; full attention fits `N^2.00`. By 32k tokens HELIX forms **32×
fewer** and runs **1.6× faster** — as unfused reference PyTorch against a fused SDPA kernel.

**Recall from far back.** Multi-query associative recall: bindings written near the start, queried ~200
tokens later, well outside the local window.

| model | recall | 95% CI |
| --- | ---: | :---: |
| HELIX (L+R+I) | **30.8%** | [28.5%, 33.1%] |
| HELIX no index (L+R) | 6.0% | [4.8%, 7.2%] |
| full attention | 32.0% | [29.7%, 34.3%] |
| *chance* | *6.2%* | |

Read the two gaps separately. **HELIX against its own ablation is the result**: strip the index strand and
the same model, same width, same depth, sits at chance — its window cannot see the bindings and its
recurrent state cannot hold them. That gap is ~21 standard errors. **HELIX against full attention is a
tie**, not a win or a loss: 1.2 points with a 1.7-point standard error, z = 0.72.

## Correctness

`pytest` covers the properties you can check without training anything:

- **strictly causal** — editing token `t` leaves every earlier logit bitwise unchanged;
- **decode == prefill** — token-by-token generation from the fixed-size state reproduces the one-shot
  forward, as does unaligned chunked prefill;
- **right padding is exactly invariant**;
- **constant work per token** — each query reads the same number of keys at any context length;
- **the cache is what the architecture claims** — fixed-size recurrent and convolution states everywhere,
  a window-capped key/value cache on non-indexing layers;
- **tiling is bitwise inert** — `attention_tile_blocks` caps peak activation memory and changes nothing;
- **every parameter gets gradient**, landmark poolers included.

## What this is not

**There are no trained checkpoints.** Nobody has trained HELIX on real text. Everything above is about
complexity, causality and recall mechanics — properties provable on an untrained model or a synthetic
probe — not about perplexity or language quality. The inductive-bias arguments (multi-scale windows, short
convolutions, surprise-gated writes) are untested hypotheses.

Treat this as an architecture proposal with a working, tested reference implementation, not a better model.
Finding out whether it is actually better needs real training runs on real hardware.

Known design limits, stated plainly:

- One retrieval serves a whole query block, so `index_topk` must cover the diversity a `block_size` span
  asks for.
- Routing is one block stale — the index cannot react to the token currently being generated.
- Landmarks are pooled from keys that already carry their rotary phase, so routing is not purely
  content-addressed.
- Left padding shifts the block grid, so it is not bit-identical to an unpadded run. Right padding is.
- No fused kernel for the gathered attention yet; the scaling is right, the constant factor is not.

## Configuration

Every knob is on `HelixConfig`, documented in its docstring. The ones that matter most:

```python
HelixConfig(
    block_size=64,          # memory-block granularity
    local_blocks=4,         # strand L sees 4 previous blocks plus its own
    num_window_scales=4,    # head groups get geometrically different windows
    index_topk=8,           # blocks strand I retrieves per query block
    index_layer_stride=3,   # ...on every third layer; the rest keep an O(1) KV cache
    index_branching=8,      # landmark tree fan-out
    attention_tile_blocks=64,  # caps peak activation memory; no effect on the result
)
```

## 2.6: Pinxit draws anime, and paints with an image model

A first, experimental version: it redraws a video model's clip as flat anime drawings. On a photo-like clip
the result is not yet the clean studio look; treat it as a tool to try, not a finished one.

* **anime drawn by hand** ([docs/PINXIT_ANIMATE.md](docs/PINXIT_ANIMATE.md)): ask in words, and an open video
  model (Wan 2.2 14B on a large GPU, Wan-Animate to make your character perform a motion, AnimateLCM on a CPU,
  or LTX, Hunyuan, CogVideoX, any of them with a LoRA of your own) imagines the motion. Pinxit then draws it
  as a studio does: the background painted once and held, the character inked and painted as a cel on every
  drawing, timed on ones, twos and threes, faces and hands drawn again at three times the size and carried over
  rigidly, every line steadied through time, every drawing checked against its frame and fixed where it is
  off. Depth, the character's outline and the camera come from the clip itself;
* **the desk**: `clip.making_of()` shows it being drawn, the background first, then each drawing on the
  lightbox, a shaded 3D hand holding the brush pen, an exposure sheet along the top;
* **memory**: a `.pinxa` file keeps it all, to recolour (shadows stay shadows), redraw with another pen, play at
  any frame rate or carry on with a next clip;
* **paired with an image model**: `paint(photo, imagine=load_imaginer(), subject="...")` has Stable Diffusion
  1.5 (held to the photo's edges) imagine the photo as a painting, and Pinxit paints that stroke by stroke;
* **words**: the eye finds a thing named in words in a picture, and reads a feeling from a phrase.

```python
from helix_lm.paint import animate
clip = animate("a cheerful anime girl with short red hair waving hello, upper body, in a sunny park")
clip.save("girl.mp4", fps=24); clip.making_of("girl_being_drawn.mp4"); clip.save("girl.pinxa")
```

## 2.5: Pinxit, a painter

Pinxit (`helix_lm.paint`, [docs/PINXIT.md](docs/PINXIT.md)) paints a photo stroke by stroke. It does not start
from noise. It decides what the picture is about, mixes a palette and lays brush strokes from broad to fine,
each with a brush, two pigment mixes, a pressure and a speed. What comes back is the list of strokes, so a
painting can be rendered at any size, replayed, saved with its memory and changed later.

```bash
pip install "helix-lm[paint]"
```

```python
from helix_lm.paint import load_eye, paint

eye = load_eye()                                         # SigLIP 2: it finds the subject
painting = paint("photo.jpg", style="mona lisa", emotion="majesty", eye=eye)
painting.save("painting.png")
painting.save("painting.pinxit")                         # with its memory: add to it, rework it, undo
```

* **the hand shows**: a heavy stroke is wide, thick and pools where it lands; a fast one runs dry, shows the
  brush's hairs and ends ragged; a slow one trembles. The canvas has a weave that a dry brush skips, and a
  saved picture shows the canvas's bare edge;
* **it holds back**: the subject is finished, the rest is left broad, and a part that is not to be finished is
  put in with one fast stroke;
* **it distorts on purpose**: the frame is cut to place the subject, the photo is seen in planes and tones
  before a stroke is made, lights are pushed warm and shadows cool, contrast is raised at the subject;
* **style from a painting**: give it a picture of any painting, or the name of one of fourteen famous ones.
  It measures the palette, how hard the edges are, whether shapes are outlined and how much the paint shows,
  carries the photo's colours onto the painting's and works that way (soft glazes after Leonardo, short loaded
  marks after Van Gogh, drawn outlines after Hokusai);
* **memory**: `painting.add(image=...)`, `touch`, `rework`, `undo` (exact), also after saving and reopening;
* **a model to train**: Pinxit on the Helix trunk with SigLIP 2 as its eye, fine-tuned through small adapters.
  One notebook cell trains it in 12-hour sessions: [notebooks/pinxit_molab_cell.py](notebooks/pinxit_molab_cell.py).

It runs today on a CPU without trained weights (written rules propose the strokes, gradient descent settles
them). No GPU run has been made yet, and painting from words does not work well enough to use; the document
says what was checked and what was not.

## 2.0: ANANSI, faster learning, audio

2.0 is a major upgrade documented in [`docs/ANANSI.md`](docs/ANANSI.md), with the evidence behind every piece:

* **faster learning** in the trainer: `--optimizer muon` (orthogonalized momentum, about 2x AdamW's token
  efficiency in Moonshot's scans, Kimi K2's optimizer), `--mup` (learning-rate transfer from a pilot),
  multi-token prediction, `helix grow` (train small, stack, continue), `--reweight-strength` (online data-mixture
  reweighting from held-out progress);
* **ANANSI** (`helix_lm.anansi`, sizes `a-350m` .. `a-34b`): the HELIX strands in a new body -- four residual
  streams mixed by manifold-constrained hyper-connections, a looped reasoning core with adaptive depth at
  inference (`model.think`), gated attention, a hashed n-gram memory, sandwich norms, a recurrence-only prelude,
  an optional fine-grained mixture of experts, and a multi-token predictor;
* **audio** (`helix_lm.audio`): a raw-waveform codec at 25 frames a second with a split residual quantizer, a
  speaker encoder for zero-shot voice cloning, score streams for singing, and an omni wrapper that interleaves
  text tokens and audio frames in one Anansi sequence;
* **a toy task suite** (`helix anansi bench`): recall, parity, multi-hop, copy-with-noise for the three families.

```bash
helix anansi sizes && helix anansi demo
helix anansi bench --steps 300
helix train --size a-1b --optimizer muon --mup --reweight-strength 1 --data /data/corx --out /data/corx/runs/a-1b
helix audio sources --commercial
```

## 2.2: hardening TriStream-2

2.2 answers the three failure modes named against 2.1 and the robotic-sound problem, with mechanisms, detectors
and fallbacks (`docs/TRISTREAM.md` section 12):

* **the refiner** (`helix_lm.audio.refiner`): phase-true additive harmonics from a 100 Hz F0, 10 ms shaped noise
  for consonants and breath, a snake-activated residual network and a gate on the codec's output, trained with
  transient and high-band losses; a 50 Hz codec option;
* **stream sync**: sub-frame F0 in the source stream, a monotonic alignment prior on lyric attention, a formant /
  pitch invariance loss;
* **routing**: look-ahead conditioning and a song-event track so the index is one block early instead of one
  block stale; sway sampling, adaptive steps, classifier-free guidance;
* **the ear** (`helix_lm.music.artifacts`): frame-rate buzz, harmonic coherence, metallic high band, consonant
  smear, sync lag, robotic pitch;
* **the humanizer** (`helix_lm.music.humanize`): portamento, overshoot, scoop, late and drifting vibrato, wander,
  jitter, releases, attacks, phrase arches, breaths; styles; the conductor renders through it;
* **the fail-safe loop** (`helix_lm.music.failsafe`): generate, listen, escalate, repair the span, transplant the
  source's unvoiced band, fall back to the source-filter sketch, report;
* a per-band **room model** so a swapped voice gets the original's room, not a broadband tail;
* **2.3**: the molab program mirrors its run to a private Hub repo and resumes from it (checkpoints with
  step and hours, budgets that carry across restarts, retries), fills the GPU (auto batch, TF32, prefetch),
  extracts and prepares the downloaded sets on the GPU, and keeps speech from swamping singing: domain
  shares first (speech annealed 50 % -> 10 % of each batch), spoken clips at half loss weight, a 50/50 codec,
  singing-only evaluation; round three (section 14): a sustain-aware alignment prior for melismas, a codebook
  register audit with high-register oversampling, rooms and EQ on every training input against dry targets,
  a per-frame formant curve with a pop detector, and a two-block look-ahead switched on before drops;
* **2.9.1**: a band limit no lead is given (a low-pass under 2 kHz, a high-pass over 1.2 kHz) is taken for a
  misreading and never put back on the new voice. A bare tone read as a 252 Hz low-pass in 2.9.0;
* **2.9.0**: TriStream on a produced lead ([docs/TRISTREAM.md](docs/TRISTREAM.md) section 19). A vocal stem from
  a dancehall or trap song keeps its chain after separation: hard pitch correction, delay throws, a plate, a
  double, saturation, a telephone EQ, heavy compression. A conversion now measures that chain, takes off what
  misleads the pitch and the words (the echo's repeats, the reverb's tail, what compression lifted between the
  lines), tracks a telephone line with its fundamental made again, and asks the model for the melody a singer
  would sing: the corrector's snaps become glides, so the new voice does not inherit the old corrector's jitter.
  Then it puts the chain back on the new voice: the corrector in the key the melody was moved to, the colour, the
  delay, a long reverb by its measure (`fx="keep"`, the default; `"dry"` leaves the new voice dry; `"off"` is
  2.8). In training, about a third of the conversion clips are heard through such a chain and one in ten is sung
  pitch-corrected. Measured on 85 real takes: no natural take read as pitch-corrected, 73 % of 0 ms corrections
  found; constant delays found on 17 to 22 of 22 takes each, 2 false echoes; under a hard telephone band the
  tracker's frames off by 50 cents went from 35 % to 5 %. Joins between chunks, repairs and the ducked band hold
  their level now (a dip of 8.1 dB at worst is 4.1, one of 3.2 dB is 0.06). No real dancehall stems were in the
  tests, and nothing ran on a GPU;
* **2.8.1**: fixes from seven reviews of 2.8.0 before its first paid run ([docs/TRISTREAM.md](docs/TRISTREAM.md)
  section 18.8). The ones that mattered most: files at 44.1 or 48 kHz (every VocalSet take) were resampled with
  their top octave folded back as noise; clips kept from an older pitch tracker kept its pitch; a clip could be
  its own voice prompt, which teaches copying; on a GPU the teacher's ear ran in half precision and a silent
  row ended the stage; the run's first pull from the Hub, and a pull of the teacher's pairs, ended or redid
  work on one cut download; the setup stage could replace the machine's torch while installing the song
  separator; a stopped cell stopped reading the program before it had pushed; and the glitch gate took the loud
  end of a clip for a dropout at its quiet start. Each has a test;
* **2.8.0**: TriStream on the hard kinds of singing, and between voices that are far apart
  ([docs/TRISTREAM.md](docs/TRISTREAM.md) section 18). The slips were looked for on real takes of belting,
  vibrato, trills and fast runs, and at the end the whole program was run on the CPU with the published
  weights. The pitch tracker reported every frame's pitch 9 ms late, let each frame choose alone, and read
  a voice with one strong harmonic (a belt, a man on "u") an octave up for whole notes. It is now timed on
  the stretch it compares, picks one line through the clip, and makes a short period pay for what it leaves
  unexplained: a vibrato of 200 cents at 7.5 Hz was 58 cents wrong and is 3, and the frames far off over 112
  test voices went from 33.5 % to 9.6 %. The gates turned away a faithful copy of 9 of 47 real takes and now
  pass all 71. Conversion left out three inputs that training always gives. New: a published converter
  (SoulX-Singer-SVC, Soul AI Lab, Apache-2.0) sings training takes in other training voices before training
  (`--teacher-hours`). Its conversion path is written into this package and agrees with the original code to
  91 dB; every rendition is judged and the worst are dropped; the pairs go to the private repo, so they are
  made once. Also: the key a melody is moved to for the new voice (`--key`, `--reference-kind`), breath and
  roughness taken from the new voice, the lead taken out of a stereo vocal stem (`--backing`), a spoken
  reference taught with the singers' own spoken takes, hard clips drawn twice as often, and an evaluation
  that reports belting, vibrato, trills and fast runs apart;
* **2.7.0**: TriStream can take its sound and its words from published models and train nothing but the
  singing model ([docs/TRISTREAM.md](docs/TRISTREAM.md) section 17). With `--backend pretrained` the frames are
  a log-mel spectrogram, BigVGAN v2 (NVIDIA, MIT) writes the sound, and HuBERT base (Meta, Apache-2.0) gives
  the content units; both are written out in this package for inference, checked against the originals on
  real singing, and saved whole with the run. No codec and no refiner are trained, so about twice the hours
  go to the model. Those hours are guarded: the averaged model is scored on singers it is not taught, the
  best is kept as `best.pt`, and the stage ends early when the score stays past its best. Also new, for
  either backend: one module makes the model's inputs for training, evaluation and conversion; the pitch is
  tracked on the GPU on the codec's own frames; the noise stream reads four measurements of the sound and no
  longer most of the input's spectrum; guidance hides the voice prompt, not only the speaker vector; produced
  frames are read back for their pitch; and some conversion batches hear their words in another voice, sung
  by the averaged model itself. The codec of 2.6 is still there (`--backend own`);
* **2.6.2**: TriStream makes up for little data with what it asks of each training step
  ([docs/TRISTREAM.md](docs/TRISTREAM.md) section 16). For voice likeness: a few seconds of the reference
  go before the clip as a voice prompt, the speaker encoder gets a contrast lesson of its own, and what a
  step would produce is read back for its voice. For words: it is read back for its content codes, and the
  codec's first codebook is taught by a frozen HuBERT and to read the same codes from another voice. For
  consonants: onsets count more in the codec and in the model. For high notes: batches are transposed
  into new singers in other registers. For leftovers of music: a backing-track residue made from nothing.
  Also a learning rate that falls with the hours, averaged weights, and the best of three tries at
  conversion. Two errors that only bf16 on a GPU would have shown are fixed: the quantizer stopped at its
  first dead code, and picked codes less exactly;
* **2.6.1**: TriStream checked on real recordings before a B300 run ([docs/TRISTREAM.md](docs/TRISTREAM.md)
  section 15). The dryness check turned away 45 of 48 real VocalSet takes and all 240 real Emilia clips, so
  the model would have trained on almost nothing: it now measures how fast the level falls when the voice
  stops. Training taught only fill-in editing, never what conversion asks (every frame masked, content
  codes, a voice from another clip): both lessons are taught now. Two choir sets the program called CC BY
  are CC BY-NC and are left out unless asked for. A preflight stops a run with no GPU, too little disk or a
  token that cannot read the speech data, and rehearses every training stage on the card first. Checkpoints
  have a backup, pushes are checked and run in the background, a loss that is not a number is skipped, and
  rooms, EQ, noise and pitch tracks are made on the GPU so 24 CPU cores can feed a large card;
* **2.4.1**: fixes from a bug scan before the first GPU run. On a GPU the prepare stage stopped at its first
  clip (the breath check built its window on the CPU), and the eval stage would have stopped in its first round
  (a CPU random generator for GPU noise, and CPU kernels in the glitch, buzz, robotic and sync checks); a test now
  replays those paths on the CPU with every would-be GPU tensor tagged, so this kind of failure is caught without
  a GPU. The session's end can no longer be swallowed by the data stage's per-source error handling. Pitch files
  made by the old tracker are redone with YIN from the vocals on disk. VocalSet's five benchmark singers are never
  trained on. The converter moves audio to the model's device. In the benchmark: the register task crashed, the
  VocalSet sample was one singer, a clean voice scored register pops, and one failing task cost the whole run;
  all fixed. The glitch check is 19 times faster on a long song;
* **2.4.0**: TriStream finishes each molab session cleanly (it saves, pushes and stops 30 minutes before the
  12-hour limit, and the next session goes on from there); the prepare stage keeps a record per clip, so a
  stopped prepare resumes at the clip it reached instead of the first one; a failure that comes back three
  times in a row stops the run instead of retrying for days; pitch targets from YIN (no octave errors on low
  voices, frames centred on their time); a blurred pitch target decoded below a bin; and a benchmark suite
  (`helix tristream bench`, [docs/BENCHMARKS.md](docs/BENCHMARKS.md)) run after every eval, with results on
  the Hub. The one notebook cell is [notebooks/tristream_molab_cell.py](notebooks/tristream_molab_cell.py);
* **2.3.4**: the GPU is fed by every CPU core but two (worker processes building small chunks, joined on the
  GPU from pinned memory; threads when `/dev/shm` is small or a worker dies), the batch is the fastest one for
  the card (doubled while clips per second rise, never just the largest), schedules count clips instead of
  steps, pitch tracks for the refiner are built off the GPU's path, and raising a stage's hours continues it;
* **2.3.3**: nothing already on disk is downloaded again: a file checked once is stamped and skipped, an
  archive already unpacked is skipped even when its zip is gone, Emilia fetches only the shards not yet
  unpacked, and an interrupted download says it is resuming and reuses every byte it has;
* **2.3.2**: sixteen ranged connections per download, each resuming on its own (Zenodo throttles one
  connection to about 1 MB/s; sixteen reached 41 MB/s), with MB, MB/s and minutes left in the log;
* **2.3.1**: downloads verified by size and md5 with resume and a second route, corrupt archives deleted
  and fetched again, one run per root (`run.lock`), the data stage retried until every source is whole;
* **round two** (`docs/TRISTREAM.md` section 13): one global frame grid and measured drift control for long
  tracks (`music.longform`), register physics with a bounded formant move and F1 tuning (`music.register`), an
  air-band extension to 48 kHz with air and pre-echo detectors, an intake that measures and cleans real-world
  audio and passes its quality to the model as a condition (`music.intake`), and robust reference embeddings
  that drop shouted, whispered or buried windows and report contamination.

## 2.1: TriStream-2 and the music stack

2.1 adds `helix_lm.music`, documented with its evidence in [`docs/TRISTREAM.md`](docs/TRISTREAM.md):

* **TriStream-2** (`ts-765m`, 764.5M parameters): a source / filter / noise / lyric singing model on the Anansi
  trunk with a rectified-flow decoder over codec frames and a source-filter sketch as its prior; in-context
  zero-shot cloning through masked-span editing; singer **and accent** adversaries; pitch and duration heads;
* **the song analyser**: beats and downbeats, key and scale, chords and tension, structure, loudness,
  brightness, room, groove and vibe cues, in plain PyTorch;
* **the frisson critic**: a per-beat "chills" score from the triggers the literature found (dynamic surges, a
  voice entering, range expansion, surprise inside a predictable context, tension released, the dip before the
  drop, groove), with the weights written out as priors and a head to learn them from labels;
* **the conductor**: a readable vocal plan (where to enter, which notes in key and in range, harmonies, breath /
  power / vibrato / warmth / echo sliders, the sudden soloist, the octave-leap climax) scored for restraint;
* **separation, conversion, effects**: a band-split separator with mask budgeting, harmonic gating, target-singer
  extraction for duets and a bleed report; the voice-swap pipeline (separate, analyse, capture the vocal's
  effects, convert, re-apply, remix, gates); reverb / echo / muffle / retune / formant shift / ducking / limiter /
  breaths; glitch detection and repair;
* **data rules**: accent tags and balancing, pitch-range buckets with a gaps report, dry-target checks,
  singer-disjoint splits, augmentation into the hard input conditions, multi-file uploads;
* **the 96 GB program** (`helix tristream molab`, `python -m helix_lm.scripts.tristream_molab`): data, prepare,
  codec, refiner, air, train, eval, push, swap on one RTX PRO 6000 Blackwell, resumable, with auto batch sizing
  and the fail-safe loop in eval and swap.

```bash
pip install "helix-lm[music]"
helix tristream sizes && helix tristream demo
helix music analyze song.wav && helix music plan song.wav --out plan.json
helix music swap song.wav reference.wav --out out.wav
helix music swap song.wav speech.wav --reference-kind spoken --key octave --backing keep --out out.wav
python -m helix_lm.scripts.tristream_molab --root /workspace/tristream --stage all --hf-repo CorxLabs/Tristream-V2-SVS
```

Nothing in 2.1 has been trained at size; the document says what is measured (toy scale) and what is a plan.

## Training Helix (1.1): CorX5.5

1.0 added the engine that turns the architecture into a model and the ladder of named sizes; 1.1 is the
program that trains **CorX5.5**, CorxLabs' 34B long-horizon coding agent, from scratch on 870B tokens in one
year on 8 x B300, largely on Jamaican data, with safeguards. The plan, arithmetic, data mixture, safeguards
and limits are in [`docs/CORX5.5.md`](docs/CORX5.5.md); the earlier 23B plan is kept in
[`docs/HELIX_23B_PLAN.md`](docs/HELIX_23B_PLAN.md). The whole program is one startup script
(`corx_startup.sh`, built from the wheel) that runs as a service and pushes code, checkpoints and milestones
to `CorxLabs/CorX5.5`.

```bash
pip install "helix-lm[all]"
helix size 34b                  # the ladder: 350m, 1b, 3b, 7b, 23b, 34b -- parameters, FLOPs, hours on 8 x B300
helix kernels                   # FlexAttention / flash-linear-attention availability
helix jamaica crawl --data /data/corx --hours 12          # Jamaican public records (polite, robots.txt)
helix jamaica synth --data /data/corx --count 300000      # SJE/Patois code-switched dialogues via a local vLLM teacher
```

| piece | module | what it does |
| --- | --- | --- |
| fused strand L | `model.py` (`attention_backend="flex"`) | each head's sliding window as one block-sparse FlexAttention kernel, no key copies; equal to the reference staircase |
| Triton strand R | `model.py` (`recurrent_backend="fla"`) | `flash-linear-attention`'s chunked gated delta rule, the reference as fallback |
| sizes | `config.py` (`HelixConfig.named`) | 350m / 1b / 3b / 7b / 23b / 34b with analytic parameter and FLOP counts |
| Anansi | `anansi/` | the 2.0 network: hyper-connected streams, looped core, gated attention, n-gram memory, MoE option, MTP |
| optimizers | `optim/` | Muon + AdamW split, muP plans |
| growth | `growth.py` | identity and stack growth of exports |
| audio | `audio/` | codec, speaker encoder, singing streams, omni wrapper, dataset catalogue |
| tasks | `tasks.py` | the toy suite |
| transformer twins | `arch.py` | `t-350m` .. `t-34b` on the Qwen3 layout (QK-norm), same trainer, exported as `Qwen3ForCausalLM`; the pilot's control |
| tokenizer | `tokenizer.py` | the CorxLabs 65,536-token byte-level BPE (uint16 storage), chat and tool-call format |
| data | `data/` | verified Hub catalog (36 pretraining sources: web, code, execution traces, commits and issues, math, legal, health, finance, education, Patois), row renderers, streaming prepare to shards with a free-space guard, the Jamaica and Caribbean filters, identity documents, a deterministic resumable mixture loader |
| Jamaican data | `data/jamaica_gov.py`, `data/synth.py` | a polite crawler of Jamaican public records; SJE/Patois code-switched dialogues for banking, legal, health, education and customer service from a local Apache-2.0 teacher |
| safeguards | `data/safety.py` | the policy prompt, boundary and look-alike examples, agent conduct, CoCoNot/tulu refusals, XSTest over-refusal and harmful-set refusal rates in `helix eval` |
| trainer | `train.py`, `hub.py` | FSDP2 bf16, fused AdamW, warmup-stable-decay fitted to `--hours`, sharded checkpoints, bf16 safetensors export pushed to the Hub (history squashed, milestone copies every N tokens), resume, MFU, a stop file |
| SFT | `data/agent.py` | SWE-agent and SWE-smith trajectories, OpenCodeInstruct, OpenThoughts, smoltalk, tulu into one masked chat format |
| eval | `evaluate.py` | lm-evaluation-harness adapter, EvalPlus, a table against the published Qwen numbers |

```bash
# on the training machine (8 GPUs), in this order; every step resumes where it stopped
helix data verify                                     # sources reachable with $HF_TOKEN
helix tokenizer sample --data /data/helix             # a text sample of the mixture ...
helix tokenizer train  --data /data/helix             # ... becomes the 65,536-token tokenizer
helix data prepare --data /data/helix --tokens 23e9   # shards for a 1b run (23B tokens = 20 x 1.17B)
torchrun --nproc_per_node=8 -m helix_lm.train --size 1b --data /data/helix --out /data/helix/runs/helix-1b \
    --hours 7 --hub-repo CorxLabs/Helix-1B
helix sft prepare --data /data/helix                  # the coding-agent conversations, masked and packed
helix sft train --data /data/helix -- --size 1b --out /data/helix/runs/helix-1b-sft \
    --init-from /data/helix/runs/helix-1b/export --seq-len 32768 --hours 2
helix eval --model /data/helix/runs/helix-1b-sft/export
```

What the tests check (`pytest`, on a CPU, in about three minutes): the fused local attention equals the
reference; the chunked loss equals the one-piece loss; recomputation changes nothing; the sharded
safetensors round-trip; the analytic parameter count matches the built model; the tokenizer round-trips,
fits in uint16 and masks a chat on the assistant's turns only; files become shards, Jamaica is found,
the identity is written; the loader is deterministic, striped across ranks, resumable and capped per
source; a training run checkpoints, exports and **resumes to the same losses and weights**; two
processes train with FSDP2 and distributed checkpoints and resume; SFT data is masked through packing and
a fine-tune starts from a saved model; the lm-eval adapter's log-likelihoods match a direct forward.

**Still true: there are no trained checkpoints yet.** 1.1 is the engine and the program, tested at toy scale
on a CPU. The program's first rung on the real machine is a 25-minute smoke run and its second a 1B pilot of
HELIX against its transformer twin on the same tokens; whether HELIX trains as well as a transformer on text
is what that pilot measures, before the year-long run starts.

## License

Apache-2.0. Portions of the delta-rule and rotary helpers derive from
[HuggingFace Transformers](https://github.com/huggingface/transformers) (Apache-2.0); see `NOTICE`.

**Made by Nathan.**
