yyhhyyyyyy on X asked for CoreML. internal/pii/guard now runs the encoder (everything after the embeddings) as a CoreML program on a Mac with macOS 13 or later, on the Neural Engine or GPU (MLComputeUnitsAll). bert.go still does the embeddings and stays the path everywhere else. - coreml_gen.py builds the program with coremltools' MIL builder from the pinned int8 model: the int8 weights dequantized, float16 compute. The repo keeps only the graph (coreml.mlmodel, 112KB) and coreml.json (each blob's offset, weight.bin's size and sha256). On each Mac the weights are written from the model already downloaded (coremlWeights, float16 rounded to nearest even as numpy does), checked against that sha256, compiled once into <model dir>/coreml/<sha>.mlmodelc (about 5s, 41MB), and opened from there after that (40-170ms). Nothing new is downloaded or hosted. - The cgo lives in internal/pii/guard/coreml, because guard has Go assembly. Without cgo or off darwin it is a stub (Available false). - A window under 16 tokens (coremlMin) stays on the CPU, which is faster there (8 tokens: 8.7ms CPU, 12.5ms CoreML; 16: 17 vs 13). A Mac before macOS 13, a failed write, compile or open, or a failed run goes to the CPU too. Model.MLErr keeps why. Accuracy against the publisher's fp32 ONNX (onnxruntime): CoreML's probabilities are within .067, the CPU's within .129, and both agree with fp32's labels on the same tokens. The CPU quantizes activations as the int8 model does and CoreML doesn't; fake quantization in the program was tried and didn't match the CPU (.75 on CPU fp32, .70 on GPU, unstable in fp16), so it was dropped. A span near the threshold can fall the other side: TestModelFinds' go.mod module path is a common_secret at .814 on CoreML, .788 on the CPU and .785 in fp32, so on a Mac it is masked at the default 0.8. TestModelFinds now tests bert.go alone (m.ml = nil), and TestCoreMLMatchesGo holds CoreML to it. Run (M4 Pro, macOS 26.2, under load ~50): - gofmt -l internal/pii: clean. go vet ./internal/pii/... with GOOS darwin, linux, windows and CGO_ENABLED=0: clean. - MAGPIE_GUARD_DIR=<pinned model> go test ./internal/pii/... ./internal/redact/... ./internal/masking/... -count=1: ok. In guard: TestHalfRounds, TestCoreMLWeights (weight.bin's sha256), TestCoreMLMatchesGo (99%+ argmax agreement on a 512-token window, the same spans as the CPU with scores within .2; loaded in 6.3s cold, 17ms for 512 tokens), TestCoreMLFailureFallsBack and TestModelFinds. - TestMaskEval/astrlink-guard replayed with outputs recorded through CoreML: the same verdicts at the default threshold; scores moved a little and one account_number span at .508 is new, under 0.8. eval-astrlink.json stays the CPU's recording. Broken by hand: half() rounding ties up instead of to even turns TestHalfRounds red; a wrong sha256 in coreml.json makes Load fall back to the CPU with MLErr set, find the same spans and leave the compiled program in place (TestCoreMLFailureFallsBack). Not tried: an Intel Mac, macOS 13 or 14 (only 26.2), the real app's GUI with Find with a local model on (the gateway path calls the same Find).
161 lines
4.3 KiB
JSON
161 lines
4.3 KiB
JSON
{"size": 42650346, "sha256": "267f9b34318dc952731157200451833e60fa66a7dbe1f5b5dfa4ae9b3aba3314", "blobs": [
|
|
["l0_qkv_weight", 64],
|
|
["l0_qkv_bias", 884864],
|
|
["l0_ao_weight", 887232],
|
|
["l0_ao_bias", 1182208],
|
|
["l0_ln1_gamma", 1183040],
|
|
["l0_ln1_beta", 1183872],
|
|
["l0_up_weight", 1184704],
|
|
["l0_up_bias", 2364416],
|
|
["l0_smooth_y", 2367552],
|
|
["l0_dn_weight", 2370688],
|
|
["l0_dn_bias", 3550400],
|
|
["l0_ln2_gamma", 3551232],
|
|
["l0_ln2_beta", 3552064],
|
|
["l1_qkv_weight", 3552896],
|
|
["l1_qkv_bias", 4437696],
|
|
["l1_ao_weight", 4440064],
|
|
["l1_ao_bias", 4735040],
|
|
["l1_ln1_gamma", 4735872],
|
|
["l1_ln1_beta", 4736704],
|
|
["l1_up_weight", 4737536],
|
|
["l1_up_bias", 5917248],
|
|
["l1_smooth_y", 5920384],
|
|
["l1_dn_weight", 5923520],
|
|
["l1_dn_bias", 7103232],
|
|
["l1_ln2_gamma", 7104064],
|
|
["l1_ln2_beta", 7104896],
|
|
["l2_qkv_weight", 7105728],
|
|
["l2_qkv_bias", 7990528],
|
|
["l2_ao_weight", 7992896],
|
|
["l2_ao_bias", 8287872],
|
|
["l2_ln1_gamma", 8288704],
|
|
["l2_ln1_beta", 8289536],
|
|
["l2_up_weight", 8290368],
|
|
["l2_up_bias", 9470080],
|
|
["l2_smooth_y", 9473216],
|
|
["l2_dn_weight", 9476352],
|
|
["l2_dn_bias", 10656064],
|
|
["l2_ln2_gamma", 10656896],
|
|
["l2_ln2_beta", 10657728],
|
|
["l3_qkv_weight", 10658560],
|
|
["l3_qkv_bias", 11543360],
|
|
["l3_ao_weight", 11545728],
|
|
["l3_ao_bias", 11840704],
|
|
["l3_ln1_gamma", 11841536],
|
|
["l3_ln1_beta", 11842368],
|
|
["l3_up_weight", 11843200],
|
|
["l3_up_bias", 13022912],
|
|
["l3_smooth_y", 13026048],
|
|
["l3_dn_weight", 13029184],
|
|
["l3_dn_bias", 14208896],
|
|
["l3_ln2_gamma", 14209728],
|
|
["l3_ln2_beta", 14210560],
|
|
["l4_qkv_weight", 14211392],
|
|
["l4_qkv_bias", 15096192],
|
|
["l4_ao_weight", 15098560],
|
|
["l4_ao_bias", 15393536],
|
|
["l4_ln1_gamma", 15394368],
|
|
["l4_ln1_beta", 15395200],
|
|
["l4_up_weight", 15396032],
|
|
["l4_up_bias", 16575744],
|
|
["l4_smooth_y", 16578880],
|
|
["l4_dn_weight", 16582016],
|
|
["l4_dn_bias", 17761728],
|
|
["l4_ln2_gamma", 17762560],
|
|
["l4_ln2_beta", 17763392],
|
|
["l5_qkv_weight", 17764224],
|
|
["l5_qkv_bias", 18649024],
|
|
["l5_ao_weight", 18651392],
|
|
["l5_ao_bias", 18946368],
|
|
["l5_ln1_gamma", 18947200],
|
|
["l5_ln1_beta", 18948032],
|
|
["l5_up_weight", 18948864],
|
|
["l5_up_bias", 20128576],
|
|
["l5_smooth_y", 20131712],
|
|
["l5_dn_weight", 20134848],
|
|
["l5_dn_bias", 21314560],
|
|
["l5_ln2_gamma", 21315392],
|
|
["l5_ln2_beta", 21316224],
|
|
["l6_qkv_weight", 21317056],
|
|
["l6_qkv_bias", 22201856],
|
|
["l6_ao_weight", 22204224],
|
|
["l6_ao_bias", 22499200],
|
|
["l6_ln1_gamma", 22500032],
|
|
["l6_ln1_beta", 22500864],
|
|
["l6_up_weight", 22501696],
|
|
["l6_up_bias", 23681408],
|
|
["l6_smooth_y", 23684544],
|
|
["l6_dn_weight", 23687680],
|
|
["l6_dn_bias", 24867392],
|
|
["l6_ln2_gamma", 24868224],
|
|
["l6_ln2_beta", 24869056],
|
|
["l7_qkv_weight", 24869888],
|
|
["l7_qkv_bias", 25754688],
|
|
["l7_ao_weight", 25757056],
|
|
["l7_ao_bias", 26052032],
|
|
["l7_ln1_gamma", 26052864],
|
|
["l7_ln1_beta", 26053696],
|
|
["l7_up_weight", 26054528],
|
|
["l7_up_bias", 27234240],
|
|
["l7_smooth_y", 27237376],
|
|
["l7_dn_weight", 27240512],
|
|
["l7_dn_bias", 28420224],
|
|
["l7_ln2_gamma", 28421056],
|
|
["l7_ln2_beta", 28421888],
|
|
["l8_qkv_weight", 28422720],
|
|
["l8_qkv_bias", 29307520],
|
|
["l8_ao_weight", 29309888],
|
|
["l8_ao_bias", 29604864],
|
|
["l8_ln1_gamma", 29605696],
|
|
["l8_ln1_beta", 29606528],
|
|
["l8_up_weight", 29607360],
|
|
["l8_up_bias", 30787072],
|
|
["l8_smooth_y", 30790208],
|
|
["l8_dn_weight", 30793344],
|
|
["l8_dn_bias", 31973056],
|
|
["l8_ln2_gamma", 31973888],
|
|
["l8_ln2_beta", 31974720],
|
|
["l9_qkv_weight", 31975552],
|
|
["l9_qkv_bias", 32860352],
|
|
["l9_ao_weight", 32862720],
|
|
["l9_ao_bias", 33157696],
|
|
["l9_ln1_gamma", 33158528],
|
|
["l9_ln1_beta", 33159360],
|
|
["l9_up_weight", 33160192],
|
|
["l9_up_bias", 34339904],
|
|
["l9_smooth_y", 34343040],
|
|
["l9_dn_weight", 34346176],
|
|
["l9_dn_bias", 35525888],
|
|
["l9_ln2_gamma", 35526720],
|
|
["l9_ln2_beta", 35527552],
|
|
["l10_qkv_weight", 35528384],
|
|
["l10_qkv_bias", 36413184],
|
|
["l10_ao_weight", 36415552],
|
|
["l10_ao_bias", 36710528],
|
|
["l10_ln1_gamma", 36711360],
|
|
["l10_ln1_beta", 36712192],
|
|
["l10_up_weight", 36713024],
|
|
["l10_up_bias", 37892736],
|
|
["l10_smooth_y", 37895872],
|
|
["l10_dn_weight", 37899008],
|
|
["l10_dn_bias", 39078720],
|
|
["l10_ln2_gamma", 39079552],
|
|
["l10_ln2_beta", 39080384],
|
|
["l11_qkv_weight", 39081216],
|
|
["l11_qkv_bias", 39966016],
|
|
["l11_ao_weight", 39968384],
|
|
["l11_ao_bias", 40263360],
|
|
["l11_ln1_gamma", 40264192],
|
|
["l11_ln1_beta", 40265024],
|
|
["l11_up_weight", 40265856],
|
|
["l11_up_bias", 41445568],
|
|
["l11_smooth_y", 41448704],
|
|
["l11_dn_weight", 41451840],
|
|
["l11_dn_bias", 42631552],
|
|
["l11_ln2_gamma", 42632384],
|
|
["l11_ln2_beta", 42633216],
|
|
["logits_weight", 42634048],
|
|
["logits_bias", 42650240]
|
|
]}
|