nemotron 3.5 rerank 8b implementation

This commit is contained in:
Gaspa79 committed 2026-10-30 09:47:42 -03:00
1 parent d773992abc
commit 74e7fddd79
35 files changed
+1788 -90

No files matched your search

+34 -1
View File
@@ -21,7 +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/nemotron35_embed` | `mistral3` | *(empty)* | Nemotron 3.5 Embed 1B/8B and Rerank 8B: native BF16 bidirectional text/image retrieval with a Pixtral tower, 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 |
@@ -935,6 +935,39 @@ English/Spanish/Japanese retrieval groups. Separate synthetic capacity checks co
They do not establish native accuracy at maximum context/resolution. Native INT8/Q8, GGUF and
TP2 remain unimplemented.
**Nemotron 3.5 Rerank 8B.** The same plugin recognizes the native
`Mistral3ForSequenceClassification` checkpoint, pinned at
`f88f8d9104726747791283ab156d2fcdb29e90a7`. It uses its own weights, the 8B text/vision
geometry above under `model.*`, and a bias-free `language_model.score.weight` [1,4096] head. Native
pooling stores the masked sum in BF16 before division, then stores the mean in BF16.
The separate `seg_mean_bf16_sum` operation preserves this seam without changing
embedding pooling. `logits_gemm` projects the mean and BF16 head to an FP32 scalar;
this is pooled output, with no generation sampler or KV cache. The endpoints return
raw logits, including negative values, rather than normalized embeddings.
The supported per-pair context remains 32768, including query/document prefixes and
images. The native training template requires text queries and at most one image
per document. The image, context and configured capacity distinctions above apply.
Stored tiny reranker fixtures and the opt-in native reference generator are
`tests/mknemotron35rerankgolden.py` and `tests/mknemotron35rerankrealreference.py`.
Both are offline tools; runtime/build/tests never download a checkpoint or execute
remote model code. CPU component gates include exact BF16 pool results and scalar
error <=.01 for the tiny text/image graphs. Native validation uses raw-score error
and ranking gates rather than embedding cosine tolerances.
```sh
python3 tests/mknemotron35rerankrealreference.py /models/Nemotron-3.5-Rerank-8B-BF16 /tmp/rerank-reference.json --sdpa-audit
RAD_NEMOTRON_RERANK_REAL_FIXTURE=/tmp/rerank-reference.json \
RAD_NEMOTRON_DEVICE=1 RADIANCE_HOME="$PWD/build/radiance_home" \
build/tests/engine_e2e_test nemotron35_rerank_real
```
Download the pinned revision above; an optional local `asset-manifest.json` is verified
when present. Standard Hugging Face revision metadata is also recognized; absent metadata
is recorded as unknown. The full-model gates are raw-score maximum absolute error <=.05,
RMSE <=.02, individual/batched difference <=1e-5 and preserved ranking for native margins
>.10. Omit `RAD_NEMOTRON_DEVICE` for CPU execution, as above.
---
# `nomicbert`: an embedding model
+26 -1
View File
@@ -304,7 +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) |
| `nemotron35_embed` | Nemotron 3.5 Embed 1B/8B and Rerank 8B, BF16 text/image retrieval 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) |
@@ -2450,6 +2450,31 @@ attention sequences and existing arithmetic; unsupported multi-launch chains are
[ARCHITECTURES.md](ARCHITECTURES.md#nemotron35_embed-embedding-models) for geometry, numerical
contracts and validation limits.
**Nemotron 3.5 Rerank 8B BF16** uses the same architecture plugin with its own native
checkpoint and learned scalar head. Serve it with `--max-model-len 32768` and enough
`--max-num-batched-tokens` for each whole query/document pair. It serves `POST /rerank`
and `/v1/rerank`, using the vLLM/Jina-style request and result fields:
```sh
curl -s http://localhost:8000/rerank -H 'Content-Type: application/json' \
-d '{"query":"Where can I borrow books?","documents":["A public library lends books.","A football match."],"top_n":2}'
```
Each result has the original document `index`, a raw `relevance_score` (higher is more
relevant), and `document`. Scores may be negative; no sigmoid, L2 normalization or
dimensional truncation applies. Results are sorted descending, with ties retaining
input order. `top_n` omitted or zero returns all documents; `return_documents:false`
omits document contents. Token usage includes all scored pairs, even with `top_n`.
Queries are text strings. A document is a string, or `{"content":[...]}` containing
typed `text` and `image_url` blocks, with an image data URL as for embeddings. At most
one image is allowed per document. The checkpoint's exact `query`/`document` template
places its image first, escapes literal controls and adds no BOS/EOS. The 32768-token
limit covers query, document, prefixes and image tokens together. Overlong pairs are
rejected, never truncated. Custom instructions, template overrides and activation
options that change the native score are refused. This model does not serve
`/v1/embeddings`; the embedding checkpoints continue to use that endpoint unchanged.
```sh
# text, a batch of texts, or token ids
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
+8
View File
@@ -212,6 +212,7 @@ at once. Run it before adding a kernel plugin; the loader names only the first c
| `mul_weight` | `M`(range) `n` `dtype` `scalar`/opt | `x`, `w`w → `y` (w one element or one row) |
| `act_mul` | `M`(range) `n` `act` `dtype` | `a`, `b` → `y` (act(a)·b, two operands) |
| `seg_mean` | `M`(range) `n` `dtype` | `x`, `cu_seqlens` → `y` (one mean row a segment) |
| `seg_mean_bf16_sum` | `M`(range) `n` `dtype` | `x`, `cu_seqlens` → `y` (BF16 sum, then BF16 quotient) |
| `pool_rows` | `M`(range) `n` `k` `mult`:f64/opt `dtype` | `x` → `y` (one mean row a window of k rows) |
| `pool_cols` | `M`(range) `n` `k` `mult`:f64/opt `dtype` | `x` → `y` (one mean column a window of k columns) |
| `relu` | `M`(range) `n` `dtype` | `x` → `y` |
@@ -291,6 +292,13 @@ rounded to `y`'s dtype before the product, as the unfused pair stores it.
`[cu[s], cu[s+1])`, summed in double and rounded once. `M` is the step's token count and bands the
op; the segment count is `cu_seqlens`' length less one. An empty segment is a zero row.
**`seg_mean_bf16_sum`** preserves the two BF16 stores of Nemotron 3.5 Rerank's masked
mean: sum the segment in f32, round the sum to BF16, divide by its valid-token count,
then round the quotient to BF16. Input and output are BF16; cumulative lengths are
int32, begin at zero, end at the active input row count and describe nonempty segments.
Pitched rows are supported. This is a separate operation so `seg_mean` and existing
embedding models keep their one-rounding contract.
**`pool_rows`** is a vision pooler over windows laid out consecutively: row `r` of `y` is the mean
of `x`'s rows `[r*k, r*k + k)`, summed in f32 and rounded to `y`'s dtype, then times `mult` and
rounded again (the unfused pair stores the mean). `M` is the input row count, a multiple of `k`.