Archived
- Gemma 4 31B (PRs #74, #75, #81, #86; sfjes, keptn42): sliding and global attention with their own kernels, the assistant head as a drafter that reads the trunk's cache, the vision tower, a fused w4a8 decode step, bf16 and compressed-tensors int4 checkpoints, and window snapshots so a prefix hit on a sliding-window model resumes instead of prefilling again. deploy/compose/gemma4-31b-w4a8.yaml serves keptn42's container on two cards - ParoQuant (PRs #65, #66, #67; malic): Qwen3.8-27B checkpoints with learned Givens rotations, as int4, int5 and MXFP4, imported without re-quantising, the prefill's rotations on the matrix cores. deploy/compose/qwen3.8-27b-paro.yaml serves them on one card. A ParoQuant container made with the PR builds is refused: convert it again with --reuse <old container> - Gemma 4 26B-A4B with z-lab's DFlash drafter (PR #88; Perire): arch/gemma4 serves Google's bf16 checkpoint with the routed experts in block fp8 or bf16 (data/recipes/gemma4-26b-a4b-df*.recipe), and libr4d gains its windowed paged attention, the fused sandwich-norm joins, expert_scale and the sharded draft head's pair_argmax. A prefill chunk runs as two slices with its all-reduces beside the compute, bit-exact with the whole step. The 31B's global layers take the windowed attention too: an 11.5K-token prefill on two R9700s in 3.1 s instead of 4.9 - a startup that logs nothing for two minutes says where it waits (#89): the system call (a KFD request by name), the library that made it, and its stack, which addr2line resolves against the binary - the prefix cache is kept in VRAM and host memory only (#70): the disk tier wrote every block and snapshot a prompt produced, and its copies never outlived the process. --prefix-cache-host-mib is renamed --prefix-cache-mib; --prefix-cache-dir and --prefix-cache-disk-mib are removed, and startup refuses all three with what replaced them. The compose files no longer mount /data, and .env no longer needs RADIANCE_STATE - --prefix-cache-ttl S (default 3600, 0 never): a conversation no request has used for that long leaves the cache, whichever tier holds it; radiance:prefix_cache_expired_total counts them. A full host tier now drops its least recently used conversations - --vision-tower-placement vram|ram (#84): ram keeps an encoder tower in pinned host memory and gives its VRAM to the KV cache, read over the link once an image - timings carry ttft_ms and total_ms (#85): the server's own time from the request body's arrival to the first and the last token, queueing and tokenisation included - a KV-cache recall that found a moved expert with nowhere to go stopped halfway and leaked the slots it had already freed: after it every recall failed, the cache stayed short until a restart, and requests failed with HTTP 500. A recall now waits for the slots it is owed and always finishes - a tool result or tool-call arguments that are not JSON are no longer refused as nesting past 1024 levels for their unmatched brackets (#90): only text that parses as JSON is held to the bound, since nothing else is parsed into a tree - the host-pool refusal names the limit that applies to pinned memory (RAM less 1/64 and 1.5 GiB), not ttm.pages_limit - --embedding-placement auto, removed in 1.3.0, is refused with what replaced it - for out-of-tree kernel libraries: gemm_nt_q gains two operands (pb1, pb2, the part bounds), and the loader requires identical op schemas, so a library built against 1.4.0 must be rebuilt. For architecture plugins, rad_op_declared(b, op) asks whether an op is in the loaded vocabulary without declaring it
125 lines
6.8 KiB
Markdown
125 lines
6.8 KiB
Markdown
# Static YaRN
|
|
|
|
Increasing `--max-model-len` reserves a larger serving window; it does not change
|
|
the model's rotary embeddings. A checkpoint trained at 262144 positions can
|
|
explicitly request static YaRN for a 524288-token deployment. Whether that extension
|
|
preserves useful accuracy must be measured on the model and workload.
|
|
|
|
One reader takes every architecture's rotary scaling (`yarn_from`,
|
|
`arch/common/rad_arch.h`). For the target it reads `text_config.rope_parameters`,
|
|
then `rope_parameters`, then the legacy `text_config.rope_scaling` and `rope_scaling`,
|
|
in that order; the first object with `rope_type` (or legacy `type`) is authoritative.
|
|
A drafter (DFlash2, DSpark) reads its own `draft.rope_parameters` /
|
|
`draft.rope_scaling`; it does not inherit the target's scaling. The vision tower keeps
|
|
its original axial rotations. A GGUF's `rope.scaling.*` keys are carried in as the
|
|
same `rope_scaling` keys when it is read.
|
|
|
|
**The factor convention is the config's**, as vLLM and transformers read it:
|
|
`factor` 2 over `original_max_position_embeddings` 262144 reaches 524288 positions.
|
|
|
|
Validated so far: the Qwen3.8 27B and 35B-A3B containers and both Flash-Next
|
|
variants at factor 2, with retrieval at ~500K tokens, and TP3 perplexity with
|
|
`--rope-scaling` within roughly ±1% of stock at factor 2. The LLaMA plugins read the
|
|
same keys and declare the same ops; YaRN there has had no model run.
|
|
|
|
## Metadata
|
|
|
|
| Key within the rotary object | Meaning |
|
|
| --- | --- |
|
|
| `rope_type` | `yarn`; `default`, absent or legacy `mrope` is no scaling; `linear` divides positions by `factor` |
|
|
| `factor` | finite number >= 1, required for YaRN |
|
|
| `original_max_position_embeddings` | positive integer, required; the **training** length, not the enlarged deployment/table length |
|
|
| `beta_fast`, `beta_slow` | defaults 32 and 1; finite, fast >= slow > 0 |
|
|
| `attention_factor` | positive finite cos/sin multiplier; default 1 + 0.1 ln(factor) for factor > 1, otherwise 1 |
|
|
| `truncate` | true/1 (default): floor/ceil correction bounds; false/0: retain fractional bounds |
|
|
|
|
Every other type -- `llama3`, `longrope`, `dynamic` -- is refused by name at load,
|
|
as are the `mscale` and `mscale_all_dim` variants (specify `attention_factor`). A
|
|
GGUF that sets llama.cpp's YaRN `attn_factor`, `ext_factor` or log multiplier to
|
|
anything but its neutral value is refused when read. Rotary width (including
|
|
partial rotary), theta and M-RoPE section selection are unchanged.
|
|
|
|
## Convert a separate container
|
|
|
|
Use the original target and drafter checkpoints, the same quantization recipe,
|
|
and a **new output path**. `--reuse` is valid only for the same source weights and
|
|
recipe; it is not a way to mix weights from different model revisions.
|
|
|
|
```sh
|
|
rad-convert /checkpoints/Qwen3.8-27B-FP8 \
|
|
--draft-model /checkpoints/Qwen3.8-27B-DFlash2 \
|
|
--recipe data/recipes/q38-27b-fp8-df2.recipe \
|
|
--reuse /models/qwen3.8-27b-fp8.rad \
|
|
--set text_config.rope_parameters.rope_type=yarn \
|
|
--set text_config.rope_parameters.factor=2 \
|
|
--set text_config.rope_parameters.original_max_position_embeddings=262144 \
|
|
--set draft.rope_parameters.rope_type=yarn \
|
|
--set draft.rope_parameters.factor=2 \
|
|
--set draft.rope_parameters.original_max_position_embeddings=262144 \
|
|
--max-ctx 524288 --kv-cache-dtype bf16 \
|
|
-o /models/qwen3.8-27b-fp8-yarn2.rad
|
|
```
|
|
|
|
Run with `--plan-only` first. `--max-ctx` is the converter's graph bound, not a
|
|
replacement for the explicit YaRN metadata or the server's `--max-model-len`.
|
|
The bundled `.rad` by itself is not a converter input; keep the source checkpoints.
|
|
Check both target and draft settings with `rad-info --meta` after conversion.
|
|
|
|
Serve on enough memory for the requested window:
|
|
|
|
```sh
|
|
radiance --model /models/qwen3.8-27b-fp8-yarn2.rad \
|
|
--tp 4 --max-model-len 524288 --max-num-seqs 32 --kv-cache-dtype bf16
|
|
```
|
|
|
|
That cache flag controls **both** target and drafter KV. Startup capacity and
|
|
successful actual long requests must be checked; the command is not a promise
|
|
of concurrency or accuracy. Keep the unmodified model and serving setup until
|
|
long-context quality and speed meet the deployment's requirements.
|
|
|
|
## Serve an existing container: `--rope-scaling`
|
|
|
|
The same metadata can be written when the container is loaded instead of converted in:
|
|
|
|
```sh
|
|
radiance --model /models/qwen3.8-next-flash-fp8.rad \
|
|
--rope-scaling yarn:2 --max-model-len 409600
|
|
```
|
|
|
|
`yarn:FACTOR[:ORIG]` sets `rope_type = yarn`, `factor` and `original_max_position_embeddings`
|
|
(`ORIG`, default the container's own trained length) in the rotary object the reader above
|
|
takes first -- for a Qwen3.8 container that is `text_config.rope_parameters`, which already says
|
|
`default`; YaRN written under plain `rope_parameters` would sit behind it and never be read. A
|
|
drafter gets the same factor over its own trained length. Over a checkpoint's own YaRN
|
|
the factor is replaced, its trained length kept unless `ORIG` is given, and an explicit
|
|
`attention_factor` (or `mscale` variant) dropped so the magnitude is derived for the new factor.
|
|
`none` takes a checkpoint's YaRN off. A linear or other explicit rotary type is refused rather
|
|
than stacked over. The result is resolved and checked exactly as a converted container's is
|
|
(`core/format/rope_override.h`, held to `yarn_from` in `tests/yarn_test.cpp`).
|
|
|
|
Startup says what the rotary is (`rope: YaRN factor 2 over 262144 trained positions -- the rotary
|
|
reaches 524288`) and warns when `--max-model-len` is past what it covers -- also with no scaling
|
|
at all, past the trained length.
|
|
|
|
The flag is for trying a factor, or serving a container whose source checkpoints are not at hand;
|
|
a deployment that settles on one can convert it in as above and drop the flag.
|
|
|
|
## Kernel and test contract
|
|
|
|
`rope`, `rope_table` and `qsa_block_key` take optional resolved coefficients
|
|
`yarn_factor`, `yarn_low`, `yarn_high`, `yarn_magnitude` (docs/OPS.md). Absent factor
|
|
is the original path, with the original op identities. With YaRN, `scale` must be 1:
|
|
inverse frequencies are blended rather than all positions being divided. Axial
|
|
rotary with YaRN is refused. Rebuild the bundled plugins together because their
|
|
shared op schemas must match.
|
|
|
|
The math follows the static YaRN formulation (Peng et al.) as vLLM's
|
|
`YaRNScalingRotaryEmbedding` implements it. `tests/yarn_test.cpp` pins the
|
|
correction bounds to vLLM's integers (14/22, 28/43, 56/85 for rotary widths 64, 128,
|
|
256 at factor 2, theta 1e7, 262144 trained positions); `tests/ref_test.cpp` and
|
|
`r4d_selftest` compare libref and libr4d against a double-precision evaluation of the
|
|
same formula at positions through 524287, within 8 ulp of each angle -- tight where
|
|
the ramp sits, loose only in the fastest pairs at long positions, which no f32 rotary
|
|
places better than its angle's own ulp. libavx is held to libref by `avx_check`, and
|
|
fused versus unfused HIP rotation is checked byte-for-byte separately.
|