Text Generation
Transformers
Safetensors
glm4_moe_lite
conversational
🇪🇺 Region: EU
olegsmirnov commited on
Commit
4364941
·
verified ·
1 Parent(s): 951ca70

Add model card

Browse files
.gitattributes CHANGED
@@ -34,3 +34,12 @@ saved_model/**/* 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
  tokenizer.json 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
  tokenizer.json filter=lfs diff=lfs merge=lfs -text
37
+ media/SWE-rebench-V2-pipeline.png filter=lfs diff=lfs merge=lfs -text
38
+ media/glm47flash_throughput.png filter=lfs diff=lfs merge=lfs -text
39
+ media/learned_patterns.png filter=lfs diff=lfs merge=lfs -text
40
+ media/overlay_sandbox.png filter=lfs diff=lfs merge=lfs -text
41
+ media/reasoning-tool-calls-logprobs.png filter=lfs diff=lfs merge=lfs -text
42
+ media/score_vs_cost.png filter=lfs diff=lfs merge=lfs -text
43
+ media/trace_overview.png filter=lfs diff=lfs merge=lfs -text
44
+ media/traffic_recorder.png filter=lfs diff=lfs merge=lfs -text
45
+ media/train_loss_decomposition.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model: zai-org/GLM-4.7-Flash
4
+ datasets:
5
+ - whitecircle/swe-rebench-v2-glm-5.1-pi-agent-successful-traces
6
+ pipeline_tag: text-generation
7
+ library_name: transformers
8
+ ---
9
+
10
+ # Introducing ⚡ GLM-4.7-Flash-Coder ⚡
11
+
12
+ We fine-tuned GLM-4.7-Flash to push its agentic coding capabilities further: from 33.15% to 41.65% on SWE-rebench-V2 (+26% relative improvement) at 14% lower inference cost.
13
+
14
+ This 30B Mixture-of-Experts model beats competitors 3.5-4× its size — Qwen3.5-122B-A10B and Devstral-2 — and surpasses Ling-2.6-Flash by a narrow margin.
15
+
16
+ ![Score vs cost-per-task scatter plot on SWE-rebench-V2, 500 Python tasks: GLM-4.7-Flash-Coder at 0.417 sits 26% above GLM-4.7-Flash at 0.332, at a lower cost per task](media/score_vs_cost.png)
17
+
18
+ ## More reasoning, fewer turns
19
+
20
+ Although GLM-4.7-Flash-Coder does 2.4× more reasoning than the base model, it completes tasks faster: 45% fewer turns, which translates to 14% lower inference cost.
21
+
22
+ ![Box plots for base vs SFT model: median reasoning tokens per response 63 vs 150, assistant turns per task 82.5 vs 44, trace token length 52k vs 39k, average cost per task $0.0443 vs $0.0382](media/trace_overview.png)
23
+
24
+ ## The key to turn efficiency is concurrent tool calls
25
+
26
+ ![Frequency of responses with 2+ read, bash, and edit tool calls: the SFT model issues simultaneous tool calls 6–90× more often than the base model](media/simultaneous_tool_calls.png)
27
+
28
+ ## SWE-rebench-V2
29
+
30
+ We trained and evaluated models on [nebius/SWE-rebench-V2](https://huggingface.co/datasets/nebius/SWE-rebench-V2) — a dataset of 32k agentic coding tasks. It consists of real issues from public repositories, closely representing real-world SWE challenges.
31
+
32
+ ![SWE-rebench-V2 pipeline: a repository and an issue enter an agentic loop in a sandbox, the generated patch is checked by the test-suite verifier, and the reward is 1 if all tests pass](media/SWE-rebench-V2-pipeline.png)
33
+
34
+ ## Teacher — GLM-5.1
35
+
36
+ The training data comes from GLM-5.1 acting as a teacher. We ran it on the train split with 4 rollouts per task and kept only trajectories that passed the tests — 7,777 successful multi-turn traces after rejection sampling.
37
+
38
+ We’re releasing the [training dataset](https://huggingface.co/datasets/whitecircle/swe-rebench-v2-glm-5.1-pi-agent-successful-traces) alongside the [train/test splits](https://huggingface.co/datasets/whitecircle/swe-rebench-v2-clean-python-tasks).
39
+
40
+ All models run inside PI — a lightweight agent harness with four tools: `bash`, `read`, `edit`, `write`.
41
+
42
+ ## Training
43
+
44
+ We trained Coder with Supervised Fine-Tuning (SFT) using [Halo](https://github.com/whitecircle/halo), our post-training framework we’re open-sourcing today 🎉
45
+
46
+ - Parallelism mode: DP=16 (multi-node training)
47
+ - Context length: 75k
48
+ - Packing: Enabled
49
+ - Global batch: 16
50
+ - Learning rate scheduling: Cosine, with linear warm-up
51
+ - Training time: 3 hours on 16 B300 GPUs
52
+
53
+ <details open>
54
+ <summary><h3>Halo 😇 is driven entirely by a single YAML config</h3></summary>
55
+
56
+ ```yaml
57
+ model_name_or_path: zai-org/GLM-4.7-Flash
58
+ trust_remote_code: true
59
+ attn_implementation: flash_attention_4_hybrid
60
+
61
+ dataset:
62
+ - whitecircle/swe-rebench-v2-glm-5.1-pi-agent-successful-traces
63
+ test_size: 0.01
64
+
65
+ conversation_field: messages
66
+ tools_field: tools
67
+ interleaved_thinking: true
68
+
69
+ max_length: 75000
70
+ packing: true
71
+
72
+ learning_rate: 1e-5
73
+ lr_scheduler_type: cosine
74
+ warmup_steps: 25
75
+ per_device_train_batch_size: 1
76
+ per_device_eval_batch_size: 1
77
+
78
+ moe_balancing: none
79
+ liger_kernel_config:
80
+ fused_linear_cross_entropy: true
81
+
82
+ assistant_message_template: "<|assistant|>"
83
+
84
+ output_dir: /mnt/research/GLM-4.7-Flash-Coder
85
+ save_steps: 50
86
+ save_only_model: true
87
+
88
+ eval_strategy: steps
89
+ eval_steps: 50
90
+ logging_steps: 1
91
+ logging_first_step: true
92
+ log_decoded_samples: true
93
+
94
+ report_to: wandb
95
+ project_name: agentic-sft
96
+ run_name: glm-4.7-flash-coder
97
+
98
+ enable_efficiency_metrics: true
99
+ ```
100
+
101
+ </details>
102
+
103
+ ## Emergent skills
104
+
105
+ The model picked up several of the teacher’s skills and patterns during fine-tuning:
106
+
107
+ - A 10× higher rate of self-corrections in reasoning,
108
+ - Self-directed questions (“But wait, could this ever be True?”),
109
+ - Advanced tool calling patterns, e.g. setting timeout for the `bash` tool.
110
+
111
+ ![Bar charts of self-corrections, question marks in reasoning, git stash usage, and timeouts passed to bash across base, SFT, and teacher models](media/learned_patterns.png)
112
+
113
+ Perhaps the most surprising transfer was the `git stash` usage:
114
+
115
+ > *Hmm, actually these look like pre-existing test differences unrelated to my fix. Let me revert my fix and run the test again.*
116
+ >
117
+ > ```bash
118
+ > git stash && python -m pytest tests/test_markdown.py::test_markdown_table -xvs 2>&1 | tail -20
119
+ > ```
120
+
121
+ ## Loss decomposition into Reasoning & Tool Calls
122
+
123
+ We only train on assistant responses. Of 177 million tokens in the dataset, only 46 million carry loss — the remaining 131 million (system prompts and tool responses) are masked.
124
+
125
+ Assistant messages are split into two parts — reasoning and tool calls. Naturally, tool call tokens have much lower entropy. These parts are very different in nature:
126
+
127
+ ![A training trace rendered with per-token probabilities: reasoning tokens in green, tool call tokens in orange, lighter shades meaning higher probability](media/reasoning-tool-calls-logprobs.png)
128
+
129
+ Although tool call tokens make up 43.3% of input tokens, they only contribute to 16.1% of overall loss. To track convergence separately, we decompose loss into two components — negative log-likelihood on reasoning and tool calling tokens, respectively.
130
+
131
+ ![Train and eval loss curves decomposed into reasoning and tool-call components with epoch boundaries; every eval loss reaches its global minimum at step 300](media/train_loss_decomposition.png)
132
+
133
+ Training loss charts show 10-20% epoch cliffs, indicating benign memorization of repeated data.
134
+
135
+ Although it’s possible to set different learning rates for two components, we observed that on our data, eval losses reach their global minima simultaneously — at the end of epoch 2.
136
+
137
+ ## Test scores
138
+
139
+ Below is the comparison of GLM-4.7-Flash, GLM-4.7-Flash-Coder, and its teacher GLM-5.1 on test set of SWE-rebench-V2:
140
+
141
+ | metric | GLM-4.7-Flash | GLM-4.7-Flash-Coder | Δ | Teacher GLM-5.1 |
142
+ | --- | --- | --- | --- | --- |
143
+ | pass@1 | 0.3315 | 0.4165 | +25.6% | 0.5650 |
144
+ | pass@2 | 0.4087 | 0.5023 | +22.9% | 0.6063 |
145
+ | pass@4 | 0.4620 | 0.5720 | +23.8% | 0.6300 |
146
+
147
+ ## How we enabled FA4
148
+
149
+ FlashAttention-4 is a fast attention kernel — but it’s incompatible with GLM-4.7-Flash’s architecture:
150
+
151
+ > *FlashAttention-4 produces NaN gradients for this model’s head_dim-256 partial-rotary attention; falling back to `attn_implementation='sdpa'`.*
152
+
153
+ We found that the incompatibility only appears in the backward pass — the forward computation is correct. So we designed a hybrid scheme: FA4 handles the forward pass, while FA2 takes over for the backward. The hybrid approach gave a 1.36× increase in attention throughput.
154
+
155
+ *We’ll have a separate post on FA4-fwd-FA2-bwd in [our research blog](https://whitecircle.com/#research); stay tuned! 💚*
156
+
157
+ ## Kernels
158
+
159
+ GLM-4.7-Flash is a Mixture-of-Experts model. Tokens are distributed unevenly across experts — that means MLP blocks receive tensors of varying width.
160
+
161
+ The Grouped-GEMM kernel batches matrix multiplications of varying shapes into a single kernel launch. Enabling it gave a 1.6× speedup on the FFN step.
162
+
163
+ Additionally, with Liger Fused Linear Cross-Entropy, we were able to compute loss without full logit matrix materialization in VRAM, preventing OOM on long sequences.
164
+
165
+ Together, these improvements yield up to a 1.63× training speedup over TRL, raising throughput to 11.1k tokens/s on a single B300 GPU on context length 4k:
166
+
167
+ ![GLM-4.7-Flash SFT throughput on a single B300 across context lengths from 4k to 128k: Halo FA4-hybrid leads Halo FA2 and TRL at every length; TRL OOMs at 128k](media/glm47flash_throughput.png)
168
+
169
+ ## Agentic infra challenge
170
+
171
+ We faced a real challenge with agentic evaluation infrastructure.
172
+
173
+ At a scale of thousands of concurrent agents, Docker introduces high startup overhead and heavy disk pressure, and quickly saturates the local network — resulting in a high rate of environment startup errors.
174
+
175
+ Kubernetes struggled at high concurrency on a single host as well: it couldn’t set up and tear down pods fast enough, triggering timeouts. The problem was worst on powerful hosts: they could support enormous concurrency, but pod scheduling couldn’t keep up, so we never reached full CPU or RAM utilization.
176
+
177
+ ## Overlay sandboxes
178
+
179
+ Our solution is the Overlay Sandbox: instead of a container image, the agent runs on the bare host, in an isolated filesystem and process group.
180
+
181
+ It has three layers: a base filesystem with the OS and repository, a hidden layer with the verifier suite, and an upper layer holding all edits and pip-installed packages.
182
+
183
+ Because overlay mounts are lazy (they don’t even index the filesystem!) and only track modified files, sandbox startup is essentially free.
184
+
185
+ ![Overlay sandbox diagram: a read-only base filesystem, hidden verifier files not visible to the agent, and a writable lazy overlay mount holding edits and new files](media/overlay_sandbox.png)
186
+
187
+ Since SWE-rebench-V2 is built from public repositories, agents must run without network access — otherwise, a model can simply fetch a real fix from GitHub. Before restricting network, we caught Fable 5 and Sonnet 5 doing exactly this — retrieving the upstream patches directly on 20-40% of tasks.
188
+
189
+ ## Traffic recorder
190
+
191
+ Our sandbox also includes a traffic recorder — a tiny proxy that forwards requests to the provider (OpenRouter / vLLM / SGLang) and records every response. It’s a harness-agnostic way to assemble full trajectories in OpenAI format and collect performance metrics.
192
+
193
+ ![Traffic recorder diagram: a proxy between the agent and the provider records raw requests and assembles them into an OpenAI-format trace](media/traffic_recorder.png)
194
+
195
+ ## Evaluation
196
+
197
+ Every agent runs with `max_turns = 200`, medium reasoning effort, and default sampling parameters.
198
+
199
+ Inference costs are calculated from OpenRouter pricing tables. We report the theoretical price under the assumption of perfect caching — actual OpenRouter costs were higher due to inconsistent routing. For locally served GLM-4.7-Flash-Coder, we applied the per-request pricing of GLM-4.7-Flash via OpenRouter’s DeepInfra provider.
200
+
201
+ <details>
202
+ <summary>OpenRouter providers per model</summary>
203
+ <br>
204
+
205
+ | model | provider | input $/Mtok | output $/Mtok | cache_read $/Mtok | cache_write $/Mtok |
206
+ | --- | --- | --- | --- | --- | --- |
207
+ | Fable-5 | google-vertex/global | 10 | 50 | 1 | 12.5 |
208
+ | Opus-4.8 | anthropic | 5 | 25 | 0.5 | 6.25 |
209
+ | GLM-5.1 | wafer/fp4 | 1 | 3.2 | 0.1 | |
210
+ | MiniMax-M3 | minimax/fp8 | 0.3 | 1.2 | 0.06 | |
211
+ | DeepSeek-V4-Pro | deepinfra/fp4 | 1.3 | 2.6 | 0.1 | |
212
+ | GPT-5.5 | azure | 5 | 30 | 0.5 | |
213
+ | Kimi-K2.6 | siliconflow/fp8 | 0.77 | 3.4 | 0.14 | |
214
+ | Haiku-4.5 | anthropic | 1 | 5 | 0.1 | 1.25 |
215
+ | Qwen3.5-397B-A17B | deepinfra/fp8 | 0.45 | 3 | 0.22 | |
216
+ | GPT-5.4-Mini | azure | 0.75 | 4.5 | 0.075 | |
217
+ | Gemini-3.1-Pro | google-ai-studio | 2 | 12 | 0.2 | 0.375 |
218
+ | GLM-4.7-Flash-Coder | deepinfra/bf16 | 0.06 | 0.4 | 0.01 | |
219
+ | Ling-2.6-Flash | novita | 0.1 | 0.3 | 0.02 | |
220
+ | Devstral-2 | mistral | 0.4 | 2 | 0.04 | |
221
+ | Qwen3.5-122B-A10B | alibaba | 0.4 | 3.2 | | |
222
+ | GLM-4.7-Flash | deepinfra/bf16 | 0.06 | 0.4 | 0.01 | |
223
+ | Gemini-3.5-Flash | google-vertex/global | 1.5 | 9 | 0.15 | 0.08333 |
224
+ | Qwen3-32B | deepinfra/fp8 | 0.08 | 0.28 | | |
225
+ | Qwen3.6-35B-A3B | parasail/fp8 | 0.15 | 1 | 0.05 | |
226
+ | Gemini-2.5-Flash | google-vertex/global | 0.3 | 2.5 | 0.03 | 0.08333 |
227
+ | Nemotron-3-Super | digitalocean | 0.21 | 0.455 | 0.06 | |
228
+ | Solar-Pro-3 | upstage | 0.15 | 0.6 | 0.015 | |
229
+
230
+ </details>
231
+
232
+ <details>
233
+ <summary>Prompt template</summary>
234
+ <br>
235
+
236
+ ```markdown
237
+ You are solving a real GitHub issue in the `{repo}` repository. The repo is already cloned and set up in the current working directory.
238
+
239
+ ## Workflow
240
+
241
+ 1. **Understand the issue.** Read the problem statement carefully. Identify the expected vs actual behavior.
242
+ 2. **Explore the codebase.** Find the relevant files using grep, find, or by reading the project structure. Read the code that needs to change.
243
+ 3. **Reproduce the bug** if possible — run the relevant test file or write a small script to confirm the issue exists.
244
+ 4. **Implement a minimal fix.** Change only what is necessary. Do not refactor unrelated code, do not add features beyond what the issue asks for.
245
+ 5. **Verify your fix.** Run the project's existing test suite to make sure you haven't introduced regressions. Look at the project's test configuration (Makefile, tox.ini, pyproject.toml, CI config) to find the right test command.
246
+ 6. **Mark the task complete** only after you've verified existing tests pass with your changes.
247
+
248
+ ## Issue
249
+
250
+ {problem_statement}
251
+
252
+ ## Expected Interfaces
253
+
254
+ The following interfaces are expected by the test suite. Pay close attention to function names, parameter signatures, and return types — the tests verify these exactly.
255
+
256
+ {interface}
257
+ ```
258
+
259
+ </details>
260
+
261
+ <details>
262
+ <summary>Inference with SGLang 0.5.14, CUDA 13</summary>
263
+ <br>
264
+
265
+ ```bash
266
+ python3 -m sglang_router.launch_server \
267
+ --model-path whitecircle/GLM-4.7-Flash-Coder \
268
+ --trust-remote-code \
269
+ --host 0.0.0.0 --port 30000 \
270
+ --context-length 202752 \
271
+ --prefill-attention-backend trtllm_mla \
272
+ --decode-attention-backend triton \
273
+ --speculative-draft-attention-backend triton \
274
+ --page-size 64 \
275
+ --tool-call-parser glm47 --reasoning-parser glm45 \
276
+ --router-policy cache_aware \
277
+ --tp-size 1 --dp-size 8
278
+ ```
279
+
280
+ </details>
281
+
282
+ ## Team
283
+
284
+ - Project lead: Oleg Smirnov
285
+ - Agentic sandboxes: Konstantin Korolev, Sergei Bratchnikov
286
+ - Contributors: Mohamed Mekkouri, Dmitrii Kharlapenko, Daniil Oblakov
287
+
288
+ A [White Circle](https://whitecircle.com) project
media/SWE-rebench-V2-pipeline.png ADDED

Git LFS Details

  • SHA256: 1ced4df856428f6195a15f811650aefe8a8b10e969a281827a9e91e8a580c5bf
  • Pointer size: 132 Bytes
  • Size of remote file: 1.16 MB
media/glm47flash_throughput.png ADDED

Git LFS Details

  • SHA256: 66960552af4f0b8f043d0fa3d5212b14758181bd76eff40a4b777bf2c8d14f12
  • Pointer size: 131 Bytes
  • Size of remote file: 109 kB
media/learned_patterns.png ADDED

Git LFS Details

  • SHA256: f689fa9b01b75c46965d6c1ab7de72eb1cd79c4cbbb254b7a8910fd71a296685
  • Pointer size: 131 Bytes
  • Size of remote file: 106 kB
media/overlay_sandbox.png ADDED

Git LFS Details

  • SHA256: d68a200722847caef996085782013bf394a8c56ba311b1f064e75ebbe9fc05c3
  • Pointer size: 131 Bytes
  • Size of remote file: 974 kB
media/reasoning-tool-calls-logprobs.png ADDED

Git LFS Details

  • SHA256: ce5b192ced75d8b807c5ea3c07a362ddf4a06aa8c33a1d7a39c0a9e4833433e1
  • Pointer size: 131 Bytes
  • Size of remote file: 412 kB
media/score_vs_cost.png ADDED

Git LFS Details

  • SHA256: 923e648197beec089ee3d896f8057d0f04bda4e110cc41cf5543ec0d7b237b00
  • Pointer size: 131 Bytes
  • Size of remote file: 381 kB
media/simultaneous_tool_calls.png ADDED
media/trace_overview.png ADDED

Git LFS Details

  • SHA256: ac54f6e59c4cf02314832fe2bdd5732ec627bde513e04fb6368829a41aebf50a
  • Pointer size: 131 Bytes
  • Size of remote file: 107 kB
media/traffic_recorder.png ADDED

Git LFS Details

  • SHA256: 03cbdc8f6e271c1f84cf89223bcea24b5769d35e88b1b1ee9b17ecdcba7fcf37
  • Pointer size: 132 Bytes
  • Size of remote file: 1.01 MB
media/train_loss_decomposition.png ADDED

Git LFS Details

  • SHA256: b17563623f49f8852021110bf5b031eb717989bec6b0a2e20523a2d0fac77595
  • Pointer size: 131 Bytes
  • Size of remote file: 533 kB