Julia-2 / runtime /README.md
Julia Klee
Julia-2: julia2_audio_v1 (text = base_v2 byte-identical, + pruned audio tower, stem p9), int8/int4 variants, lean runtime 0.1.0 (audio, LiveSession, modalities), card with speech, live calls and variants
1d1c6db
|
Raw History Blame Contribute Delete
4.19 kB
# Julia-2 runtime (`julia2`, draft 0.1.0)
A small standalone runtime for the Julia-2 decision model: text / JSON / image / audio states, live calls.
No `transformers` at inference: own forwards for the trunk (hybrid linear-attention + attention), the vision tower and
the audio tower, loading only the tensors Julia-2 uses (no LM head, no MTP, no generation code).
Dependencies: `torch`, `safetensors`, `tokenizers`, `numpy`, `pillow`, `soundfile` (audio files), `scipy` (resampling).
Optional fast kernels on CUDA: `flash-linear-attention`, `causal-conv1d` (pure-torch fallbacks are used otherwise).
```python
from julia2 import Runtime
rt = Runtime("Julia-2") # or Runtime(path, precision="int8"|"int4", device="cpu")
# text / JSON (System One request format; one probability per option, nothing generated)
rt.predict_questions(state, {"move": {"type": "choice", "instructions": "...", "criteria": {"a": "...", "b": "..."}},
"risk": {"type": "noul", "instructions": "Is this risky?"},
"level": {"type": "score", "instructions": "Severity?", "criteria": ["none", "low", "high"]}})
rt.decide(state, "Which option?", {"a": "...", "b": "..."}) # one choice question
rt.predict_batch([{"state": ..., "questions": {...}}, ...]) # many requests, length-bucketed batches
# images and audio: System One parts in the state, or images= / audio= arguments
rt.predict_questions([{"type": "image", "image": "photo.jpg"}, {"type": "text", "text": "Claim form attached."}], questions)
rt.predict_questions([{"type": "input_audio", "input_audio": "call.flac"}], questions) # path | bytes | data URL | (np.array, sr)
# live call: fixed context + fixed questions, audio pushed as it arrives, answers streamed after every push/turn
live = rt.open_live({"customer": "Ana", "bank": "Meridional"}, questions, lang="en")
live.turn("caller"); live.push(pcm_float32_16k) # any chunk size (80 ms is fine); encodes in 0.96 s hops
answers, alert = live.ask() # alert = hysteresis on the question with key "alert"
live.turn("customer"); live.push_text("No, I never gave anyone my PIN.")
```
## How it works
* **Shared state.** The state is read once into a `State` (recurrent/conv states of the 18 Gated-DeltaNet layers + K/V
of the 6 attention layers). Every question is a short branch forked from that state; answers equal independent passes
within bf16 noise. Live sessions append tokens to the same state (text, audio, 80 ms chunks), so a question costs the
same whether the call is 10 s or 10 min old.
* **Audio enters as tokens.** The audio tower (EmbeddingGemma-2 conformer, pruned 10 layers / FFN 3072 / 6 heads, Apache-2.0)
+ projector produce 12.5 tokens/s in the trunk's input-embedding space. No transcription anywhere.
* **Images.** Own preprocessing (bicubic resize to the 1.6 MP cap on a 32-px grid, patch 16, merge 2, 3-D rotary positions),
encodings cached per image hash so several questions / requests on the same image do not re-encode it.
* **GPU.** bf16 weights, fp32 norms/recurrence/readout, static state buffers, append/ask captured as CUDA graphs per shape,
compiled fixed-shape audio hop encoder. **CPU.** same code, bf16 compute when the CPU has fast bf16 (AMX / AVX512-BF16),
fp32 otherwise, thread count capped to physical cores.
* **Precision variants** (`precision=`): `bf16` (root), `int8` (per-channel weight-only), `int4` (asymmetric, groups of 128).
Norms, embeddings, readout, audio projector/subsampler, vision patch-embed/merger stay in bf16. See `models.json`.
## Tests and bench
```
python -m tests.run_all [--device cpu] [--precision int8] # text == reference (argmax >= 99%), image smoke, audio gap smoke, live streaming == full re-encode
python -m tools.bench [--device cpu] [--precision int4] # p50/p95 latency for text / shared / batch / image / audio / live, peak memory
```
`tests/text_ref.json` holds the reference probabilities (300 held-out rows, computed with the training-time HF path of the
same checkpoint); `tests/data/` three held-out synthetic calls (two-voice TTS, scripts by an LLM).