oamazonasgabriel commited on
Commit
bf7aa79
·
verified ·
1 Parent(s): a6e58bc

Upload fine-tuned bunker-laya checkpoint + ONNX (transformers.js)

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ onnx/model.onnx.data filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers.js
3
+ base_model: convaiinnovations/laya
4
+ license: apache-2.0
5
+ tags:
6
+ - laya
7
+ - onnx
8
+ - guardrails
9
+ - pii
10
+ - prompt-injection
11
+ - text-classification
12
+ - transformers.js
13
+ ---
14
+
15
+ # impacte/bunker-laya
16
+
17
+ Fine-tuned [`convaiinnovations/laya`](https://huggingface.co/convaiinnovations/laya)
18
+ for the [`opencode-bunker`](https://github.com/impacte-tech/opencode-bunker)
19
+ guardrail: typed decisions over **PII**, **prompt injection**, **jailbreak
20
+ attempts** and **harmful requests**.
21
+
22
+ Laya is a non-autoregressive **System 1 decision model**: give it a state (text)
23
+ and typed questions (`choice`, `score`, `noul`) and it returns typed answers with
24
+ calibrated probabilities in a single forward pass. It never generates text, so
25
+ there is nothing to parse and nothing to hallucinate.
26
+
27
+ ## Question bank
28
+
29
+ - `pii_present`: Does the text contain personally identifiable information (PII)?
30
+ - `pii_email`: Does the text contain an email address?
31
+ - `pii_phone`: Does the text contain a phone number?
32
+ - `pii_ssn`: Does the text contain a government identification number such as a Social Security number?
33
+ - `pii_credit_card`: Does the text contain a payment card number?
34
+ - `pii_ip_address`: Does the text contain an IP address?
35
+ - `pii_secret`: Does the text contain an API key, password, token, or other credential?
36
+ - `pii_person_name`: Does the text contain a person's name?
37
+ - `pii_address`: Does the text contain a physical mailing address?
38
+ - `injection_present`: Does the content attempt to override, bypass, or manipulate an AI system's instructions, safety measures, or identity? Examples: 'ignore previous instructions', 'reveal your system prompt', 'act as an unrestricted AI', 'pretend you have no rules'.
39
+ - `jailbreak_attempt`: Does the content attempt to bypass an AI system's safety measures or jailbreak it?
40
+ - `harmful_request`: Is the content a request for harmful, illegal, or disallowed activity?
41
+
42
+ ## Files
43
+
44
+ | Path | What |
45
+ | --- | --- |
46
+ | `onnx/model.int8.onnx` | INT8 weight-only graph — **use this in JS** (self-contained, ~600 MB) |
47
+ | `onnx/model.onnx` + `onnx/model.onnx.data` | FP32 graph (external data) — for the Python `laya.ONNXAgent` |
48
+ | `tokenizer/` | ModernBERT tokenizer (`tokenizer.json`, `tokenizer_config.json`) |
49
+ | `encoder/config.json` | encoder config |
50
+ | `rl_agent_config.json` | `max_len`, `head_max_len`, per-question-type temperatures |
51
+ | `model.safetensors` | PyTorch checkpoint (for re-export / further fine-tuning) |
52
+
53
+ ## Graph contract
54
+
55
+ Inputs:
56
+
57
+ | name | dtype | shape | meaning |
58
+ | --- | --- | --- | --- |
59
+ | `input_ids` | int64 | `[batch, seq_len]` | token ids |
60
+ | `attention_mask` | int64 | `[batch, seq_len]` | 1 for real tokens |
61
+ | `marker_pos` | int64 | `[batch, num_markers]` | position of each option's `[MASK]` |
62
+ | `marker_mask` | bool | `[batch, num_markers]` | which marker slots are real |
63
+ | `qtype` | int64 | `[batch]` | `choice=0`, `score=1`, `noul=2` |
64
+
65
+ Outputs:
66
+
67
+ | name | shape | meaning |
68
+ | --- | --- | --- |
69
+ | `logits` | `[batch, num_markers]` | per-option logits (softmax over the question's options) |
70
+ | `act_logits` | `[batch, 2]` | action head (softmax) |
71
+
72
+ For a `noul` question there are exactly two options (`false`, `true`), so
73
+ `P(true) = softmax(logits[:2] / temperature)[1]`.
74
+
75
+ ## Sequence format
76
+
77
+ Each question is one row. The head is built as:
78
+
79
+ ```
80
+ [CLS] <qtype> question: <instructions> [SEP] [MASK] false: ... [MASK] true: ... [SEP] <state> [SEP]
81
+ ```
82
+
83
+ - `marker_pos` points at each `[MASK]` token; `marker_mask` marks the real ones.
84
+ - The state is appended after the head and truncated to the room left by
85
+ `max_len - head_max_len`.
86
+ - `qtype` is `2` for every `noul` question in this model.
87
+
88
+ ## Use with Transformers.js
89
+
90
+ Transformers.js provides the tokenizer and the ONNX Runtime backend. Because the
91
+ graph is a custom decision head (not a standard `AutoModel` architecture), load
92
+ the tokenizer with `AutoTokenizer` and run the graph with an ONNX Runtime
93
+ session:
94
+
95
+ ```js
96
+ import { AutoTokenizer } from "@huggingface/transformers";
97
+ import { InferenceSession, Tensor } from "onnxruntime-node"; // or onnxruntime-web
98
+
99
+ const REPO = "impacte/bunker-laya";
100
+ const tokenizer = await AutoTokenizer.from_pretrained(REPO);
101
+ const session = await InferenceSession.create("model.int8.onnx"); // from the repo
102
+
103
+ // 1. Build the head: [CLS] <qtype> question: <instructions> [SEP] [MASK] false: ... [MASK] true: ... [SEP]
104
+ // 2. Append the state, then [SEP]; truncate to max_len - head_max_len.
105
+ // 3. Run:
106
+ const out = await session.run({
107
+ input_ids: new Tensor("int64", ids, [1, ids.length]),
108
+ attention_mask: new Tensor("int64", mask, [1, ids.length]),
109
+ marker_pos: new Tensor("int64", markerPos, [1, markerPos.length]),
110
+ marker_mask: new Tensor("bool", markerMask, [1, markerMask.length]),
111
+ qtype: new Tensor("int64", [2n], [1]),
112
+ });
113
+ // logits: [1, 2] -> softmax -> P(true)
114
+ ```
115
+
116
+ `opencode-bunker`'s `onnx-local` provider does exactly this (see
117
+ `src/classifier/onnx-local.ts`), so the plugin needs no Python sidecar.
118
+
119
+ ## Pairing with opencode-bunker
120
+
121
+ ```
122
+ opencode turn
123
+ │ chat.message / messages.transform
124
+ ▼
125
+ opencode-bunker plugin
126
+ │ classify(text)
127
+ ▼
128
+ onnx-local provider ── AutoTokenizer (transformers.js) ──► ids
129
+ │ ── ONNX Runtime session ───────────► logits
130
+ ▼
131
+ typed decisions (pii_*, injection_present, …) ──► allow / flag / redact / block
132
+ │
133
+ ▼
134
+ audit.jsonl (pre-provider proof) ──► provider request (or blocked)
135
+ ```
136
+
137
+ The plugin fuses these model probabilities with its regex presets and custom
138
+ patterns; regex `increment` deltas raise a question's probability and can
139
+ escalate the action. See the plugin's `.planning/ARCHITECTURE.md`.
140
+
141
+ ## Provenance
142
+
143
+ Built by the `opencode-bunker-laya` pipeline. Base model Apache-2.0. Each
144
+ training dataset keeps its own license (see the pipeline README).
checkpoint_meta.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "epoch": 2,
3
+ "final": true
4
+ }
encoder/config.json ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ModernBertForMaskedLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 50281,
8
+ "classifier_activation": "gelu",
9
+ "classifier_bias": false,
10
+ "classifier_dropout": 0.0,
11
+ "classifier_pooling": "mean",
12
+ "cls_token_id": 50281,
13
+ "decoder_bias": true,
14
+ "deterministic_flash_attn": false,
15
+ "dtype": "float32",
16
+ "embedding_dropout": 0.0,
17
+ "eos_token_id": 50282,
18
+ "global_attn_every_n_layers": 3,
19
+ "gradient_checkpointing": false,
20
+ "hidden_activation": "gelu",
21
+ "hidden_size": 1024,
22
+ "initializer_cutoff_factor": 2.0,
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 2624,
25
+ "layer_norm_eps": 1e-05,
26
+ "layer_types": [
27
+ "full_attention",
28
+ "sliding_attention",
29
+ "sliding_attention",
30
+ "full_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "full_attention",
34
+ "sliding_attention",
35
+ "sliding_attention",
36
+ "full_attention",
37
+ "sliding_attention",
38
+ "sliding_attention",
39
+ "full_attention",
40
+ "sliding_attention",
41
+ "sliding_attention",
42
+ "full_attention",
43
+ "sliding_attention",
44
+ "sliding_attention",
45
+ "full_attention",
46
+ "sliding_attention",
47
+ "sliding_attention",
48
+ "full_attention",
49
+ "sliding_attention",
50
+ "sliding_attention",
51
+ "full_attention",
52
+ "sliding_attention",
53
+ "sliding_attention",
54
+ "full_attention"
55
+ ],
56
+ "local_attention": 128,
57
+ "max_position_embeddings": 8192,
58
+ "mlp_bias": false,
59
+ "mlp_dropout": 0.0,
60
+ "model_type": "modernbert",
61
+ "norm_bias": false,
62
+ "norm_eps": 1e-05,
63
+ "num_attention_heads": 16,
64
+ "num_hidden_layers": 28,
65
+ "pad_token_id": 50283,
66
+ "position_embedding_type": "absolute",
67
+ "repad_logits_with_grad": false,
68
+ "rope_parameters": {
69
+ "full_attention": {
70
+ "rope_theta": 160000.0,
71
+ "rope_type": "default"
72
+ },
73
+ "sliding_attention": {
74
+ "rope_theta": 10000.0,
75
+ "rope_type": "default"
76
+ }
77
+ },
78
+ "sep_token_id": 50282,
79
+ "sparse_pred_ignore_index": -100,
80
+ "sparse_prediction": false,
81
+ "tie_word_embeddings": true,
82
+ "transformers_version": "5.18.0",
83
+ "vocab_size": 50368
84
+ }
eval_metrics.json ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_dir": "/home/amazonas/Projects/homelab/opencode-bunker-laya/outputs/laya-bunker-pii",
3
+ "rows_evaluated": 2000,
4
+ "questions": {
5
+ "harmful_request": {
6
+ "n": 576,
7
+ "accuracy": 0.9930555555555556,
8
+ "brier": 0.0069371251562500005,
9
+ "ece": 0.010298784722222214,
10
+ "positive_rate": 0.06944444444444445
11
+ },
12
+ "injection_present": {
13
+ "n": 1604,
14
+ "accuracy": 0.9763092269326683,
15
+ "brier": 0.022460516421446385,
16
+ "ece": 0.00732182044887781,
17
+ "positive_rate": 0.35972568578553615
18
+ },
19
+ "jailbreak_attempt": {
20
+ "n": 940,
21
+ "accuracy": 0.9808510638297873,
22
+ "brier": 0.018587605627659574,
23
+ "ece": 0.008280531914893622,
24
+ "positive_rate": 0.043617021276595745
25
+ },
26
+ "pii_address": {
27
+ "n": 186,
28
+ "accuracy": 0.9623655913978495,
29
+ "brier": 0.036114259408602155,
30
+ "ece": 0.021106989247311792,
31
+ "positive_rate": 0.4032258064516129
32
+ },
33
+ "pii_credit_card": {
34
+ "n": 186,
35
+ "accuracy": 0.989247311827957,
36
+ "brier": 0.01046261258064516,
37
+ "ece": 0.0052215053763440865,
38
+ "positive_rate": 0.03225806451612903
39
+ },
40
+ "pii_email": {
41
+ "n": 186,
42
+ "accuracy": 1.0,
43
+ "brier": 0.00024845629032258074,
44
+ "ece": 0.015758602150537617,
45
+ "positive_rate": 0.13978494623655913
46
+ },
47
+ "pii_ip_address": {
48
+ "n": 186,
49
+ "accuracy": 1.0,
50
+ "brier": 0.00024525069892473116,
51
+ "ece": 0.015656451612903223,
52
+ "positive_rate": 0.0
53
+ },
54
+ "pii_person_name": {
55
+ "n": 186,
56
+ "accuracy": 0.978494623655914,
57
+ "brier": 0.02094184166666667,
58
+ "ece": 0.015327419354838705,
59
+ "positive_rate": 0.34946236559139787
60
+ },
61
+ "pii_phone": {
62
+ "n": 186,
63
+ "accuracy": 0.9946236559139785,
64
+ "brier": 0.005439713440860215,
65
+ "ece": 0.010408602150537629,
66
+ "positive_rate": 0.15053763440860216
67
+ },
68
+ "pii_present": {
69
+ "n": 552,
70
+ "accuracy": 0.9981884057971014,
71
+ "brier": 0.0019122373007246375,
72
+ "ece": 0.013831340579710147,
73
+ "positive_rate": 0.17391304347826086
74
+ },
75
+ "pii_secret": {
76
+ "n": 186,
77
+ "accuracy": 0.9838709677419355,
78
+ "brier": 0.015601908064516128,
79
+ "ece": 0.007907526881720424,
80
+ "positive_rate": 0.08602150537634409
81
+ },
82
+ "pii_ssn": {
83
+ "n": 186,
84
+ "accuracy": 0.9838709677419355,
85
+ "brier": 0.016300077849462365,
86
+ "ece": 0.015453763440860144,
87
+ "positive_rate": 0.22580645161290322
88
+ }
89
+ },
90
+ "macro_accuracy": 0.9867397808662236,
91
+ "ood_probe": {
92
+ "pii_present": {
93
+ "mean_prob": 0.015783333333333333,
94
+ "max_prob": 0.0164
95
+ },
96
+ "pii_email": {
97
+ "mean_prob": 0.0161,
98
+ "max_prob": 0.0166
99
+ },
100
+ "pii_phone": {
101
+ "mean_prob": 0.015983333333333336,
102
+ "max_prob": 0.0163
103
+ },
104
+ "pii_ssn": {
105
+ "mean_prob": 0.016216666666666667,
106
+ "max_prob": 0.0168
107
+ },
108
+ "pii_credit_card": {
109
+ "mean_prob": 0.01576666666666667,
110
+ "max_prob": 0.0159
111
+ },
112
+ "pii_ip_address": {
113
+ "mean_prob": 0.015899999999999997,
114
+ "max_prob": 0.0162
115
+ },
116
+ "pii_secret": {
117
+ "mean_prob": 0.016883333333333334,
118
+ "max_prob": 0.0176
119
+ },
120
+ "pii_person_name": {
121
+ "mean_prob": 0.01605,
122
+ "max_prob": 0.0167
123
+ },
124
+ "pii_address": {
125
+ "mean_prob": 0.01656666666666667,
126
+ "max_prob": 0.0171
127
+ },
128
+ "injection_present": {
129
+ "mean_prob": 0.020516666666666666,
130
+ "max_prob": 0.0283
131
+ },
132
+ "jailbreak_attempt": {
133
+ "mean_prob": 0.01585,
134
+ "max_prob": 0.0163
135
+ },
136
+ "harmful_request": {
137
+ "mean_prob": 0.015899999999999997,
138
+ "max_prob": 0.0161
139
+ }
140
+ }
141
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:184806c1c902849e294cabb35e7b6904465522994e2ecfad7dc8d347133bd024
3
+ size 842609220
onnx/model.int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:411cc08c3cfe0a7378c4e2adea6f39f4f84c0a51a9625b293a80327196d92813
3
+ size 598528117
onnx/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:35d61ece7143958cf32c02e9902673615817a7bdbe5e5003f58c378443e3ac4d
3
+ size 3559945
onnx/model.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1bf96875c18428de4dcbbe3d62233ddbaba46698e70b1c2570ef75c91892a04
3
+ size 1685258240
rl_agent_config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "encoder": "answerdotai/ModernBERT-large",
3
+ "head_layers": 2,
4
+ "max_len": 1024,
5
+ "head_max_len": 256,
6
+ "max_prefixes": 6,
7
+ "act_costs": {
8
+ "escalate": 0.5
9
+ },
10
+ "cost_wrong_act": 3.0,
11
+ "amp_dtype": "bf16",
12
+ "model_name": "laya-bunker-pii",
13
+ "temperature": [
14
+ 1.2,
15
+ 1.2,
16
+ 4.433279991149902
17
+ ],
18
+ "training": {
19
+ "updates": 7313,
20
+ "epochs_completed": 1,
21
+ "hours": 1.96,
22
+ "world_size": 1,
23
+ "fine_tuned_from_checkpoint": true
24
+ },
25
+ "max_tokens_per_batch": 2048,
26
+ "gradient_checkpointing": true,
27
+ "fine_tuned": true
28
+ }
tokenizer/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "local_files_only": false,
5
+ "mask_token": "[MASK]",
6
+ "model_input_names": [
7
+ "input_ids",
8
+ "attention_mask"
9
+ ],
10
+ "model_max_length": 8192,
11
+ "pad_token": "[PAD]",
12
+ "sep_token": "[SEP]",
13
+ "tokenizer_class": "PreTrainedTokenizerFast",
14
+ "unk_token": "[UNK]"
15
+ }