leonsarmiento commited on
Commit
6352e26
·
verified ·
1 Parent(s): e5163d6

Upload folder using huggingface_hub

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
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: mlx
3
+ base_model: zai-org/GLM-4.7-Flash
4
+ tags:
5
+ - mlx
6
+ - mlx-lm
7
+ - moe
8
+ - glm4
9
+ - basequant-xl
10
+ pipeline_tag: text-generation
11
+ ---
12
+
13
+ # leonsarmiento/GLM-4.7-Flash-6bit-XL-mlx
14
+
15
+ This model was converted to MLX format from [`zai-org/GLM-4.7-Flash`](https://huggingface.co/zai-org/GLM-4.7-Flash) using **BaseQuant_XL 6/8-bit mixed quantization** optimized for Apple Silicon.
16
+
17
+ **BaseQuant_XL** keeps the most routing-critical layers in full bf16 precision — `lm_head` and `shared_experts` — while applying aggressive quantization to the bulk parameters. The MoE router gate (`MoEGate`) uses raw arrays rather than `nn.Linear`, so it is naturally excluded from quantization.
18
+
19
+ GLM-4.7-Flash is a 31B-parameter text-only MoE (Mixture of Experts) model with 64 routed experts (4 active per token + 1 shared expert), MLA-style attention with LoRA-rank Q/KV compression, and speculative decoding support (MTP). Despite 31B total parameters, only ~3B are activated per token for efficient inference.
20
+
21
+ ## Intelligence Benchmarks (n=30 samples)
22
+
23
+ | Benchmark | GLM-4.7-Flash XL (6-bit) | GLM-4.7-Flash (6-bit) | Delta |
24
+ |-----------|--------------------------|----------------------|-------|
25
+ | MMLU | **73.3%** | 70.0% | +3.3 |
26
+ | MMLU_PRO | **50.0%** | 43.3% | **+6.7** |
27
+ | HellaSwag | **56.7%** | 53.3% | +3.4 |
28
+ | TruthfulQA | 76.7% | 76.7% | — |
29
+ | ARC Challenge | **66.7%** | 63.3% | +3.4 |
30
+ | Winogrande | 53.3% | **60.0%** | -6.7 |
31
+ | MathQA | **20.0%** | 16.7% | +3.3 |
32
+ | HumanEval | 73.3% | 73.3% | — |
33
+ | MBPP | 66.7% | 66.7% | — |
34
+
35
+ > XL shows broad improvements across MMLU, MMLU_PRO, HellaSwag, ARC, and MathQA. Winogrande regression (-6.7) is within sampling noise at n=30.
36
+
37
+ ## Use with mlx
38
+
39
+ ```bash
40
+ pip install -U mlx-lm
41
+ ```
42
+
43
+ ```python
44
+ from mlx_lm import load, generate
45
+
46
+ model, tokenizer = load("leonsarmiento/GLM-4.7-Flash-6bit-XL-mlx")
47
+
48
+ prompt = "Hello, how are you?"
49
+
50
+ response = generate(model, tokenizer, prompt=prompt, temp=0.2, top_k=50, top_p=0.95)
51
+ print(response)
52
+ ```
53
+
54
+ ## BaseQuant_XL Quantization Strategy
55
+
56
+ | Bit Depth | Layers | Rationale |
57
+ |-----------|--------|-----------|
58
+ | **bf16 (unquantized)** | `lm_head`, `shared_experts` | Output projection and shared computation — errors here cascade through all tokens. MoE router (`MoEGate`) uses raw arrays, naturally excluded |
59
+ | **8-bit** | `embed_tokens`, `self_attn` (MLA), dense `mlp` (layer 0) | Every-token layers — embeddings, attention, dense MLP |
60
+ | **6-bit** | `switch_mlp` (routed experts) | Bulk of parameters, only 4 of 64 experts active per token (6.25%) — natural redundancy tolerates lower precision |
61
+
62
+ ### Quantization Details
63
+
64
+ | Layer | Bits | Group Size |
65
+ |-------|------|------------|
66
+ | `lm_head` | bf16 | — |
67
+ | `shared_experts` | bf16 | — |
68
+ | `MoEGate` (router) | bf16 | — (not nn.Linear) |
69
+ | `embed_tokens` | 8 | 64 |
70
+ | `self_attn` (MLA) | 8 | 64 |
71
+ | dense `mlp` (layer 0) | 8 | 64 |
72
+ | `switch_mlp` (routed experts) | 6 | 64 |
73
+ | Default fallback | 8 | 64 |
74
+
75
+ - **Quantization type**: BaseQuant_XL mixed (text-only)
76
+ - **Bits per weight**: 6.834
77
+ - **Total size**: ~24 GB
78
+ - **Group size**: 64
79
+ - **Method**: `mlx_lm.convert` with custom `quant_predicate`
80
+
81
+ ## Recommended Inference Parameters
82
+
83
+ | Parameter | Value |
84
+ |-----------|-------|
85
+ | `temperature` | 0.2 |
86
+ | `top_k` | 50 |
87
+ | `top_p` | 0.95 |
88
+ | `min_p` | 0.01 |
89
+ | `repeat_penalty` | disabled |
90
+
91
+ ## LM Studio Jinja template or oMLX custom kwargs
92
+
93
+ Add these flags to the top of the jinja template or as custom kwargs to use this model in the way it was intended by GLM:
94
+
95
+ ```jinja
96
+ {%- set enable_thinking = true -%}
97
+ {%- set clear_thinking = false -%}
98
+ ```
chat_template.jinja ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gMASK]<sop>
2
+ {%- if tools -%}
3
+ <|system|>
4
+ # Tools
5
+
6
+ You may call one or more functions to assist with the user query.
7
+
8
+ You are provided with function signatures within <tools></tools> XML tags:
9
+ <tools>
10
+ {% for tool in tools %}
11
+ {{ tool | tojson(ensure_ascii=False) }}
12
+ {% endfor %}
13
+ </tools>
14
+
15
+ For each function call, output the function name and arguments within the following XML format:
16
+ <tool_call>{function-name}<arg_key>{arg-key-1}</arg_key><arg_value>{arg-value-1}</arg_value><arg_key>{arg-key-2}</arg_key><arg_value>{arg-value-2}</arg_value>...</tool_call>{%- endif -%}
17
+ {%- macro visible_text(content) -%}
18
+ {%- if content is string -%}
19
+ {{- content }}
20
+ {%- elif content is iterable and content is not mapping -%}
21
+ {%- for item in content -%}
22
+ {%- if item is mapping and item.type == 'text' -%}
23
+ {{- item.text }}
24
+ {%- elif item is string -%}
25
+ {{- item }}
26
+ {%- endif -%}
27
+ {%- endfor -%}
28
+ {%- else -%}
29
+ {{- content }}
30
+ {%- endif -%}
31
+ {%- endmacro -%}
32
+ {%- set ns = namespace(last_user_index=-1) %}
33
+ {%- for m in messages %}
34
+ {%- if m.role == 'user' %}
35
+ {% set ns.last_user_index = loop.index0 -%}
36
+ {%- endif %}
37
+ {%- endfor %}
38
+ {% for m in messages %}
39
+ {%- if m.role == 'user' -%}<|user|>{{ visible_text(m.content) }}
40
+ {%- elif m.role == 'assistant' -%}
41
+ <|assistant|>
42
+ {%- set reasoning_content = '' %}
43
+ {%- set content = visible_text(m.content) %}
44
+ {%- if m.reasoning_content is string %}
45
+ {%- set reasoning_content = m.reasoning_content %}
46
+ {%- else %}
47
+ {%- if '</think>' in content %}
48
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
49
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
50
+ {%- endif %}
51
+ {%- endif %}
52
+ {%- if ((clear_thinking is defined and not clear_thinking) or loop.index0 > ns.last_user_index) and reasoning_content -%}
53
+ {{ '<think>' + reasoning_content.strip() + '</think>'}}
54
+ {%- else -%}
55
+ {{ '</think>' }}
56
+ {%- endif -%}
57
+ {%- if content.strip() -%}
58
+ {{ content.strip() }}
59
+ {%- endif -%}
60
+ {% if m.tool_calls %}
61
+ {% for tc in m.tool_calls %}
62
+ {%- if tc.function %}
63
+ {%- set tc = tc.function %}
64
+ {%- endif %}
65
+ {{- '<tool_call>' + tc.name -}}
66
+ {% set _args = tc.arguments %}{% for k, v in _args.items() %}<arg_key>{{ k }}</arg_key><arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>{% endfor %}</tool_call>{% endfor %}
67
+ {% endif %}
68
+ {%- elif m.role == 'tool' -%}
69
+ {%- if m.content is string -%}
70
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
71
+ {{- '<|observation|>' }}
72
+ {%- endif %}
73
+ {{- '<tool_response>' }}
74
+ {{- m.content }}
75
+ {{- '</tool_response>' }}
76
+ {%- else -%}
77
+ <|observation|>{% for tr in m.content %}
78
+ <tool_response>{{ tr.output if tr.output is defined else tr }}</tool_response>{% endfor -%}
79
+ {% endif -%}
80
+ {%- elif m.role == 'system' -%}
81
+ <|system|>{{ visible_text(m.content) }}
82
+ {%- endif -%}
83
+ {%- endfor -%}
84
+ {%- if add_generation_prompt -%}
85
+ <|assistant|>{{- '</think>' if (enable_thinking is defined and not enable_thinking) else '<think>' -}}
86
+ {%- endif -%}
config.json ADDED
The diff for this file is too large to render. See raw diff
 
generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "eos_token_id": [
4
+ 154820,
5
+ 154827,
6
+ 154829
7
+ ],
8
+ "pad_token_id": 154820,
9
+ "temperature": 1.0,
10
+ "transformers_version": "5.0.0.dev0"
11
+ }
model-00001-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ddc584dd48daea25f9947af92019946d2114af837f8ea61fb1734f0f3b26d2c3
3
+ size 5247149964
model-00002-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de9a2dd65fe9e3c8a26533adc36585d790ce8706fd8293cfae0bd00bfc53ff58
3
+ size 5330032826
model-00003-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:52159ffcbf9086952bfe89bbe15129be0aecd45f7805cba446037fe855283aa5
3
+ size 5330032794
model-00004-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f002e0db5119c2c1eb610b44c7eecb9b6c2a4b4cbcc66dec5b50582d00fb2418
3
+ size 5330032808
model-00005-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec22d4cd22feb4bf1f470114162923132ab2813f5fcf344a7fbbb755c40fa2f1
3
+ size 4342292895
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:19e773648cb4e65de8660ea6365e10acca112d42a854923df93db4a6f333a82d
3
+ size 20217442
tokenizer_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "clean_up_tokenization_spaces": false,
4
+ "do_lower_case": false,
5
+ "eos_token": "<|endoftext|>",
6
+ "is_local": true,
7
+ "local_files_only": false,
8
+ "model_max_length": 128000,
9
+ "pad_token": "<|endoftext|>",
10
+ "padding_side": "left",
11
+ "remove_space": false,
12
+ "tokenizer_class": "TokenizersBackend",
13
+ "tool_parser_type": "glm47"
14
+ }