nomicbert: architecture plugin for nomic-embed-text-v2-moe

Post-norm encoder with fused Wqkv and biases, NeoX rotary, non-causal attention, a dense MLP on even layers and a top-2 of 8 expert MLP on odd layers, mean pooling into the pooled f32 buffer for /v1/embeddings. The checkpoint is f32; data/recipes/nomic-embed-v2-moe-bf16.recipe casts the linears, the token embedding and the token-type table to bf16 (the device kernels read bf16), norms and biases stay f32. The checkpoint's shared experts.bias is not applied: against a llama.cpp run of the same checkpoint at Q8_0 the variant without it matches best (cosine 0.9994; the others 0.9990 to 0.9993), and llama.cpp's own nomic-bert-moe does not carry it. Verified on a gfx1201 card and on libavx/libref against a pure-float32 torch reference: mean cosine 0.99995, min 0.99983 over 20 texts. Unit tests declare and lint a cut-down model. Not verified: inputs above 512 tokens against a reference on the device, other quantisations.
This commit is contained in:
Boris Manojlovic authored and StillDeadcode committed 2026-10-27 20:58:47 +01:00
1 parent 4853db97db
commit fd40bb430c
8 files changed
+865 -4

No files matched your search

@@ -0,0 +1,24 @@
# nomic-embed-v2-moe-bf16.recipe -- nomic-embed-text-v2-moe from the HF checkpoint, as the
# nomicbert plugin serves it.
#
# rad-convert /data --recipe data/recipes/nomic-embed-v2-moe-bf16.recipe -o nomic.rad
#
# The checkpoint stores every tensor f32 (config.json says torch_dtype float32). The plugin runs
# the linears, the token table and the token-type table in bf16 and keeps norms and biases f32, so
# this recipe casts exactly the weights that plugin declares bf16. Without it rad-convert refuses
# the checkpoint at declare: a declare-time bf16 weight cannot hold an f32 checkpoint's codes.
#
# token_type.weight is bf16 because libr4d's table_add_bf16 reads a bf16 table; libref's and
# libavx's table_add read any dtype the tensor carries, so the same container serves all three.
# The checkpoint's mlp.experts.bias tensors are not mapped by the plugin at all and do not appear
# in the plan.
token_embd.weight cast dtype=bf16
token_type.weight cast dtype=bf16
blk.*.attn_qkv.weight cast dtype=bf16
blk.*.attn_out.weight cast dtype=bf16
blk.*.ffn_fc1.weight cast dtype=bf16
blk.*.ffn_fc2.weight cast dtype=bf16
blk.*.ffn_router.weight cast dtype=bf16
blk.*.ffn_exp_w1.*.weight cast dtype=bf16
blk.*.ffn_exp_w2.*.weight cast dtype=bf16