mourningdove commited on
Commit
68e99f0
·
verified ·
1 Parent(s): d6e1fdf

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +125 -0
README.md CHANGED
@@ -14,3 +14,128 @@ tags:
14
  - qwen-coder
15
  - mlx
16
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  - qwen-coder
15
  - mlx
16
  ---
17
+
18
+
19
+ # ZK Constraint Auditor v0.0
20
+
21
+ A LoRA fine-tune of `Qwen2.5-Coder-1.5B-Instruct` specialized in identifying insufficient constraints in ZK proof circuits. Fine-tuned on data from the [mourningdove007/zk-constraint-data](https://github.com/mourningdove007/zk-constraint-data) GitHub repository. About 15 training examples and about 3 validation examples are far from sufficient to train a quality model. A model fine-tuned on so little data will likely behave sensibly only on very simple circuits. This version is a proof of concept.
22
+
23
+
24
+ ## Intended use
25
+
26
+ - First-pass triage of Circom circuits during security audits
27
+ - Educational tool for learning constraint insufficiency patterns
28
+ - Research baseline for ZK security tooling
29
+
30
+ ## Training details
31
+
32
+ | Parameter | Value |
33
+ |-----------|-------|
34
+ | Base model | Qwen2.5-Coder-1.5B-Instruct |
35
+ | Method | LoRA (MLX) |
36
+ | LoRA layers | 8 |
37
+ | Training examples | ~15 |
38
+ | Validation examples | ~3 |
39
+ | Iterations | 200 |
40
+ | Learning rate | 2e-5 |
41
+ | Framework | Circom |
42
+
43
+
44
+ ## Usage (macOS)
45
+
46
+ We use [MLX](https://github.com/ml-explore/mlx-lm) for fine-tuning an existing model. Install it with:
47
+
48
+ ```
49
+ pip install -U mlx-lm
50
+ ```
51
+
52
+ The model can be loaded from our Hugging Face repository and used to generate a response for a user-supplied prompt.
53
+
54
+ ```python
55
+ import mlx.core as mx
56
+ from mlx_lm import load, generate
57
+
58
+ model, tokenizer = load("mourningdove/zk-auditor")
59
+
60
+ messages = [
61
+ {"role": "system", "content": "You are a ZK proof security auditor specializing in Circom."},
62
+ {"role": "user", "content": "Audit this circuit for vulnerabilities: template Test() { signal input a; signal output b; b <-- a * 3; }"}
63
+ ]
64
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
65
+
66
+
67
+ response = generate(
68
+ model,
69
+ tokenizer,
70
+ prompt=prompt,
71
+ max_tokens=300,
72
+ sampler=lambda x: mx.argmax(x, axis=-1)
73
+ )
74
+ print(response)
75
+ ```
76
+
77
+ ## Usage (Transformers)
78
+
79
+ Coming soon. The plan is to provide a working Transformers example in the next version.
80
+
81
+ ## A Note on `apply_chat_template`
82
+
83
+ This model was fine-tuned using Qwen's ChatML format, so you must apply the correct chat template when running inference in Python. Without it, the model receives a prompt structure that it was never trained on and will produce incorrect output.
84
+
85
+ `apply_chat_template` formats your messages into the ChatML structure the model expects. If your `tokenizer_config.json` is missing the `chat_template` key, inference can fail silently. Use the following to verify that your chat template matches the base model's template:
86
+
87
+ ```python
88
+ from transformers import AutoTokenizer
89
+
90
+ ref = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-1.5B-Instruct")
91
+ tokenizer = AutoTokenizer.from_pretrained("mourningdove/zk-auditor")
92
+ print(ref.chat_template == tokenizer.chat_template)
93
+ ```
94
+
95
+ ## Training
96
+
97
+ The initial model we use is [Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct). A smaller model (1.5B parameters) is selected so the progression of our fine-tuned model will be more apparent when additional training data is added. This model can be downloaded from Hugging Face using their CLI tools.
98
+
99
+ ```
100
+ hf download Qwen/Qwen2.5-Coder-1.5B-Instruct
101
+ ```
102
+
103
+ We can train the model to obtain the adapter weights.
104
+
105
+ ```
106
+ mlx_lm.lora --config config_v00.yaml --train --iters 10
107
+ ```
108
+
109
+ Fuse the adapter weights to the base model:
110
+
111
+ ```
112
+ mlx_lm.fuse \
113
+ --model Qwen/Qwen2.5-Coder-1.5B-Instruct \
114
+ --adapter-path adapters/v00/ \
115
+ --save-path fused/
116
+ ```
117
+
118
+ Verify the model works:
119
+
120
+ ```
121
+ mlx_lm.generate \
122
+ --model fused/ \
123
+ --prompt "Audit this Circom circuit for vulnerabilities: template Test() { signal input a; signal output b; b <-- a * 2; }"
124
+ ```
125
+
126
+ We can upload to our Hugging Face repository with the following:
127
+
128
+ ```
129
+ hf upload mourningdove/zk-auditor fused --repo-type model
130
+ ```
131
+
132
+ ## Roadmap
133
+
134
+ - **v0.1** — 40–50 examples, real findings from public audits, broader pattern coverage
135
+ - **v0.2** — 100+ examples, held-out evaluation set, honest benchmark results
136
+
137
+
138
+ ## License
139
+
140
+ Model weights: Apache 2.0 (inherited from base model)
141
+