code wiki / (root) / nx_bert_ce_lib.nx

nx_bert_ce_lib.nx

buildroot/runtime/nx_bert_ce_lib.nx

17919 B346 linesdepth 9pulls 24 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_f32.nx nx_f32_cvt.nx nx_f32_div.nx nx_f32_activations.nx nx_f32_matmul_t.nx nx_f32_layernorm.nx nx_f32_gelu.nx nx_thread_pool.nx nx_safetensors_load.nx nx_bert_ce_lib.nx nx_beir_eval.nx nx_bert_ce_gate.nx

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

24const BC_G_HID: i64 = 0
25const BC_G_LAYERS: i64 = 1
26const BC_G_HEADS: i64 = 2
27const BC_G_INTER: i64 = 3
28const BC_G_MAXPOS: i64 = 4
29const BC_G_VOCAB: i64 = 5
30const BC_G_EPS: i64 = 6 // f32 bits, from config layer_norm_eps
31const BC_G_SCALE: i64 = 7 // f32 bits, 1 / sqrt(head_dim)
32const BC_G_WEMB: i64 = 8
33const BC_G_PEMB: i64 = 9
34const BC_G_TEMB: i64 = 10
35const BC_G_ELNG: i64 = 11
36const BC_G_ELNB: i64 = 12
37const BC_G_LAYERW: i64 = 13 // *i64, BC_L_SLOTS pointers per layer
38const BC_G_POOLW: i64 = 14
39const BC_G_POOLB: i64 = 15
40const BC_G_CLSW: i64 = 16
41const BC_G_CLSB: i64 = 17
42const BC_G_LOADED: i64 = 18
43const BC_G_MISSING: i64 = 19 // *u8 name of the first tensor or field that failed, for the announce
44const BC_G_POOL: i64 = 20 // *NxThreadPool, or 0 for the serial path
45const BC_G_SLOTS: i64 = 21
46const BC_G_BYTES: i64 = 168
48const BC_L_WQ: i64 = 0
49const BC_L_BQ: i64 = 1
50const BC_L_WK: i64 = 2
51const BC_L_BK: i64 = 3
52const BC_L_WV: i64 = 4
53const BC_L_BV: i64 = 5
54const BC_L_WO: i64 = 6
55const BC_L_BO: i64 = 7
56const BC_L_LN1G: i64 = 8
57const BC_L_LN1B: i64 = 9
58const BC_L_W1: i64 = 10
59const BC_L_B1: i64 = 11
60const BC_L_W2: i64 = 12
61const BC_L_B2: i64 = 13
62const BC_L_LN2G: i64 = 14
63const BC_L_LN2B: i64 = 15
64const BC_L_SLOTS: i64 = 16
66const BC_NAME_CAP: i64 = 256
67const BC_DTYPE_CAP: i64 = 16
68const BC_DECIMAL: i64 = 10
69const BC_ASCII_ZERO: i64 = 48
70const BC_ASCII_NINE: i64 = 57
71const BC_COLON: i64 = 58
72const BC_SPACE: i64 = 32
73const BC_MINUS: i64 = 45
74const BC_PLUS: i64 = 43
75const BC_DOT: i64 = 46
76const BC_LOWER_E: i64 = 101
77const BC_UPPER_E: i64 = 69
78const BC_MILLI: i64 = 1000
79const BC_MICRO: i64 = 1000000

functions

82func bc_skip_to_value(buf: *u8, n: i64, key: *u8) -> i64
called by 2: bc_cfg_intbc_cfg_f32 calls 1: stl_find
94func bc_cfg_int(buf: *u8, n: i64, key: *u8) -> i64
101func 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
104func bc_cfg_f32(buf: *u8, n: i64, key: *u8) -> i64
137func bc_tensor(buf: *u8, hlen: i64, dstart: i64, name: *u8, dt: *u8, offs: *i64) -> i64
147func bc_cat(dst: *u8, pos: i64, s: *u8) -> i64
called by 1: bc_lname
154func bc_lname(scr: *u8, layer: i64, suffix: *u8) -> i64
called by 1: bc_lload calls 1: bc_cat
168func bc_fail(g: *i64, name: *u8) -> i64
called by 1: bc_load calls 1: sys_mmap
180func bc_lload(lw: *i64, mb: *u8, hlen: i64, dstart: i64, scr: *u8, layer: i64, slot: i64, suffix: *u8, dt: *u8, offs: *i64) -> i64
called by 1: bc_load calls 2: bc_lnamebc_tensor
189func bc_load(g: *i64, model_path: *u8, config_path: *u8) -> i64
275func bc_forward(g: *i64, ids: *i64, types: *i64, T: i64) -> i64
345func bc_f32_milli(x: i64) -> i64 { return __f32_to_i64(__f32_mul(x, __f32_from_i64(BC_MILLI))) }
called by 1: main
346func bc_f32_micro(x: i64) -> i64 { return __f32_to_i64(__f32_mul(x, __f32_from_i64(BC_MICRO))) }
called by 1: _be_ce_task