nx_bert_ce_lib.nx
buildroot/runtime/nx_bert_ce_lib.nx
about
nx_bert_ce_lib.nx -- SOVEREIGN BERT cross-encoder (BertForSequenceClassification with one logit) composed from
the estate's own f32 tower: nx_safetensors_load (weights), vit_mhsa and vit_mhsa_pool (multi-head attention
with biases, the ViT block's kernel), nx_f32_layernorm, nx_f32_matmul_t and its pooled twin, nx_f32_gelu_vec and
nx_f32_tanh. The model is a LICENSED DATA ASSET (Apache-2.0, mirrored with provenance under knowledge/fetched/)
read by NishiLang from the first byte; nothing foreign executes. BERT differs from the ViT block already in the
tree in three places and only those are written here: POST-norm residuals (LayerNorm after each add), an
embedding layer of word + absolute position + token type followed by LayerNorm, and the pooler (tanh of a dense
over the [CLS] row) with the classifier. Depth, width, heads, intermediate size, position count and the LayerNorm
epsilon are read from the model's config.json at load, never from a constant. Search rung R0, 2026-09-14.
license_tier: ORIGINAL
dependencies 11 imports · 2 importers
diagram shows first 10 each side; +1 more imports, +0 more importers in the complete lists below.
imports: nx_syscalls.nxnx_f32.nxnx_f32_cvt.nxnx_f32_div.nxnx_f32_activations.nxnx_f32_matmul_t.nxnx_f32_layernorm.nxnx_f32_gelu.nxnx_thread_pool.nxnx_safetensors_load.nxnx_vit_encoder_layer.nx
imported by: nx_beir_eval.nxnx_bert_ce_gate.nx
structs
| none |
consts
| 24 | const BC_G_HID: i64 = 0 |
| 25 | const BC_G_LAYERS: i64 = 1 |
| 26 | const BC_G_HEADS: i64 = 2 |
| 27 | const BC_G_INTER: i64 = 3 |
| 28 | const BC_G_MAXPOS: i64 = 4 |
| 29 | const BC_G_VOCAB: i64 = 5 |
| 30 | const BC_G_EPS: i64 = 6 // f32 bits, from config layer_norm_eps |
| 31 | const BC_G_SCALE: i64 = 7 // f32 bits, 1 / sqrt(head_dim) |
| 32 | const BC_G_WEMB: i64 = 8 |
| 33 | const BC_G_PEMB: i64 = 9 |
| 34 | const BC_G_TEMB: i64 = 10 |
| 35 | const BC_G_ELNG: i64 = 11 |
| 36 | const BC_G_ELNB: i64 = 12 |
| 37 | const BC_G_LAYERW: i64 = 13 // *i64, BC_L_SLOTS pointers per layer |
| 38 | const BC_G_POOLW: i64 = 14 |
| 39 | const BC_G_POOLB: i64 = 15 |
| 40 | const BC_G_CLSW: i64 = 16 |
| 41 | const BC_G_CLSB: i64 = 17 |
| 42 | const BC_G_LOADED: i64 = 18 |
| 43 | const BC_G_MISSING: i64 = 19 // *u8 name of the first tensor or field that failed, for the announce |
| 44 | const BC_G_POOL: i64 = 20 // *NxThreadPool, or 0 for the serial path |
| 45 | const BC_G_SLOTS: i64 = 21 |
| 46 | const BC_G_BYTES: i64 = 168 |
| 48 | const BC_L_WQ: i64 = 0 |
| 49 | const BC_L_BQ: i64 = 1 |
| 50 | const BC_L_WK: i64 = 2 |
| 51 | const BC_L_BK: i64 = 3 |
| 52 | const BC_L_WV: i64 = 4 |
| 53 | const BC_L_BV: i64 = 5 |
| 54 | const BC_L_WO: i64 = 6 |
| 55 | const BC_L_BO: i64 = 7 |
| 56 | const BC_L_LN1G: i64 = 8 |
| 57 | const BC_L_LN1B: i64 = 9 |
| 58 | const BC_L_W1: i64 = 10 |
| 59 | const BC_L_B1: i64 = 11 |
| 60 | const BC_L_W2: i64 = 12 |
| 61 | const BC_L_B2: i64 = 13 |
| 62 | const BC_L_LN2G: i64 = 14 |
| 63 | const BC_L_LN2B: i64 = 15 |
| 64 | const BC_L_SLOTS: i64 = 16 |
| 66 | const BC_NAME_CAP: i64 = 256 |
| 67 | const BC_DTYPE_CAP: i64 = 16 |
| 68 | const BC_DECIMAL: i64 = 10 |
| 69 | const BC_ASCII_ZERO: i64 = 48 |
| 70 | const BC_ASCII_NINE: i64 = 57 |
| 71 | const BC_COLON: i64 = 58 |
| 72 | const BC_SPACE: i64 = 32 |
| 73 | const BC_MINUS: i64 = 45 |
| 74 | const BC_PLUS: i64 = 43 |
| 75 | const BC_DOT: i64 = 46 |
| 76 | const BC_LOWER_E: i64 = 101 |
| 77 | const BC_UPPER_E: i64 = 69 |
| 78 | const BC_MILLI: i64 = 1000 |
| 79 | const BC_MICRO: i64 = 1000000 |
functions
| 82 | func bc_skip_to_value(buf: *u8, n: i64, key: *u8) -> i64 |
| 94 | func bc_cfg_int(buf: *u8, n: i64, key: *u8) -> i64 |
| 101 | func bc_is_digit(c: i64) -> i64 { if c >= BC_ASCII_ZERO { if c <= BC_ASCII_NINE { return 1 } } return 0 } called by 1: bc_cfg_f32 |
| 104 | func bc_cfg_f32(buf: *u8, n: i64, key: *u8) -> i64 |
| 137 | func bc_tensor(buf: *u8, hlen: i64, dstart: i64, name: *u8, dt: *u8, offs: *i64) -> i64 |
| 147 | func bc_cat(dst: *u8, pos: i64, s: *u8) -> i64 called by 1: bc_lname |
| 154 | func bc_lname(scr: *u8, layer: i64, suffix: *u8) -> i64 |
| 168 | func bc_fail(g: *i64, name: *u8) -> i64 |
| 180 | func bc_lload(lw: *i64, mb: *u8, hlen: i64, dstart: i64, scr: *u8, layer: i64, slot: i64, suffix: *u8, dt: *u8, offs: *i64) -> i64 |
| 189 | func bc_load(g: *i64, model_path: *u8, config_path: *u8) -> i64 |
| 275 | func bc_forward(g: *i64, ids: *i64, types: *i64, T: i64) -> i64 called by 2: _be_ce_taskmain calls 7: sys_mmapnx_f32_layernormnx_f32_matmul_t_poolnx_f32_matmul_tnx_f32_gelu_vecnx_f32_tanh+1 |
| 345 | func bc_f32_milli(x: i64) -> i64 { return __f32_to_i64(__f32_mul(x, __f32_from_i64(BC_MILLI))) } called by 1: main |
| 346 | func bc_f32_micro(x: i64) -> i64 { return __f32_to_i64(__f32_mul(x, __f32_from_i64(BC_MICRO))) } called by 1: _be_ce_task |