Add files using upload-large-folder tool
Browse files- .gitattributes +1 -0
- README.md +39 -0
- chat_template.jinja +86 -0
- config.json +55 -0
- generation_config.json +11 -0
- model-00001-of-00004.safetensors +3 -0
- model-00002-of-00004.safetensors +3 -0
- model-00003-of-00004.safetensors +3 -0
- model-00004-of-00004.safetensors +3 -0
- model.safetensors.index.json +0 -0
- tokenizer.json +3 -0
- tokenizer_config.json +54 -0
.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,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- zh
|
| 5 |
+
library_name: mlx
|
| 6 |
+
license: mit
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
base_model: zai-org/GLM-4.7-Flash
|
| 9 |
+
tags:
|
| 10 |
+
- mlx
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# mlx-community/GLM-4.7-Flash-4bit
|
| 14 |
+
|
| 15 |
+
This model [mlx-community/GLM-4.7-Flash-4bit](https://huggingface.co/mlx-community/GLM-4.7-Flash-4bit) was
|
| 16 |
+
converted to MLX format from [zai-org/GLM-4.7-Flash](https://huggingface.co/zai-org/GLM-4.7-Flash)
|
| 17 |
+
using mlx-lm version **0.30.2**.
|
| 18 |
+
|
| 19 |
+
## Use with mlx
|
| 20 |
+
|
| 21 |
+
```bash
|
| 22 |
+
pip install mlx-lm
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
from mlx_lm import load, generate
|
| 27 |
+
|
| 28 |
+
model, tokenizer = load("mlx-community/GLM-4.7-Flash-4bit")
|
| 29 |
+
|
| 30 |
+
prompt = "hello"
|
| 31 |
+
|
| 32 |
+
if tokenizer.chat_template is not None:
|
| 33 |
+
messages = [{"role": "user", "content": prompt}]
|
| 34 |
+
prompt = tokenizer.apply_chat_template(
|
| 35 |
+
messages, add_generation_prompt=True, return_dict=False,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
response = generate(model, tokenizer, prompt=prompt, verbose=True)
|
| 39 |
+
```
|
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
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Glm4MoeLiteForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"dtype": "bfloat16",
|
| 8 |
+
"eos_token_id": [
|
| 9 |
+
154820,
|
| 10 |
+
154827,
|
| 11 |
+
154829
|
| 12 |
+
],
|
| 13 |
+
"first_k_dense_replace": 1,
|
| 14 |
+
"hidden_act": "silu",
|
| 15 |
+
"hidden_size": 2048,
|
| 16 |
+
"intermediate_size": 10240,
|
| 17 |
+
"kv_lora_rank": 512,
|
| 18 |
+
"max_position_embeddings": 202752,
|
| 19 |
+
"model_type": "glm4_moe_lite",
|
| 20 |
+
"moe_intermediate_size": 1536,
|
| 21 |
+
"n_group": 1,
|
| 22 |
+
"n_routed_experts": 64,
|
| 23 |
+
"n_shared_experts": 1,
|
| 24 |
+
"norm_topk_prob": true,
|
| 25 |
+
"num_attention_heads": 20,
|
| 26 |
+
"num_experts_per_tok": 4,
|
| 27 |
+
"num_hidden_layers": 47,
|
| 28 |
+
"num_key_value_heads": 20,
|
| 29 |
+
"num_nextn_predict_layers": 1,
|
| 30 |
+
"pad_token_id": 154820,
|
| 31 |
+
"partial_rotary_factor": 1.0,
|
| 32 |
+
"q_lora_rank": 768,
|
| 33 |
+
"qk_nope_head_dim": 192,
|
| 34 |
+
"qk_rope_head_dim": 64,
|
| 35 |
+
"quantization": {
|
| 36 |
+
"group_size": 64,
|
| 37 |
+
"bits": 4,
|
| 38 |
+
"mode": "affine"
|
| 39 |
+
},
|
| 40 |
+
"quantization_config": {
|
| 41 |
+
"group_size": 64,
|
| 42 |
+
"bits": 4,
|
| 43 |
+
"mode": "affine"
|
| 44 |
+
},
|
| 45 |
+
"rms_norm_eps": 1e-05,
|
| 46 |
+
"rope_scaling": null,
|
| 47 |
+
"rope_theta": 1000000,
|
| 48 |
+
"routed_scaling_factor": 1.8,
|
| 49 |
+
"tie_word_embeddings": false,
|
| 50 |
+
"topk_group": 1,
|
| 51 |
+
"topk_method": "noaux_tc",
|
| 52 |
+
"transformers_version": "5.0.0rc0",
|
| 53 |
+
"v_head_dim": 256,
|
| 54 |
+
"vocab_size": 154880
|
| 55 |
+
}
|
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-00004.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:faf1fbf037a483c8e3715b8f9e7f612460563b799fcedcc3bcde741fb803b847
|
| 3 |
+
size 5357447205
|
model-00002-of-00004.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:245d14506734ae39da2dc2fb0968abc228d566da144d8b2e14ddbd7233e495f6
|
| 3 |
+
size 5363456985
|
model-00003-of-00004.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:59e8ddad2e9e0b4419b7a1eed2eefcda37218c08475ee64d210be98b53c1e188
|
| 3 |
+
size 5363456853
|
model-00004-of-00004.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:681e1dcffe65139de9dae2ca98c430d7e863e43ef29bd438d40b6975b6bebb77
|
| 3 |
+
size 768063712
|
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:ad47af68eb0dfcc868258957578831a793a15858b88e2f8325d644fc77f4fb1c
|
| 3 |
+
size 20217424
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"additional_special_tokens": [
|
| 3 |
+
"<|endoftext|>",
|
| 4 |
+
"[MASK]",
|
| 5 |
+
"[gMASK]",
|
| 6 |
+
"[sMASK]",
|
| 7 |
+
"<sop>",
|
| 8 |
+
"<eop>",
|
| 9 |
+
"<|system|>",
|
| 10 |
+
"<|user|>",
|
| 11 |
+
"<|assistant|>",
|
| 12 |
+
"<|observation|>",
|
| 13 |
+
"<|begin_of_image|>",
|
| 14 |
+
"<|end_of_image|>",
|
| 15 |
+
"<|begin_of_video|>",
|
| 16 |
+
"<|end_of_video|>",
|
| 17 |
+
"<|begin_of_audio|>",
|
| 18 |
+
"<|end_of_audio|>",
|
| 19 |
+
"<|begin_of_transcription|>",
|
| 20 |
+
"<|end_of_transcription|>"
|
| 21 |
+
],
|
| 22 |
+
"backend": "tokenizers",
|
| 23 |
+
"clean_up_tokenization_spaces": false,
|
| 24 |
+
"do_lower_case": false,
|
| 25 |
+
"eos_token": "<|endoftext|>",
|
| 26 |
+
"extra_special_tokens": [
|
| 27 |
+
"<|endoftext|>",
|
| 28 |
+
"[MASK]",
|
| 29 |
+
"[gMASK]",
|
| 30 |
+
"[sMASK]",
|
| 31 |
+
"<sop>",
|
| 32 |
+
"<eop>",
|
| 33 |
+
"<|system|>",
|
| 34 |
+
"<|user|>",
|
| 35 |
+
"<|assistant|>",
|
| 36 |
+
"<|observation|>",
|
| 37 |
+
"<|begin_of_image|>",
|
| 38 |
+
"<|end_of_image|>",
|
| 39 |
+
"<|begin_of_video|>",
|
| 40 |
+
"<|end_of_video|>",
|
| 41 |
+
"<|begin_of_audio|>",
|
| 42 |
+
"<|end_of_audio|>",
|
| 43 |
+
"<|begin_of_transcription|>",
|
| 44 |
+
"<|end_of_transcription|>"
|
| 45 |
+
],
|
| 46 |
+
"is_local": true,
|
| 47 |
+
"model_max_length": 128000,
|
| 48 |
+
"model_specific_special_tokens": {},
|
| 49 |
+
"pad_token": "<|endoftext|>",
|
| 50 |
+
"padding_side": "left",
|
| 51 |
+
"remove_space": false,
|
| 52 |
+
"tokenizer_class": "TokenizersBackend",
|
| 53 |
+
"tool_parser_type": "glm47"
|
| 54 |
+
}
|