Archived
nemotron 3.5 implementation
This commit is contained in:
1 parent
33108e488b
commit
94c90b17ad
59 files changed
+6046
-76
No files matched your search
@@ -21,6 +21,7 @@ plugin claims.
|
||||
| `arch/lfm2_bf16` | `lfm2` | *(empty)* | LiquidAI's LFM2 and LFM2-VL, bf16, one rank |
|
||||
| `arch/embgemma2` | `embeddinggemma2` | *(empty)* | EmbeddingGemma 2: a bidirectional encoder with Gemma 4's vision tower and audio conformer, pooled to one vector |
|
||||
| `arch/nomicbert` | `nomicbert` | *(empty)* | nomic-embed-text-v2-moe: a bidirectional post-norm encoder, 12 layers with 8 experts at top 2 on every second layer, mean-pooled to one vector an input |
|
||||
| `arch/nemotron35_embed` | `mistral3` | *(empty)* | Nemotron 3.5 Embed 1B and 8B: native BF16 bidirectional text/image encoders with a Pixtral tower, retrieval formatting and normalized mean pooling, TP1 ([geometry and contracts](#nemotron35_embed-embedding-models)) |
|
||||
| `arch/gemma4_bf16` | `gemma4` | `compressed-tensors` | Gemma 4 31B dense, and the E2B/E4B form at one rank, with its vision tower: sliding-window and proportional-RoPE global (`attention_k_eq_v`) attention, GELU ffn, softcapped logits; int4 codes with an f16 scale per 128 from Google's CT-INT4 (QAT) release or from bf16, served w4a8, or int8 codes on the same grid from bf16 (w8a8, the Q8 container). Optional draft model (`rad-convert --draft-model`): Google's assistant, with no cache of its own (`rad_drafter_shared_kv`), or z-lab's DFlash drafter, the block `arch/gemma4` serves (`arch/common/rad_gemma4_dflash.h`), or RedHatAI's DFlash2 speculator (`arch/common/rad_block_dflash2.h`) |
|
||||
| `arch/gemma3` | `gemma3` | *(empty)* | Gemma 3 dense text (TranslateGemma 27B) from the bf16 checkpoint: sliding-window and global attention at one head geometry, GemmaRMSNorm, GELU ffn; linears bf16, or int8, MXFP4 or asymmetric int4 over an activation scaled per (row, 128), as the recipe stores them. Optional DFlash2 drafter (`rad-convert --draft-model`) |
|
||||
| `arch/gemma4` | `gemma4` | *(empty)* | Gemma 4 text from Google's bf16 checkpoint (the 26B-A4B MoE and the dense sizes without per-layer embeddings) with z-lab's DFlash drafter; routed experts bf16 or block fp8 |
|
||||
@@ -863,6 +864,79 @@ Traps:
|
||||
|
||||
---
|
||||
|
||||
# `nemotron35_embed`: embedding models
|
||||
|
||||
Native BF16 [Nemotron 3.5 Embed 1B](https://huggingface.co/nvidia/Nemotron-3.5-Embed-1B-BF16)
|
||||
and [8B](https://huggingface.co/nvidia/Nemotron-3.5-Embed-8B-BF16) are bidirectional multimodal
|
||||
encoders, selected by `(mistral3, "")` with noncausal Mistral3/Ministral3 checks. They declare
|
||||
pooled output and no language-generation head. CPU (`libavx`, with `libref` as the oracle) and
|
||||
RDNA4 (`libr4d`) serve BF16 at TP1; quantized planes, TP>1, drafting and audio are rejected.
|
||||
[GUIDE §5.6](GUIDE.md#56-completions-embeddings-images-tokenising) covers serving and retrieval inputs.
|
||||
|
||||
| Checkpoint | Pinned revision | Text geometry | Default vector |
|
||||
|---|---|---|---:|
|
||||
| 1B BF16 | `e24ca1e346bcc53572bd7bdc02b3e8ebf66c197c` | 16 layers, hidden 2048, FFN 6144, 24 Q / 8 KV heads | 2048 |
|
||||
| 8B BF16 | `781e779ee4ca9c2d2a4f38321993556baeab49a1` | 34 layers, hidden 4096, FFN 14336, 32 Q / 8 KV heads | 4096 |
|
||||
|
||||
Both have 128-wide text heads. The 1B query width is 3072, independently of its hidden width.
|
||||
Each uses its own checkpoint weights and embedding space. The vision tower is Pixtral: 24 layers,
|
||||
hidden 1024, 16 heads of width 64, 14-pixel patches and a learned 2x2 patch merger/projector.
|
||||
|
||||
**Numerical contracts.** Native safetensors mapping fuses QKV and gate/up without changing
|
||||
precision. Attention is bidirectional over each complete input and isolated across inputs.
|
||||
Pooling is the valid-token mean; dimensional truncation precedes L2 normalization.
|
||||
|
||||
Ministral rounds the weightless norm before applying its BF16 gain. Its rotary rounds cos/sin
|
||||
and individual products to BF16, with model-local YaRN magnitude and position-dependent query
|
||||
scaling, including the position-16384 seam. Shared rotary defaults remain unchanged. Pixtral
|
||||
preserves axial height/width rotary, channel-major patch merging, exact GELU and BF16 seams.
|
||||
Only actual `[IMG]` rows receive image embeddings; separator embeddings remain ordinary tokens
|
||||
and participate in pooling. The model-specific operation laws are in [OPS.md](OPS.md).
|
||||
|
||||
**Context and images.** The maximum is 32768 total encoded tokens per input, including prefixes,
|
||||
image placeholders and separators. The backbone's 262144 positional slots do not establish a
|
||||
larger supported embedding context. Inputs are never silently truncated. Configured per-input,
|
||||
combined-token, sequence-slot and image-pass budgets remain separate limits.
|
||||
|
||||
The default longest edge is 1120, without initial enlargement. Reference PIL bicubic resizing
|
||||
aligns dimensions to 28, followed by CLIP normalization and raster 14x14 patches. The default
|
||||
maximum square has 6400 patches and must fit one encoder pass. The published 1540-pixel option
|
||||
and larger image settings are not validated by this port.
|
||||
|
||||
**Verification.** Stored tiny fixtures cover issued graphs, exact preprocessing/token identity,
|
||||
BF16 seams, ragged multimodal inputs, invalid shapes and both head geometries. The regular C++
|
||||
suite needs neither Python nor downloaded checkpoints. Opt-in R9700 entries are
|
||||
`nemotron35_device_test_card` and `r4d_bf16_capacity_test_card`; the latter uses over 8 GiB VRAM
|
||||
to cross actual activation-offset boundaries, with bounded host staging.
|
||||
|
||||
The offline native oracle uses CPU torch 2.14.1, matching torchvision 0.29.1, Transformers 5.20.0
|
||||
and Pillow 13.0.0, explicitly selecting PIL preprocessing and never running remote model code:
|
||||
|
||||
```sh
|
||||
HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 python tests/mknemotron35realreference.py \
|
||||
/models/Nemotron-3.5-Embed-1B-BF16 /tmp/nemotron-reference.json --extended
|
||||
RAD_NEMOTRON_REAL_FIXTURE=/tmp/nemotron-reference.json RAD_NEMOTRON_DEVICE=1 \
|
||||
RADIANCE_HOME="$PWD/build/radiance_home" RAD_TEST_CPU_BUDGET=0 OMP_WAIT_POLICY=passive \
|
||||
build/tests/engine_e2e_test nemotron35_real
|
||||
```
|
||||
|
||||
Use the corresponding native checkpoint for 8B; omit `RAD_NEMOTRON_DEVICE` for CPU execution.
|
||||
`RAD_NEMOTRON_DEVICE_INDEX=1` selects another physical card. Run large checks sequentially; 8B
|
||||
needs roughly 20 GB available host memory. Tiny gates are relative L2 <=.01 and cosine >=.9995.
|
||||
Native gates are cosine >=.9995, normalized L2 <=.032, norm error <=1e-5 and pairwise-score error
|
||||
<=.005, fixed before candidate evaluation. The full-model bound accounts for audited BF16
|
||||
backend sensitivity: eager-vs-SDPA alone reached 2.805% normalized L2 on the 8B samples.
|
||||
Individual/batched vectors must agree within L2 <=1e-5; native ranking margins >.01 must retain
|
||||
their ordering. These gates are not bitwise or broad retrieval-quality guarantees.
|
||||
|
||||
CPU/R9700 comparisons cover both variants; the extended 1B corpus reaches 1924 tokens with
|
||||
English/Spanish/Japanese retrieval groups. Separate synthetic capacity checks cover a complete
|
||||
32768-token input, four full 1B inputs in one 131072-token step and a default maximum image.
|
||||
They do not establish native accuracy at maximum context/resolution. Native INT8/Q8, GGUF and
|
||||
TP2 remain unimplemented.
|
||||
|
||||
---
|
||||
|
||||
# `nomicbert`: an embedding model
|
||||
|
||||
`arch/nomicbert` declares a pooled output (`rad_declare_pooled`) and no logits, so it is an
|
||||
|
||||
+30
-1
@@ -304,6 +304,7 @@ and runs.
|
||||
| `lfm2_bf16` | LiquidAI LFM2 and LFM2-VL in bf16, including d1 (§5.13) |
|
||||
| `embgemma2` | EmbeddingGemma 2, an embedding model (§5.6) |
|
||||
| `nomicbert` | nomic-embed-text-v2-moe, an embedding model (§5.6) |
|
||||
| `nemotron35_embed` | Nemotron 3.5 Embed 1B and 8B, BF16 text/image embeddings at TP1 (§5.6) |
|
||||
| `qwenimage21` | Qwen-Image 2.1 and 2.1-Turbo, an image model (§5.6) |
|
||||
| `krea2` | Krea 2 Raw and Turbo, an image model from text (§5.6) |
|
||||
| `anima` | Anima Base, Aesthetic and Turbo, an anime and illustration image model from text (§5.6) |
|
||||
@@ -2411,7 +2412,7 @@ token ids mixed, with its `add_special` and `parse_special` and their defaults);
|
||||
returns `tokens` as llama-server does, as `{id, piece}` objects with `with_pieces`. `/detokenize`
|
||||
returns the text as both `prompt` (vLLM) and `content` (llama-server).
|
||||
|
||||
**An embedding model** (EmbeddingGemma 2, nomic-embed-text-v2-moe) serves `/v1/embeddings` only;
|
||||
**An embedding model** (EmbeddingGemma 2, nomic-embed-text-v2-moe, Nemotron 3.5 Embed) serves `/v1/embeddings` only;
|
||||
completions and chat answer 501. One input is one vector and must fit one step
|
||||
(`--max-num-batched-tokens`); a longer one is refused with `context_length_exceeded`.
|
||||
|
||||
@@ -2421,6 +2422,34 @@ the directory must contain `tokenizer.json`. The engine adds neither the `search
|
||||
`search_document: ` prefix: the client sends it, or names the checkpoint's prompt with
|
||||
`prompt_name`. The checkpoint's shared `experts.bias` tensors are not applied.
|
||||
|
||||
Nemotron 3.5 Embed 1B and 8B load directly from their native BF16 safetensors snapshots, including
|
||||
the tokenizer, processor and retrieval-prompt files; no conversion is needed. Use the normal
|
||||
HIP/FFmpeg build for R9700 (`-DRAD_WITH_HIP=ON -DRAD_GPU_TARGETS=gfx1201 -DRAD_WITH_FFMPEG=ON`):
|
||||
|
||||
```sh
|
||||
RADIANCE_HOME="$PWD/build/radiance_home" build/bin/radiance \
|
||||
--model /models/Nemotron-3.5-Embed-1B-BF16 --kernels libr4d,libavx --tp 1 \
|
||||
--max-model-len 32768 --max-num-batched-tokens 32768 --max-num-seqs 4 \
|
||||
--mm-max-patches 6400
|
||||
```
|
||||
|
||||
Use the 8B checkpoint path for 8B, or a CPU build and `--kernels libavx` on x86-64. Named prompts
|
||||
are `query` (`query: `) and `document` (`passage: `). Typed text/image inputs and one user message
|
||||
with an optional leading system prefix follow the checkpoint's retrieval template: escaped user
|
||||
text, images before text, exact spacing and no implicit BOS/EOS. Images use data URLs. Raw token
|
||||
arrays are already formatted and receive no named prefix. Custom `--override-chat-template`
|
||||
files are rejected; use a named prompt or system prefix instead.
|
||||
|
||||
The 32768-token maximum counts prefixes, image placeholders and separators. `--max-model-len`
|
||||
may lower it. Four full inputs need `--max-num-batched-tokens 131072 --max-num-seqs 4` to share
|
||||
one step; requests arriving during an active forward wait for the next step. Configured budgets
|
||||
size the arenas, so raising a budget reserves more memory even for smaller requests. The BF16
|
||||
GEMMs use bounded row launches and rebased pointers for tall combined batches, preserving whole
|
||||
attention sequences and existing arithmetic; unsupported multi-launch chains are refused.
|
||||
`--mm-max-patches 6400` covers the default 1120-square image in one encoder pass. See
|
||||
[ARCHITECTURES.md](ARCHITECTURES.md#nemotron35_embed-embedding-models) for geometry, numerical
|
||||
contracts and validation limits.
|
||||
|
||||
```sh
|
||||
# text, a batch of texts, or token ids
|
||||
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
|
||||
|
||||
+41
@@ -218,6 +218,7 @@ at once. Run it before adding a kernel plugin; the loader names only the first c
|
||||
| `clamp` | `M`(range) `n` `dtype` | `x`, `lo`w, `hi`w → `y` |
|
||||
| `conv2d` | `M`(range) `width` `cin` `cout` `kh` `kw` `stride` `pad` `cu_div`/opt `valid_stride`/opt `dtype` `t_last`/opt `act`/opt | `x`, `w`w, `cu_seqlens`, `valid`? → `y`; `b`w? |
|
||||
| `conv2d_unfold` | `M`(range) `width` `cin` `kh` `kw` `stride` `pad` `cu_div`/opt `valid_stride`/opt `t_last`/opt `dtype` | `x`, `cu_seqlens`, `valid`? → `y` |
|
||||
| `pixtral_merge` | `M`(range) `n` `merge` `dtype` | `x`, `coord` → `y` |
|
||||
| `conv1d_dw` | `M`(range) `n` `k` `cu_div`/opt `dtype` | `x`, `w`w, `cu_seqlens` → `y`; `b`w? |
|
||||
| `rel_sinusoid` | `M`(range) `n` `max_timescale`:f64/opt `dtype` | → `y` |
|
||||
| `gelu_mul` | `M`(range) `n` `dtype` | `gate_up` → `y` (splits `[M,2n]` into gelu·up, tanh approx) |
|
||||
@@ -898,6 +899,10 @@ as the weight's GEMM stored them and claims no form. It changes no value.
|
||||
| `rope` | `M`(range) `head_dim` `n_head` `n_head_kv` `theta`:f64 `scale`:f64 `mode` `rotary_dim`/opt `sections`/opt `yarn_factor`:f64/opt `yarn_low`:f64/opt `yarn_high`:f64/opt `yarn_magnitude`:f64/opt `ladder`/opt `llama3_factor`:f64/opt `llama3_low`:f64/opt `llama3_high`:f64/opt `llama3_orig`:f64/opt | `qkv`:inout, `positions` |
|
||||
| `rope_rows` | `M`(range) `head_dim` `n_head` `n_head_kv` `theta`:f64 `scale`:f64 `mode` `rotary_dim`/opt `sections`/opt `yarn_factor`:f64/opt `yarn_low`:f64/opt `yarn_high`:f64/opt `yarn_magnitude`:f64/opt `ladder`/opt `llama3_factor`:f64/opt `llama3_low`:f64/opt `llama3_high`:f64/opt `llama3_orig`:f64/opt | `qkv`:inout, `positions` (the same rotation; at 64+ rows and 4+ heads one angle a (token, pair), byte-identical) |
|
||||
| `rope_table` | `M`(range) `rot` `theta`:f64 `scale`:f64 `dtype` `yarn_factor`:f64/opt `yarn_low`:f64/opt `yarn_high`:f64/opt `yarn_magnitude`:f64/opt `head_dim`/opt `ladder`/opt | `positions` → `cos_sin` |
|
||||
| `position_scale` | `M`(range) `n` `original` `beta`:f64 `dtype` | `x`:inout, `positions` |
|
||||
| `embed_attn` | `M`(range) `head_dim` `gqa` `causal` `max_seqlen`/opt `dtype` `scale`:f64/opt | `q`, `k`, `v`, `cu_seqlens` → `out` |
|
||||
| `ministral_rope` | `M`(range) `head_dim` `n_head` `n_head_kv` `theta`:f64 `dtype` `yarn_factor`:f64/opt `yarn_low`:f64/opt `yarn_high`:f64/opt `yarn_magnitude`:f64/opt | `qkv`:inout, `pos` |
|
||||
| `pixtral_rope` | `M`(range) `head_dim` `n_head` `theta`:f64 `dtype` | `qkv`:inout, `coord` |
|
||||
| `qk_norm_rope` | `M`(range) `head_dim` `n_head` `n_head_kv` `theta`:f64 `eps`:f64 `scale`:f64/opt `mode`/opt `rotary_dim`/opt `wadd`:f64/opt `v_norm`/opt `sections`/opt `comps`/opt | `qkv`:inout, `positions`?, `q_w`w?, `k_w`w? |
|
||||
| `qkv_norm_rope` | `M`(range) `head_dim` `n_head` `n_head_kv` `theta`:f64 `eps`:f64 `scale`:f64/opt `mode`/opt `rotary_dim`/opt `ladder`/opt `wadd`:f64/opt `v_from_k`/opt `v_norm`/opt `dtype` | `q`:inout, `k`:inout, `v`:inout, `positions`, `q_w`w, `k_w`w |
|
||||
| `qkv_norm_rope_kv_store` | `M`(range) `head_dim` `n_head` `n_head_kv` `theta`:f64 `eps`:f64 `scale`:f64/opt `mode`/opt `rotary_dim`/opt `ladder`/opt `wadd`:f64/opt `v_from_k`/opt `dtype` `v_norm`/opt `block_size` `kv_dtype` `k_scale`:f64/opt `v_scale`:f64/opt | `q`:inout, `k`:inout, `v`:inout, `positions`, `q_w`w, `k_w`w, `slot_mapping`, `kv_cache`:inout |
|
||||
@@ -1012,6 +1017,42 @@ prefix of the full-width table: at `head_dim 512, rotary_dim 128`, frequency `i
|
||||
ladders), and the head past `rotary_dim` is untouched either way. `rope_table` takes `head_dim` for
|
||||
the same reason: its angles must stay `rope`'s exactly.
|
||||
|
||||
**`position_scale`** multiplies query row `r` by
|
||||
`1 + beta * log(1 + floor(positions[r] / original))`, rounding the multiplier to the input's
|
||||
dtype before multiplying. It takes a pitched `[M, n]` query view and nonnegative i32 positions;
|
||||
columns outside that view (keys and values in a fused QKV buffer) are unchanged. `original` must
|
||||
be positive and `beta` finite and nonnegative. It currently has host rows for bf16 and f32 only.
|
||||
It implements Ministral 3's query scaling after RoPE; it is independent of YaRN's cos/sin
|
||||
magnitude and does not change existing `rope` behavior.
|
||||
|
||||
**`embed_attn`** serves complete noncausal segments of at most 32768 rows. QK dot products
|
||||
are rounded to the activation dtype, multiplied by `scale` (default `1/sqrt(head_dim)`) and
|
||||
rounded again. Softmax is float32; its probabilities are rounded to the activation dtype before
|
||||
the value product. This reproduces the eager BF16 materialization boundaries used by the
|
||||
Nemotron reference. `causal` must be zero. Existing `attn_dense` semantics are unchanged.
|
||||
|
||||
**`ministral_rope`** rotates the Q and K heads of fused QKV rows with NeoX pairing and the
|
||||
resolved YaRN frequency ladder. Cosine/sine are rounded to the activation dtype, as are each
|
||||
of the two products before addition/subtraction, matching Ministral's BF16 rotary expression.
|
||||
V heads are unchanged. Active rows come from the issued tensor views; `M` is the capacity band.
|
||||
This separate operation preserves every existing `rope` implementation and schema.
|
||||
|
||||
**`pixtral_rope`** rotates Q and K of `[M, 3 * n_head * head_dim]` fused QKV rows, leaving V
|
||||
unchanged. `coord` is `[2, M]` nonnegative i32 `(height, width)` patch coordinates. The head
|
||||
dimension must be divisible by four. NeoX pairs `(i, i + head_dim/2)` use the height ladder
|
||||
`theta^(-4j/head_dim)` for `i = j < head_dim/4`, then the width ladder
|
||||
`theta^(-(4j+2)/head_dim)` for `i = j + head_dim/4`. In BF16, cos/sin and each product are
|
||||
rounded before the addition, as in Transformers. Host rows support BF16 and f32. This is a
|
||||
separate contract from `rope`'s existing axial mode, whose two ladders are identical.
|
||||
|
||||
**`pixtral_merge`** packs `[M, n]` raster patch rows into `[M / merge^2, n * merge^2]` rows.
|
||||
`coord` is `[4, M]` i32 `(row, column, height, width)` patch coordinates; it must describe whole
|
||||
raster grids, each side divisible by `merge`. Images may have different widths. One output row
|
||||
is a merged spatial cell with columns `(channel, dy, dx)`, matching PyTorch `unfold`; values
|
||||
are copied exactly. The complete coordinates are validated before writing, so invalid grids
|
||||
leave the output unchanged. Host rows support BF16 and f32. Automatic random shape fixtures
|
||||
cannot supply this coupled coordinate grid; callers must provide a valid grid fixture.
|
||||
|
||||
**`qk_norm_rope`** RMS-norms each q and k head of a fused `[q | k | v]` row against its gain (plus
|
||||
`wadd`), rounds, and rotates in place. `positions` is read as `rope` reads it, integer or f32.
|
||||
|
||||
|
||||
+4
-3
@@ -397,9 +397,10 @@ says so with `RAD_ARCH_SERVES_IMPORTS(0)` (`qwen35_w8a8` does), and imports keep
|
||||
below it. The pass's block is `n_tok / n_seq`; a block the plugin has no ops for should fail the
|
||||
step (`rad_block_dflash2.h` does). Appended in ABI 27.
|
||||
- **Media preprocessing is the core's** (`core/mm`): resizing, patching, placeholder-token
|
||||
expansion and positions, in five processor families (Qwen-VL, Gemma 4, LFM2-VL, Unlimited-OCR,
|
||||
GLM-5.3) chosen by the container's `vision_config.model_type` (Unlimited-OCR's by its
|
||||
`model_type`). A vision model with another pipeline needs a core change.
|
||||
expansion and positions, in six processor families (Qwen-VL, Gemma 4, LFM2-VL, Unlimited-OCR,
|
||||
GLM-5.3 and Pixtral for Nemotron 3.5) chosen by the container's `vision_config.model_type`
|
||||
and owning-model checks (Unlimited-OCR's by its `model_type`). A vision model with another
|
||||
pipeline needs a core change.
|
||||
Audio goes through one of two feature extractors, Gemma 4's and Qwen3-ASR's (Whisper's), chosen
|
||||
by `audio_config.model_type`.
|
||||
- **A speech model says how it hears**, through the optional
|
||||
|
||||
Reference in new issue
Block a user