Instructions to use tiny-random/glm-5.3-flash with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/glm-5.3-flash with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/glm-5.3-flash") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("tiny-random/glm-5.3-flash") model = AutoModelForMultimodalLM.from_pretrained("tiny-random/glm-5.3-flash", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/glm-5.3-flash with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/glm-5.3-flash" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/glm-5.3-flash", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/tiny-random/glm-5.3-flash
- SGLang
How to use tiny-random/glm-5.3-flash with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "tiny-random/glm-5.3-flash" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/glm-5.3-flash", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "tiny-random/glm-5.3-flash" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/glm-5.3-flash", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use tiny-random/glm-5.3-flash with Docker Model Runner:
docker model run hf.co/tiny-random/glm-5.3-flash
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- .meta.json +22 -0
- LICENSE +21 -0
- README.md +496 -0
- chat_template.jinja +257 -0
- config.json +233 -0
- generation_config.json +12 -0
- model.safetensors +3 -0
- processor_config.json +44 -0
- tokenizer.json +3 -0
- tokenizer_config.json +33 -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
|
.meta.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source_model": {
|
| 3 |
+
"name": "zai-org/GLM-5.3-Flash",
|
| 4 |
+
"commit_id": "46a050bec13002ad29ee795c16e61cf4fa3c4a9c"
|
| 5 |
+
},
|
| 6 |
+
"env": {
|
| 7 |
+
"python": "3.12.13",
|
| 8 |
+
"packages": {
|
| 9 |
+
"Pillow": "12.3.0",
|
| 10 |
+
"accelerate": "1.13.0",
|
| 11 |
+
"huggingface_hub": "2.3.0",
|
| 12 |
+
"kernels": "0.17.2",
|
| 13 |
+
"numpy": "2.5.2",
|
| 14 |
+
"safetensors": "0.8.0",
|
| 15 |
+
"tokenizers": "0.23.3",
|
| 16 |
+
"torch": "2.13.0+cu126",
|
| 17 |
+
"transformers": "5.20.2",
|
| 18 |
+
"vllm": "0.1.dev1+g5a3eba034.d20260730.cu126"
|
| 19 |
+
},
|
| 20 |
+
"cuda": "12.6"
|
| 21 |
+
}
|
| 22 |
+
}
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 Z.AI Co., Ltd
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,496 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
base_model:
|
| 4 |
+
- zai-org/GLM-5.3-Flash
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [zai-org/GLM-5.3-Flash](https://huggingface.co/zai-org/GLM-5.3-Flash).
|
| 8 |
+
|
| 9 |
+
Structural comparison with `zai-org/GLM-5.3-Flash`:
|
| 10 |
+
|
| 11 |
+
| Feature | Source | Tiny |
|
| 12 |
+
|---|---:|---:|
|
| 13 |
+
| Architecture / modalities | GLM5-Next; text, image, video | Same |
|
| 14 |
+
| Vocabulary rows / tied embeddings | 154,880 / false | Same |
|
| 15 |
+
| Text layers / attention cadence | 45; three KDA then DSA | 8; two complete three-KDA + DSA cycles |
|
| 16 |
+
| Text hidden size | 4,096 | 128 |
|
| 17 |
+
| KDA heads / head dimension | 64 / 128 | 64 / 128 |
|
| 18 |
+
| DSA heads / NoPE / value dimensions | 64 / 256 / 256 | 64 / 32 / 256 |
|
| 19 |
+
| Indexer heads / dimension / top-k | 32 / 128 / 2,048 | 32 / 128 / 128 |
|
| 20 |
+
| Routed experts / selected experts / shared experts | 288 / 8 / 1 | 32 / 8 / 1 |
|
| 21 |
+
| Hyper-Connections | Four manifold-constrained streams | Same |
|
| 22 |
+
| MTP | One DSA/MoE layer with shared embedding/head | Same |
|
| 23 |
+
| Vision depth / hidden / output size | 24 / 1,024 / 4,096 | 2 / 128 / 128 |
|
| 24 |
+
| Checkpoint precision | BF16 plus E4M3 block-FP8 and FP32 scales | Same; 32x32 blocks for reduced axes |
|
| 25 |
+
|
| 26 |
+
The KDA and DSA indexer heads remain 128-wide because vLLM's GLM5-Next KDA and Hadamard-128 indexer kernels require that ABI. The source E4M3 format is retained with reduced 32x32 blocks; the TP=4 example selects vLLM's Triton block-FP8 GEMM because H20's automatic Humming kernel requires an output scale group of at least 64.
|
| 27 |
+
Tokenizer, processor, chat template and generation assets are copied unchanged from the pinned source revision.
|
| 28 |
+
|
| 29 |
+
| File path | Size |
|
| 30 |
+
|------|------|
|
| 31 |
+
| model.safetensors | 207.3MB |
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
### Example usage:
|
| 35 |
+
|
| 36 |
+
- vLLM (✅ verified)
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
vllm serve tiny-random/glm-5.3-flash \
|
| 40 |
+
--tensor-parallel-size 4 \
|
| 41 |
+
--speculative-config '{"method":"mtp","num_speculative_tokens":1}' \
|
| 42 |
+
--max-model-len 4096 \
|
| 43 |
+
--max-num-batched-tokens 512 \
|
| 44 |
+
--max-num-seqs 4 \
|
| 45 |
+
--gpu-memory-utilization 0.3 \
|
| 46 |
+
--kernel-config '{"moe_backend":"triton","linear_backend":"triton"}' \
|
| 47 |
+
--compilation-config '{"cudagraph_capture_sizes":[1,2,4,8]}'
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
- Transformers (✅ verified)
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
import numpy as np
|
| 54 |
+
import torch
|
| 55 |
+
from PIL import Image
|
| 56 |
+
from transformers import AutoModelForImageTextToText, AutoProcessor
|
| 57 |
+
from transformers.integrations.hub_kernels import allow_all_hub_kernels
|
| 58 |
+
from transformers.video_utils import VideoMetadata
|
| 59 |
+
|
| 60 |
+
model_id = "tiny-random/glm-5.3-flash"
|
| 61 |
+
# Transformers resolves the official fine-grained FP8 kernel from the Hub.
|
| 62 |
+
with allow_all_hub_kernels():
|
| 63 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
| 64 |
+
model_id, dtype=torch.bfloat16, attn_implementation="sdpa",
|
| 65 |
+
).to("cuda")
|
| 66 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 67 |
+
image = Image.new("RGB", (28, 28), "red")
|
| 68 |
+
video = np.stack([
|
| 69 |
+
np.asarray(Image.new("RGB", (28, 28), color))
|
| 70 |
+
for color in ("red", "green", "blue", "yellow")
|
| 71 |
+
])
|
| 72 |
+
messages = [{"role": "user", "content": [
|
| 73 |
+
{"type": "image", "image": image},
|
| 74 |
+
{"type": "video", "video": video},
|
| 75 |
+
{"type": "text", "text": "Describe the image and the video."},
|
| 76 |
+
]}]
|
| 77 |
+
inputs = processor.apply_chat_template(
|
| 78 |
+
messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt",
|
| 79 |
+
video_metadata=[VideoMetadata(total_num_frames=4, fps=2, frames_indices=[0, 1, 2, 3])],
|
| 80 |
+
).to(model.device)
|
| 81 |
+
output = model.generate(**inputs, do_sample=False, max_new_tokens=10)
|
| 82 |
+
print(processor.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### Codes to create this repo (✅ verified):
|
| 86 |
+
|
| 87 |
+
<details><summary>Click to expand</summary>
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
"""Create the GLM5-Next multimodal checkpoint in its public FP8 schema."""
|
| 91 |
+
import json
|
| 92 |
+
from pathlib import Path
|
| 93 |
+
from shutil import copyfile
|
| 94 |
+
|
| 95 |
+
import torch
|
| 96 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
| 97 |
+
from safetensors.torch import save_file
|
| 98 |
+
from transformers import AutoConfig, AutoModelForImageTextToText, set_seed
|
| 99 |
+
|
| 100 |
+
source_model_id = "zai-org/GLM-5.3-Flash"
|
| 101 |
+
save_folder = "/tmp/tiny-random/glm-53-flash"
|
| 102 |
+
source_revision = "46a050bec13002ad29ee795c16e61cf4fa3c4a9c"
|
| 103 |
+
set_seed(42)
|
| 104 |
+
folder = Path(save_folder)
|
| 105 |
+
folder.mkdir(parents=True, exist_ok=True)
|
| 106 |
+
raw = json.loads(Path(hf_hub_download(
|
| 107 |
+
source_model_id, "config.json", revision=source_revision)).read_text())
|
| 108 |
+
raw["quantization_config"]["weight_block_size"] = [32, 32]
|
| 109 |
+
text = raw["text_config"]
|
| 110 |
+
text.update(
|
| 111 |
+
hidden_size=128,
|
| 112 |
+
num_hidden_layers=8,
|
| 113 |
+
# Retain the source's TP=4-friendly global head topology. The KDA
|
| 114 |
+
# and DSA runtime kernels operate on 16 heads per TP rank.
|
| 115 |
+
num_attention_heads=64,
|
| 116 |
+
num_key_value_heads=64,
|
| 117 |
+
intermediate_size=128,
|
| 118 |
+
moe_intermediate_size=128,
|
| 119 |
+
n_routed_experts=32,
|
| 120 |
+
num_experts_per_tok=8,
|
| 121 |
+
q_lora_rank=128,
|
| 122 |
+
# FA3 sparse-MQA uses this latent as q_v and requires >=256.
|
| 123 |
+
kv_lora_rank=256,
|
| 124 |
+
qk_nope_head_dim=32,
|
| 125 |
+
qk_rope_head_dim=0,
|
| 126 |
+
# Retain source value-head width required by sparse-MQA FA3.
|
| 127 |
+
v_head_dim=256,
|
| 128 |
+
index_head_dim=128,
|
| 129 |
+
# The Hadamard-128 indexer fused kernel accepts 32 or 64; source is 32.
|
| 130 |
+
index_n_heads=32,
|
| 131 |
+
index_topk=128,
|
| 132 |
+
index_kpool=4,
|
| 133 |
+
linear_head_dim=128,
|
| 134 |
+
first_k_dense_replace=3,
|
| 135 |
+
layer_types=["linear_attention", "linear_attention", "linear_attention", "indexed_attention"] * 2,
|
| 136 |
+
mlp_layer_types=["dense", "dense", "dense", "sparse", "sparse", "sparse", "sparse", "sparse"],
|
| 137 |
+
indexer_types=["full"] * 8,
|
| 138 |
+
)
|
| 139 |
+
text["linear_attn_config"].update(
|
| 140 |
+
head_dim=128,
|
| 141 |
+
num_heads=64,
|
| 142 |
+
kda_layers=[0, 1, 2, 4, 5, 6],
|
| 143 |
+
full_attn_layers=[3, 7],
|
| 144 |
+
)
|
| 145 |
+
# TP=4 shards vision attention too: retain four visual heads and a
|
| 146 |
+
# 32-wide visual head dimension for an executable multimodal tower.
|
| 147 |
+
raw["vision_config"].update(
|
| 148 |
+
depth=2, hidden_size=128, intermediate_size=256, num_heads=4,
|
| 149 |
+
out_hidden_size=128, projection_intermediate_size=64, image_size=28, patch_size=14,
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
config_for_build = dict(raw)
|
| 153 |
+
config_for_build.pop("quantization_config")
|
| 154 |
+
(folder / "config.json").write_text(json.dumps(config_for_build, indent=2) + "\n")
|
| 155 |
+
config = AutoConfig.from_pretrained(folder)
|
| 156 |
+
model = AutoModelForImageTextToText.from_config(config, dtype=torch.bfloat16)
|
| 157 |
+
|
| 158 |
+
with torch.no_grad():
|
| 159 |
+
for name, value in model.named_parameters():
|
| 160 |
+
if name.endswith("A_log"):
|
| 161 |
+
value.zero_()
|
| 162 |
+
elif name.endswith("dt_bias"):
|
| 163 |
+
value.fill_(1)
|
| 164 |
+
elif name.endswith("e_score_correction_bias"):
|
| 165 |
+
value.zero_()
|
| 166 |
+
elif name.endswith("weight") and "norm" in name:
|
| 167 |
+
value.fill_(1)
|
| 168 |
+
else:
|
| 169 |
+
value.normal_(mean=0.0, std=0.02)
|
| 170 |
+
|
| 171 |
+
state = {name: value.detach().cpu().contiguous() for name, value in model.state_dict().items()}
|
| 172 |
+
|
| 173 |
+
# Transformers builds the published GLM5-Next graph with convenient
|
| 174 |
+
# module names (``attn_hc`` / ``forget_gate`` / fused ``conv1d``), while
|
| 175 |
+
# both the pinned source checkpoint and vLLM consume the public checkpoint
|
| 176 |
+
# schema below. Convert it before quantization: this is a lossless key
|
| 177 |
+
# rewrite except for splitting the concatenated Q|K|V convolution weight.
|
| 178 |
+
for name in list(state):
|
| 179 |
+
replacement = (
|
| 180 |
+
name.replace(".attn_hc.base", ".hc_attn_base")
|
| 181 |
+
.replace(".attn_hc.fn", ".hc_attn_fn")
|
| 182 |
+
.replace(".attn_hc.scale", ".hc_attn_scale")
|
| 183 |
+
.replace(".ffn_hc.base", ".hc_ffn_base")
|
| 184 |
+
.replace(".ffn_hc.fn", ".hc_ffn_fn")
|
| 185 |
+
.replace(".ffn_hc.scale", ".hc_ffn_scale")
|
| 186 |
+
.replace(".self_attn.forget_gate.", ".self_attn.")
|
| 187 |
+
)
|
| 188 |
+
if replacement != name:
|
| 189 |
+
state[replacement] = state.pop(name)
|
| 190 |
+
projection_size = text["linear_attn_config"]["num_heads"] * text["linear_attn_config"]["head_dim"]
|
| 191 |
+
for name in list(state):
|
| 192 |
+
if not name.endswith(".self_attn.conv1d.weight"):
|
| 193 |
+
continue
|
| 194 |
+
prefix = name.removesuffix(".conv1d.weight")
|
| 195 |
+
q, k, v = state.pop(name).split(projection_size, dim=0)
|
| 196 |
+
state[prefix + ".q_conv1d.weight"] = q.contiguous()
|
| 197 |
+
state[prefix + ".k_conv1d.weight"] = k.contiguous()
|
| 198 |
+
state[prefix + ".v_conv1d.weight"] = v.contiguous()
|
| 199 |
+
block_out, block_in = raw["quantization_config"]["weight_block_size"]
|
| 200 |
+
|
| 201 |
+
def pack(name: str, weight: torch.Tensor) -> None:
|
| 202 |
+
rows, columns = weight.shape
|
| 203 |
+
assert rows % block_out == 0 and columns % block_in == 0, (name, weight.shape)
|
| 204 |
+
blocks = weight.float().reshape(rows // block_out, block_out, columns // block_in, block_in)
|
| 205 |
+
scales = (blocks.abs().amax(dim=(1, 3)) / 448).clamp_min(1e-12).to(torch.float32)
|
| 206 |
+
state[name] = (blocks / scales[:, None, :, None]).clamp(-448, 448).reshape(weight.shape).to(
|
| 207 |
+
torch.float8_e4m3fn
|
| 208 |
+
).contiguous()
|
| 209 |
+
state[name.removesuffix("weight") + "weight_scale_inv"] = scales.contiguous()
|
| 210 |
+
|
| 211 |
+
def keep_bf16(name: str) -> bool:
|
| 212 |
+
# GLM5-Next keeps every KDA/linear-attention tensor in BF16. They are
|
| 213 |
+
# exposed below ``self_attn`` in the Transformers graph rather than
|
| 214 |
+
# under a ``linear_attention`` component name.
|
| 215 |
+
kda_prefixes = tuple(
|
| 216 |
+
f"model.language_model.layers.{index}.self_attn."
|
| 217 |
+
for index in (0, 1, 2, 4, 5, 6)
|
| 218 |
+
)
|
| 219 |
+
return (
|
| 220 |
+
name in {"model.language_model.embed_tokens.weight", "lm_head.weight"}
|
| 221 |
+
or name.startswith(kda_prefixes)
|
| 222 |
+
# GLM5-Next's DSA value expansion deliberately remains BF16.
|
| 223 |
+
or name.endswith(".self_attn.kv_b_proj.weight")
|
| 224 |
+
or ".norm." in name
|
| 225 |
+
or ".indexer." in name
|
| 226 |
+
or ".linear_attention." in name
|
| 227 |
+
or name.endswith(".mlp.gate.weight")
|
| 228 |
+
or name.endswith(".mlp.gate.e_score_correction_bias")
|
| 229 |
+
or name.startswith("model.visual.")
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
# The upstream skip list contains absolute source-layer paths. Retain
|
| 233 |
+
# only the reduced graph's BF16 components so the Transformers FP8 loader
|
| 234 |
+
# constructs KDA, DSA value, router, indexer and vision modules correctly.
|
| 235 |
+
exclusions = {"model.language_model.embed_tokens", "lm_head", "model.visual"}
|
| 236 |
+
for module_name, module in model.named_modules():
|
| 237 |
+
if isinstance(module, torch.nn.Linear) and keep_bf16(module_name + ".weight"):
|
| 238 |
+
exclusions.add(module_name)
|
| 239 |
+
raw["quantization_config"]["modules_to_not_convert"] = sorted(exclusions)
|
| 240 |
+
|
| 241 |
+
for name in list(state):
|
| 242 |
+
if not name.endswith(".mlp.experts.gate_up_proj"):
|
| 243 |
+
continue
|
| 244 |
+
prefix = name.removesuffix(".gate_up_proj")
|
| 245 |
+
gate_up = state.pop(name)
|
| 246 |
+
down = state.pop(prefix + ".down_proj")
|
| 247 |
+
for expert in range(gate_up.shape[0]):
|
| 248 |
+
gate, up = gate_up[expert].chunk(2, dim=0)
|
| 249 |
+
pack(f"{prefix}.{expert}.gate_proj.weight", gate)
|
| 250 |
+
pack(f"{prefix}.{expert}.up_proj.weight", up)
|
| 251 |
+
pack(f"{prefix}.{expert}.down_proj.weight", down[expert])
|
| 252 |
+
|
| 253 |
+
for name in list(state):
|
| 254 |
+
value = state[name]
|
| 255 |
+
if not (name.endswith(".weight") and value.ndim == 2) or keep_bf16(name):
|
| 256 |
+
continue
|
| 257 |
+
pack(name, value)
|
| 258 |
+
|
| 259 |
+
# vLLM consumes the next-token predictor from layer index num_hidden_layers.
|
| 260 |
+
# It is a DSA/MoE layer, not a KDA/mHC layer, and shares the global token
|
| 261 |
+
# embedding and LM head exactly like the source checkpoint.
|
| 262 |
+
base_prefix = "model.language_model.layers.7."
|
| 263 |
+
mtp_prefix = "model.language_model.layers.8."
|
| 264 |
+
for name, value in list(state.items()):
|
| 265 |
+
# GLM5-Next's embedded draft DSA/MoE layer has no Hyper-Connections;
|
| 266 |
+
# source layer 45 likewise omits every hc_* tensor.
|
| 267 |
+
if name.startswith(base_prefix) and ".hc_" not in name:
|
| 268 |
+
state[mtp_prefix + name.removeprefix(base_prefix)] = value.clone()
|
| 269 |
+
state[mtp_prefix + "eh_proj.weight"] = torch.empty(128, 256, dtype=torch.bfloat16).normal_(0, 0.02)
|
| 270 |
+
for name in ("enorm.weight", "hnorm.weight", "shared_head.norm.weight"):
|
| 271 |
+
state[mtp_prefix + name] = torch.ones(128, dtype=torch.bfloat16)
|
| 272 |
+
|
| 273 |
+
save_file(state, folder / "model.safetensors", metadata={"format": "pt"})
|
| 274 |
+
(folder / "config.json").write_text(json.dumps(raw, indent=2) + "\n")
|
| 275 |
+
|
| 276 |
+
assets = {
|
| 277 |
+
"tokenizer.json", "tokenizer_config.json", "special_tokens_map.json", "added_tokens.json",
|
| 278 |
+
"chat_template.jinja", "chat_template.json", "processor_config.json", "preprocessor_config.json",
|
| 279 |
+
"video_preprocessor_config.json", "generation_config.json", "LICENSE",
|
| 280 |
+
}
|
| 281 |
+
for name in sorted(set(list_repo_files(source_model_id, revision=source_revision)) & assets):
|
| 282 |
+
copyfile(hf_hub_download(source_model_id, name, revision=source_revision), folder / name)
|
| 283 |
+
```
|
| 284 |
+
|
| 285 |
+
</details>
|
| 286 |
+
|
| 287 |
+
### Printing the model:
|
| 288 |
+
|
| 289 |
+
<details><summary>Click to expand</summary>
|
| 290 |
+
|
| 291 |
+
```text
|
| 292 |
+
Glm5NextForConditionalGeneration(
|
| 293 |
+
(model): Glm5NextModel(
|
| 294 |
+
(visual): Glm5NextVisionModel(
|
| 295 |
+
(patch_embed): Glm5NextVisionPatchEmbed(
|
| 296 |
+
(proj): Conv3d(3, 128, kernel_size=(2, 14, 14), stride=(2, 14, 14))
|
| 297 |
+
)
|
| 298 |
+
(rotary_pos_emb): Glm5NextVisionRotaryEmbedding()
|
| 299 |
+
(blocks): ModuleList(
|
| 300 |
+
(0-1): 2 x Glm5NextVisionBlock(
|
| 301 |
+
(norm1): Glm5NextRMSNorm((128,), eps=1e-05)
|
| 302 |
+
(norm2): Glm5NextRMSNorm((128,), eps=1e-05)
|
| 303 |
+
(attn): Glm5NextVisionAttention(
|
| 304 |
+
(qkv): Linear(in_features=128, out_features=384, bias=True)
|
| 305 |
+
(proj): Linear(in_features=128, out_features=128, bias=True)
|
| 306 |
+
(q_norm): Glm5NextRMSNorm((32,), eps=1e-05)
|
| 307 |
+
(k_norm): Glm5NextRMSNorm((32,), eps=1e-05)
|
| 308 |
+
)
|
| 309 |
+
(mlp): Glm5NextVisionMLP(
|
| 310 |
+
(gate_proj): Linear(in_features=128, out_features=256, bias=True)
|
| 311 |
+
(up_proj): Linear(in_features=128, out_features=256, bias=True)
|
| 312 |
+
(down_proj): Linear(in_features=256, out_features=128, bias=True)
|
| 313 |
+
(act_fn): SiLUActivation()
|
| 314 |
+
)
|
| 315 |
+
)
|
| 316 |
+
)
|
| 317 |
+
(merger): Glm5NextVisionPatchMerger(
|
| 318 |
+
(proj): Linear(in_features=128, out_features=128, bias=False)
|
| 319 |
+
(post_projection_norm): LayerNorm((128,), eps=1e-05, elementwise_affine=True, bias=True)
|
| 320 |
+
(gate_proj): Linear(in_features=128, out_features=64, bias=False)
|
| 321 |
+
(up_proj): Linear(in_features=128, out_features=64, bias=False)
|
| 322 |
+
(down_proj): Linear(in_features=64, out_features=128, bias=False)
|
| 323 |
+
(act1): GELU(approximate='none')
|
| 324 |
+
(act_fn): SiLUActivation()
|
| 325 |
+
)
|
| 326 |
+
(downsample): Conv2d(128, 128, kernel_size=(2, 2), stride=(2, 2))
|
| 327 |
+
(post_layernorm): Glm5NextRMSNorm((128,), eps=1e-05)
|
| 328 |
+
)
|
| 329 |
+
(language_model): Glm5NextTextModel(
|
| 330 |
+
(embed_tokens): Embedding(154880, 128, padding_idx=154820)
|
| 331 |
+
(layers): ModuleList(
|
| 332 |
+
(0-2): 3 x Glm5NextTextDecoderLayer(
|
| 333 |
+
(self_attn): Glm5NextTextLinearAttention(
|
| 334 |
+
(q_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 335 |
+
(k_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 336 |
+
(v_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 337 |
+
(conv1d): Conv1d(24576, 24576, kernel_size=(4,), stride=(1,), padding=(3,), groups=24576, bias=False)
|
| 338 |
+
(forget_gate): Glm5NextTextForgetGate(
|
| 339 |
+
(f_a_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 340 |
+
(f_b_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 341 |
+
)
|
| 342 |
+
(b_proj): Linear(in_features=128, out_features=64, bias=False)
|
| 343 |
+
(g_a_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 344 |
+
(g_b_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 345 |
+
(o_norm): Glm5NextTextRMSNormGated()
|
| 346 |
+
(o_proj): Linear(in_features=8192, out_features=128, bias=False)
|
| 347 |
+
)
|
| 348 |
+
(mlp): Glm5NextTextMLP(
|
| 349 |
+
(gate_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 350 |
+
(up_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 351 |
+
(down_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 352 |
+
(act_fn): SiLUActivation()
|
| 353 |
+
)
|
| 354 |
+
(input_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 355 |
+
(post_attention_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 356 |
+
(attn_hc): Glm5NextTextHyperConnection(
|
| 357 |
+
(input_norm): Glm5NextTextUnweightedRMSNorm()
|
| 358 |
+
)
|
| 359 |
+
(ffn_hc): Glm5NextTextHyperConnection(
|
| 360 |
+
(input_norm): Glm5NextTextUnweightedRMSNorm()
|
| 361 |
+
)
|
| 362 |
+
)
|
| 363 |
+
(3): Glm5NextTextDecoderLayer(
|
| 364 |
+
(self_attn): Glm5NextTextAttention(
|
| 365 |
+
(q_a_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 366 |
+
(q_a_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 367 |
+
(q_b_proj): Linear(in_features=128, out_features=2048, bias=False)
|
| 368 |
+
(kv_a_proj_with_mqa): Linear(in_features=128, out_features=256, bias=False)
|
| 369 |
+
(kv_a_layernorm): Glm5NextTextRMSNorm((256,), eps=1e-05)
|
| 370 |
+
(kv_b_proj): Linear(in_features=256, out_features=18432, bias=False)
|
| 371 |
+
(o_proj): Linear(in_features=16384, out_features=128, bias=False)
|
| 372 |
+
(indexer): Glm5NextTextIndexer(
|
| 373 |
+
(wq_b): Linear(in_features=128, out_features=4096, bias=False)
|
| 374 |
+
(wk): Linear(in_features=128, out_features=128, bias=False)
|
| 375 |
+
(k_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
|
| 376 |
+
(weights_proj): Linear(in_features=128, out_features=32, bias=False)
|
| 377 |
+
)
|
| 378 |
+
)
|
| 379 |
+
(mlp): Glm5NextTextMoE(
|
| 380 |
+
(experts): Glm5NextTextExperts()
|
| 381 |
+
(gate): Glm5NextTextTopkRouter()
|
| 382 |
+
(shared_experts): Glm5NextTextMLP(
|
| 383 |
+
(gate_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 384 |
+
(up_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 385 |
+
(down_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 386 |
+
(act_fn): SiLUActivation()
|
| 387 |
+
)
|
| 388 |
+
)
|
| 389 |
+
(input_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 390 |
+
(post_attention_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 391 |
+
(attn_hc): Glm5NextTextHyperConnection(
|
| 392 |
+
(input_norm): Glm5NextTextUnweightedRMSNorm()
|
| 393 |
+
)
|
| 394 |
+
(ffn_hc): Glm5NextTextHyperConnection(
|
| 395 |
+
(input_norm): Glm5NextTextUnweightedRMSNorm()
|
| 396 |
+
)
|
| 397 |
+
)
|
| 398 |
+
(4-6): 3 x Glm5NextTextDecoderLayer(
|
| 399 |
+
(self_attn): Glm5NextTextLinearAttention(
|
| 400 |
+
(q_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 401 |
+
(k_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 402 |
+
(v_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 403 |
+
(conv1d): Conv1d(24576, 24576, kernel_size=(4,), stride=(1,), padding=(3,), groups=24576, bias=False)
|
| 404 |
+
(forget_gate): Glm5NextTextForgetGate(
|
| 405 |
+
(f_a_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 406 |
+
(f_b_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 407 |
+
)
|
| 408 |
+
(b_proj): Linear(in_features=128, out_features=64, bias=False)
|
| 409 |
+
(g_a_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 410 |
+
(g_b_proj): Linear(in_features=128, out_features=8192, bias=False)
|
| 411 |
+
(o_norm): Glm5NextTextRMSNormGated()
|
| 412 |
+
(o_proj): Linear(in_features=8192, out_features=128, bias=False)
|
| 413 |
+
)
|
| 414 |
+
(mlp): Glm5NextTextMoE(
|
| 415 |
+
(experts): Glm5NextTextExperts()
|
| 416 |
+
(gate): Glm5NextTextTopkRouter()
|
| 417 |
+
(shared_experts): Glm5NextTextMLP(
|
| 418 |
+
(gate_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 419 |
+
(up_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 420 |
+
(down_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 421 |
+
(act_fn): SiLUActivation()
|
| 422 |
+
)
|
| 423 |
+
)
|
| 424 |
+
(input_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 425 |
+
(post_attention_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 426 |
+
(attn_hc): Glm5NextTextHyperConnection(
|
| 427 |
+
(input_norm): Glm5NextTextUnweightedRMSNorm()
|
| 428 |
+
)
|
| 429 |
+
(ffn_hc): Glm5NextTextHyperConnection(
|
| 430 |
+
(input_norm): Glm5NextTextUnweightedRMSNorm()
|
| 431 |
+
)
|
| 432 |
+
)
|
| 433 |
+
(7): Glm5NextTextDecoderLayer(
|
| 434 |
+
(self_attn): Glm5NextTextAttention(
|
| 435 |
+
(q_a_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 436 |
+
(q_a_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 437 |
+
(q_b_proj): Linear(in_features=128, out_features=2048, bias=False)
|
| 438 |
+
(kv_a_proj_with_mqa): Linear(in_features=128, out_features=256, bias=False)
|
| 439 |
+
(kv_a_layernorm): Glm5NextTextRMSNorm((256,), eps=1e-05)
|
| 440 |
+
(kv_b_proj): Linear(in_features=256, out_features=18432, bias=False)
|
| 441 |
+
(o_proj): Linear(in_features=16384, out_features=128, bias=False)
|
| 442 |
+
(indexer): Glm5NextTextIndexer(
|
| 443 |
+
(wq_b): Linear(in_features=128, out_features=4096, bias=False)
|
| 444 |
+
(wk): Linear(in_features=128, out_features=128, bias=False)
|
| 445 |
+
(k_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
|
| 446 |
+
(weights_proj): Linear(in_features=128, out_features=32, bias=False)
|
| 447 |
+
)
|
| 448 |
+
)
|
| 449 |
+
(mlp): Glm5NextTextMoE(
|
| 450 |
+
(experts): Glm5NextTextExperts()
|
| 451 |
+
(gate): Glm5NextTextTopkRouter()
|
| 452 |
+
(shared_experts): Glm5NextTextMLP(
|
| 453 |
+
(gate_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 454 |
+
(up_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 455 |
+
(down_proj): Linear(in_features=128, out_features=128, bias=False)
|
| 456 |
+
(act_fn): SiLUActivation()
|
| 457 |
+
)
|
| 458 |
+
)
|
| 459 |
+
(input_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 460 |
+
(post_attention_layernorm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 461 |
+
(attn_hc): Glm5NextTextHyperConnection(
|
| 462 |
+
(input_norm): Glm5NextTextUnweightedRMSNorm()
|
| 463 |
+
)
|
| 464 |
+
(ffn_hc): Glm5NextTextHyperConnection(
|
| 465 |
+
(input_norm): Glm5NextTextUnweightedRMSNorm()
|
| 466 |
+
)
|
| 467 |
+
)
|
| 468 |
+
)
|
| 469 |
+
(norm): Glm5NextTextRMSNorm((128,), eps=1e-05)
|
| 470 |
+
(hc_head): Glm5NextTextHyperHead()
|
| 471 |
+
)
|
| 472 |
+
)
|
| 473 |
+
(lm_head): Linear(in_features=128, out_features=154880, bias=False)
|
| 474 |
+
)
|
| 475 |
+
```
|
| 476 |
+
|
| 477 |
+
</details>
|
| 478 |
+
|
| 479 |
+
### Test environment:
|
| 480 |
+
|
| 481 |
+
- Pillow: 12.3.0
|
| 482 |
+
- accelerate: 1.13.0
|
| 483 |
+
- huggingface_hub: 2.3.0
|
| 484 |
+
- kernels: 0.17.2
|
| 485 |
+
- numpy: 2.5.2
|
| 486 |
+
- safetensors: 0.8.0
|
| 487 |
+
- tokenizers: 0.23.3
|
| 488 |
+
- torch: 2.13.0+cu126
|
| 489 |
+
- transformers: 5.20.2
|
| 490 |
+
- vllm: 0.1.dev1+g5a3eba034.d20260730.cu126
|
| 491 |
+
|
| 492 |
+
### Change log:
|
| 493 |
+
|
| 494 |
+
- 2026-10-24: Initial version.
|
| 495 |
+
|
| 496 |
+
This repo is generated by GPT-6.1-Sol
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[gMASK]<sop>
|
| 2 |
+
{%- set effective_reasoning_effort = reasoning_effort if reasoning_effort is defined and reasoning_effort in ['low', 'high'] else 'max' -%}
|
| 3 |
+
{%- if effective_reasoning_effort is not none -%}<|system|>Reasoning Effort: {{ effective_reasoning_effort | capitalize }}{%- endif -%}
|
| 4 |
+
{%- set clear_thinking = clear_thinking if clear_thinking is defined else false -%}
|
| 5 |
+
{%- if tools -%}
|
| 6 |
+
{%- macro tool_to_json(tool) -%}
|
| 7 |
+
{%- set ns_tool = namespace(first=true) -%}
|
| 8 |
+
{{ '{' -}}
|
| 9 |
+
{%- for k, v in tool.items() -%}
|
| 10 |
+
{%- if k != 'defer_loading' and k != 'strict' -%}
|
| 11 |
+
{%- if not ns_tool.first -%}{{- ', ' -}}{%- endif -%}
|
| 12 |
+
{%- set ns_tool.first = false -%}
|
| 13 |
+
"{{ k }}": {{ v | tojson(ensure_ascii=False) }}
|
| 14 |
+
{%- endif -%}
|
| 15 |
+
{%- endfor -%}
|
| 16 |
+
{{- '}' -}}
|
| 17 |
+
{%- endmacro -%}
|
| 18 |
+
{%- macro tool_references_to_response(refs) -%}
|
| 19 |
+
{{- '<tool_response><tools>\n' -}}
|
| 20 |
+
{%- for tr in refs -%}
|
| 21 |
+
{%- for tool in tools -%}
|
| 22 |
+
{%- if 'function' in tool -%}
|
| 23 |
+
{%- set tool = tool['function'] -%}
|
| 24 |
+
{%- endif -%}
|
| 25 |
+
{%- if tool.name == tr.name -%}
|
| 26 |
+
{{- tool_to_json(tool) + '\n' -}}
|
| 27 |
+
{%- endif -%}
|
| 28 |
+
{%- endfor -%}
|
| 29 |
+
{%- endfor -%}
|
| 30 |
+
{{- '</tools></tool_response>' -}}
|
| 31 |
+
{%- endmacro -%}
|
| 32 |
+
<|system|>
|
| 33 |
+
# Tools
|
| 34 |
+
|
| 35 |
+
You may call one or more functions to assist with the user query.
|
| 36 |
+
|
| 37 |
+
You are provided with function signatures within <tools></tools> XML tags:
|
| 38 |
+
<tools>
|
| 39 |
+
{% for tool in tools %}
|
| 40 |
+
{%- if 'function' in tool -%}
|
| 41 |
+
{%- set tool = tool['function'] -%}
|
| 42 |
+
{%- endif -%}
|
| 43 |
+
{% if tool.defer_loading is not defined or not tool.defer_loading %}
|
| 44 |
+
{{ tool_to_json(tool) }}
|
| 45 |
+
{% endif %}
|
| 46 |
+
{% endfor %}
|
| 47 |
+
</tools>
|
| 48 |
+
|
| 49 |
+
For each function call, output the function name and arguments within the following XML format:
|
| 50 |
+
<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 -%}
|
| 51 |
+
{%- macro emit_image() -%}<|begin_of_image|><|image|><|end_of_image|>{%- endmacro -%}
|
| 52 |
+
{%- macro emit_video() -%}<|begin_of_video|><|video|><|end_of_video|>{%- endmacro -%}
|
| 53 |
+
{%- macro emit_audio() -%}<|begin_of_audio|><|end_of_audio|>{%- endmacro -%}
|
| 54 |
+
{%- macro visible_text(content) -%}
|
| 55 |
+
{%- if content is string -%}
|
| 56 |
+
{{- content -}}
|
| 57 |
+
{%- elif content is iterable and content is not mapping -%}
|
| 58 |
+
{%- for item in content -%}
|
| 59 |
+
{%- if item is mapping and item.type == 'text' -%}
|
| 60 |
+
{{- item.text -}}
|
| 61 |
+
{%- elif item is string -%}
|
| 62 |
+
{{- item -}}
|
| 63 |
+
{%- elif item is mapping and item.type in ['image', 'image_url'] -%}
|
| 64 |
+
{{- emit_image() -}}
|
| 65 |
+
{%- elif item is mapping and item.type in ['video', 'video_url'] -%}
|
| 66 |
+
{{- emit_video() -}}
|
| 67 |
+
{%- elif item is mapping and item.type in ['audio', 'audio_url', 'input_audio'] -%}
|
| 68 |
+
{{- emit_audio() -}}
|
| 69 |
+
{%- endif -%}
|
| 70 |
+
{%- endfor -%}
|
| 71 |
+
{%- elif content is not none -%}
|
| 72 |
+
{{- content -}}
|
| 73 |
+
{%- endif -%}
|
| 74 |
+
{%- endmacro -%}
|
| 75 |
+
{%- macro tool_response(text) -%}
|
| 76 |
+
{{- '<tool_response>' + text + '</tool_response>' -}}
|
| 77 |
+
{%- endmacro -%}
|
| 78 |
+
{%- macro render_tool_response(m) -%}
|
| 79 |
+
{%- if m.content is string -%}
|
| 80 |
+
{{- tool_response(m.content) -}}
|
| 81 |
+
{%- elif m.content and m.content is not mapping and m.content.0.type == "tool_reference" -%}
|
| 82 |
+
{{- tool_references_to_response(m.content) -}}
|
| 83 |
+
{%- elif is_list_of_outputs(m) -%}
|
| 84 |
+
{%- for tr in m.content -%}
|
| 85 |
+
{%- if tr.output is iterable and tr.output is not string and tr.output is not mapping and tr.output and tr.output.0.type == "tool_reference" -%}
|
| 86 |
+
{{- tool_references_to_response(tr.output) -}}
|
| 87 |
+
{%- else -%}
|
| 88 |
+
{{- tool_response(visible_text(tr.output)) -}}
|
| 89 |
+
{%- endif -%}
|
| 90 |
+
{%- endfor -%}
|
| 91 |
+
{%- else -%}
|
| 92 |
+
{{- tool_response(visible_text(m.content)) -}}
|
| 93 |
+
{%- endif -%}
|
| 94 |
+
{%- endmacro -%}
|
| 95 |
+
{%- macro id_of(obj) -%}
|
| 96 |
+
{%- if obj.tool_call_id -%}
|
| 97 |
+
{{- obj.tool_call_id -}}
|
| 98 |
+
{%- elif obj.id -%}
|
| 99 |
+
{{- obj.id -}}
|
| 100 |
+
{%- endif -%}
|
| 101 |
+
{%- endmacro -%}
|
| 102 |
+
{%- macro is_list_of_outputs(m) -%}
|
| 103 |
+
{%- if m.content and m.content.0.output is defined -%}1{%- endif -%}
|
| 104 |
+
{%- endmacro -%}
|
| 105 |
+
{%- macro has_dup_tool_result_id(lo, hi, target) -%}
|
| 106 |
+
{%- set ns_cnt = namespace(n=0) -%}
|
| 107 |
+
{%- for k in range(lo, hi + 1) -%}
|
| 108 |
+
{%- set m = messages[k] -%}
|
| 109 |
+
{%- if is_list_of_outputs(m) -%}
|
| 110 |
+
{%- for entry in m.content -%}
|
| 111 |
+
{%- if id_of(entry) == target -%}
|
| 112 |
+
{%- set ns_cnt.n = ns_cnt.n + 1 -%}
|
| 113 |
+
{%- endif -%}
|
| 114 |
+
{%- endfor -%}
|
| 115 |
+
{%- elif id_of(m) == target -%}
|
| 116 |
+
{%- set ns_cnt.n = ns_cnt.n + 1 -%}
|
| 117 |
+
{%- endif -%}
|
| 118 |
+
{%- if ns_cnt.n > 1 -%}{%- break -%}{%- endif -%}
|
| 119 |
+
{%- endfor -%}
|
| 120 |
+
{%- if ns_cnt.n > 1 -%}1{%- endif -%}
|
| 121 |
+
{%- endmacro -%}
|
| 122 |
+
{%- macro tc_id_exists(tcs, target) -%}
|
| 123 |
+
{%- set ns_f = namespace(found=false) -%}
|
| 124 |
+
{%- for tc in tcs -%}
|
| 125 |
+
{%- if id_of(tc) == target -%}
|
| 126 |
+
{%- set ns_f.found = true -%}
|
| 127 |
+
{%- break -%}
|
| 128 |
+
{%- endif -%}
|
| 129 |
+
{%- endfor -%}
|
| 130 |
+
{%- if ns_f.found -%}1{%- endif -%}
|
| 131 |
+
{%- endmacro -%}
|
| 132 |
+
{%- set ns = namespace(last_user_index=-1) -%}
|
| 133 |
+
{%- for m in messages %}
|
| 134 |
+
{%- if m.role == 'user' %}
|
| 135 |
+
{%- set ns.last_user_index = loop.index0 -%}
|
| 136 |
+
{%- endif %}
|
| 137 |
+
{%- endfor %}
|
| 138 |
+
{%- for m in messages -%}
|
| 139 |
+
{%- if m.role == 'user' -%}<|user|>{{ visible_text(m.content) }}
|
| 140 |
+
{%- elif m.role == 'assistant' -%}
|
| 141 |
+
<|assistant|>
|
| 142 |
+
{%- set content = visible_text(m.content) %}
|
| 143 |
+
{%- if m.reasoning_content is string %}
|
| 144 |
+
{%- set reasoning_content = m.reasoning_content %}
|
| 145 |
+
{%- elif '</think>' in content %}
|
| 146 |
+
{%- set reasoning_content = content.split('</think>')[0].split('<think>')[-1] %}
|
| 147 |
+
{%- set content = content.split('</think>')[-1] %}
|
| 148 |
+
{%- endif %}
|
| 149 |
+
{%- if (not clear_thinking or loop.index0 > ns.last_user_index) and reasoning_content is defined -%}
|
| 150 |
+
{{ '<think>' + reasoning_content + '</think>'}}
|
| 151 |
+
{%- else -%}
|
| 152 |
+
{{ '<think></think>' }}
|
| 153 |
+
{%- endif -%}
|
| 154 |
+
{%- if content.strip() -%}
|
| 155 |
+
{{ content.strip() }}
|
| 156 |
+
{%- endif -%}
|
| 157 |
+
{% if m.tool_calls %}
|
| 158 |
+
{% for tc in m.tool_calls %}
|
| 159 |
+
{%- if tc.function %}
|
| 160 |
+
{%- set tc = tc.function %}
|
| 161 |
+
{%- endif %}
|
| 162 |
+
{{- '<tool_call>' ~ tc.name -}}
|
| 163 |
+
{% 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 %}
|
| 164 |
+
{% endif %}
|
| 165 |
+
{%- elif m.role == 'tool' -%}
|
| 166 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 167 |
+
{{- '<|observation|>' -}}
|
| 168 |
+
{%- set block_start = loop.index0 -%}
|
| 169 |
+
{%- set ns_blk = namespace(end=block_start) -%}
|
| 170 |
+
{%- for j in range(block_start, messages|length) -%}
|
| 171 |
+
{%- if messages[j].role == 'tool' -%}
|
| 172 |
+
{%- set ns_blk.end = j -%}
|
| 173 |
+
{%- else -%}
|
| 174 |
+
{%- break -%}
|
| 175 |
+
{%- endif -%}
|
| 176 |
+
{%- endfor -%}
|
| 177 |
+
{%- set ns_a = namespace(tool_calls=none) -%}
|
| 178 |
+
{%- if block_start > 0 and messages[block_start - 1].role == 'assistant' and messages[block_start - 1].tool_calls -%}
|
| 179 |
+
{%- set ns_a.tool_calls = messages[block_start - 1].tool_calls -%}
|
| 180 |
+
{%- endif -%}
|
| 181 |
+
{%- set ns_chk = namespace(can_sort=true, res=[], mk=[], ek=[], tcs=[]) -%}
|
| 182 |
+
{%- for k in range(block_start, ns_blk.end + 1) -%}
|
| 183 |
+
{%- set m = messages[k] -%}
|
| 184 |
+
{%- if is_list_of_outputs(m) -%}
|
| 185 |
+
{%- for entry in m.content -%}
|
| 186 |
+
{%- set ns_chk.res = ns_chk.res + [id_of(entry)] -%}
|
| 187 |
+
{%- set ns_chk.mk = ns_chk.mk + [k] -%}
|
| 188 |
+
{%- set ns_chk.ek = ns_chk.ek + [loop.index0] -%}
|
| 189 |
+
{%- endfor -%}
|
| 190 |
+
{%- else -%}
|
| 191 |
+
{%- set ns_chk.res = ns_chk.res + [id_of(m)] -%}
|
| 192 |
+
{%- set ns_chk.mk = ns_chk.mk + [k] -%}
|
| 193 |
+
{%- set ns_chk.ek = ns_chk.ek + [-1] -%}
|
| 194 |
+
{%- endif -%}
|
| 195 |
+
{%- endfor -%}
|
| 196 |
+
{%- if not ns_a.tool_calls -%}
|
| 197 |
+
{%- set ns_chk.can_sort = false -%}
|
| 198 |
+
{%- else -%}
|
| 199 |
+
{%- for tc in ns_a.tool_calls -%}
|
| 200 |
+
{%- set ns_chk.tcs = ns_chk.tcs + [id_of(tc)] -%}
|
| 201 |
+
{%- endfor -%}
|
| 202 |
+
{%- if '' in ns_chk.res or '' in ns_chk.tcs -%}
|
| 203 |
+
{%- set ns_chk.can_sort = false -%}
|
| 204 |
+
{%- elif ns_chk.res | unique(case_sensitive=true) | list | length != ns_chk.res | length -%}
|
| 205 |
+
{%- set ns_chk.can_sort = false -%}
|
| 206 |
+
{%- elif ns_chk.tcs | unique(case_sensitive=true) | list | length != ns_chk.tcs | length -%}
|
| 207 |
+
{%- set ns_chk.can_sort = false -%}
|
| 208 |
+
{%- else -%}
|
| 209 |
+
{%- for eid in ns_chk.res -%}
|
| 210 |
+
{%- if eid not in ns_chk.tcs -%}
|
| 211 |
+
{%- set ns_chk.can_sort = false -%}
|
| 212 |
+
{%- break -%}
|
| 213 |
+
{%- endif -%}
|
| 214 |
+
{%- endfor -%}
|
| 215 |
+
{%- endif -%}
|
| 216 |
+
{%- endif -%}
|
| 217 |
+
{%- if ns_chk.can_sort -%}
|
| 218 |
+
{%- set ns_ord = namespace(res=[], tcs=[], j=0, pairs=[]) -%}
|
| 219 |
+
{%- for eid in ns_chk.res -%}
|
| 220 |
+
{%- set ns_ord.res = ns_ord.res + [{'id': eid, 'p': loop.index0}] -%}
|
| 221 |
+
{%- endfor -%}
|
| 222 |
+
{%- for tc_id in ns_chk.tcs -%}
|
| 223 |
+
{%- set ns_ord.tcs = ns_ord.tcs + [{'id': tc_id, 'i': loop.index0}] -%}
|
| 224 |
+
{%- endfor -%}
|
| 225 |
+
{%- set ns_ord.res = ns_ord.res | sort(attribute='id', case_sensitive=true) -%}
|
| 226 |
+
{%- for tc in ns_ord.tcs | sort(attribute='id', case_sensitive=true) -%}
|
| 227 |
+
{%- if ns_ord.j < ns_ord.res | length and ns_ord.res[ns_ord.j].id == tc.id -%}
|
| 228 |
+
{%- set ns_ord.pairs = ns_ord.pairs + [{'i': tc.i, 'p': ns_ord.res[ns_ord.j].p}] -%}
|
| 229 |
+
{%- set ns_ord.j = ns_ord.j + 1 -%}
|
| 230 |
+
{%- endif -%}
|
| 231 |
+
{%- endfor -%}
|
| 232 |
+
{%- for pair in ns_ord.pairs | sort(attribute='i') -%}
|
| 233 |
+
{%- set m = messages[ns_chk.mk[pair.p]] -%}
|
| 234 |
+
{%- if ns_chk.ek[pair.p] >= 0 -%}
|
| 235 |
+
{%- set entry = m.content[ns_chk.ek[pair.p]] -%}
|
| 236 |
+
{%- if entry.output is iterable and entry.output is not string and entry.output is not mapping and entry.output and entry.output.0.type == "tool_reference" -%}
|
| 237 |
+
{{- tool_references_to_response(entry.output) -}}
|
| 238 |
+
{%- else -%}
|
| 239 |
+
{{- tool_response(visible_text(entry.output)) -}}
|
| 240 |
+
{%- endif -%}
|
| 241 |
+
{%- else -%}
|
| 242 |
+
{{- render_tool_response(m) -}}
|
| 243 |
+
{%- endif -%}
|
| 244 |
+
{%- endfor -%}
|
| 245 |
+
{%- else -%}
|
| 246 |
+
{%- for k in range(block_start, ns_blk.end + 1) -%}
|
| 247 |
+
{{- render_tool_response(messages[k]) -}}
|
| 248 |
+
{%- endfor -%}
|
| 249 |
+
{%- endif -%}
|
| 250 |
+
{% endif -%}
|
| 251 |
+
{%- elif m.role == 'system' -%}
|
| 252 |
+
<|system|>{{ visible_text(m.content) }}
|
| 253 |
+
{%- endif -%}
|
| 254 |
+
{%- endfor -%}
|
| 255 |
+
{%- if add_generation_prompt -%}
|
| 256 |
+
<|assistant|>{{- '<think>' -}}
|
| 257 |
+
{%- endif -%}
|
config.json
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
"Glm5NextForConditionalGeneration"
|
| 4 |
+
],
|
| 5 |
+
"text_config": {
|
| 6 |
+
"attention_bias": false,
|
| 7 |
+
"attention_dropout": 0.0,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": [
|
| 10 |
+
154820,
|
| 11 |
+
154827,
|
| 12 |
+
154829
|
| 13 |
+
],
|
| 14 |
+
"first_k_dense_replace": 3,
|
| 15 |
+
"hc_eps": 1e-06,
|
| 16 |
+
"hc_mult": 4,
|
| 17 |
+
"hc_sinkhorn_iters": 20,
|
| 18 |
+
"head_dim": 0,
|
| 19 |
+
"hidden_act": "silu",
|
| 20 |
+
"hidden_size": 128,
|
| 21 |
+
"index_head_dim": 128,
|
| 22 |
+
"index_kpool": 4,
|
| 23 |
+
"index_kpool_always_select_tail": true,
|
| 24 |
+
"index_kpool_compress": true,
|
| 25 |
+
"index_n_heads": 32,
|
| 26 |
+
"index_topk": 128,
|
| 27 |
+
"index_share_for_mtp_iteration": true,
|
| 28 |
+
"indexer_rope_interleave": true,
|
| 29 |
+
"indexer_types": [
|
| 30 |
+
"full",
|
| 31 |
+
"full",
|
| 32 |
+
"full",
|
| 33 |
+
"full",
|
| 34 |
+
"full",
|
| 35 |
+
"full",
|
| 36 |
+
"full",
|
| 37 |
+
"full"
|
| 38 |
+
],
|
| 39 |
+
"initializer_range": 0.02,
|
| 40 |
+
"intermediate_size": 128,
|
| 41 |
+
"kv_lora_rank": 256,
|
| 42 |
+
"layer_types": [
|
| 43 |
+
"linear_attention",
|
| 44 |
+
"linear_attention",
|
| 45 |
+
"linear_attention",
|
| 46 |
+
"indexed_attention",
|
| 47 |
+
"linear_attention",
|
| 48 |
+
"linear_attention",
|
| 49 |
+
"linear_attention",
|
| 50 |
+
"indexed_attention"
|
| 51 |
+
],
|
| 52 |
+
"linear_attn_config": {
|
| 53 |
+
"num_heads": 64,
|
| 54 |
+
"gate_lower_bound": -5.0,
|
| 55 |
+
"head_dim": 128,
|
| 56 |
+
"short_conv_kernel_size": 4,
|
| 57 |
+
"kda_layers": [
|
| 58 |
+
0,
|
| 59 |
+
1,
|
| 60 |
+
2,
|
| 61 |
+
4,
|
| 62 |
+
5,
|
| 63 |
+
6
|
| 64 |
+
],
|
| 65 |
+
"full_attn_layers": [
|
| 66 |
+
3,
|
| 67 |
+
7
|
| 68 |
+
]
|
| 69 |
+
},
|
| 70 |
+
"max_position_embeddings": 1048576,
|
| 71 |
+
"mhc": true,
|
| 72 |
+
"mla_use_nope": true,
|
| 73 |
+
"mlp_layer_types": [
|
| 74 |
+
"dense",
|
| 75 |
+
"dense",
|
| 76 |
+
"dense",
|
| 77 |
+
"sparse",
|
| 78 |
+
"sparse",
|
| 79 |
+
"sparse",
|
| 80 |
+
"sparse",
|
| 81 |
+
"sparse"
|
| 82 |
+
],
|
| 83 |
+
"model_type": "glm5_next_text",
|
| 84 |
+
"moe_intermediate_size": 128,
|
| 85 |
+
"moe_router_dtype": "float32",
|
| 86 |
+
"n_group": 1,
|
| 87 |
+
"n_routed_experts": 32,
|
| 88 |
+
"n_shared_experts": 1,
|
| 89 |
+
"norm_topk_prob": true,
|
| 90 |
+
"num_attention_heads": 64,
|
| 91 |
+
"num_experts_per_tok": 8,
|
| 92 |
+
"num_hidden_layers": 8,
|
| 93 |
+
"num_key_value_heads": 64,
|
| 94 |
+
"num_nextn_predict_layers": 1,
|
| 95 |
+
"output_router_logits": false,
|
| 96 |
+
"pad_token_id": 154820,
|
| 97 |
+
"q_lora_rank": 128,
|
| 98 |
+
"qk_head_dim": 256,
|
| 99 |
+
"qk_nope_head_dim": 32,
|
| 100 |
+
"qk_rope_head_dim": 0,
|
| 101 |
+
"rms_norm_eps": 1e-05,
|
| 102 |
+
"routed_scaling_factor": 2.5,
|
| 103 |
+
"router_aux_loss_coef": 0.001,
|
| 104 |
+
"scoring_func": "sigmoid",
|
| 105 |
+
"swiglu_limit": 10.0,
|
| 106 |
+
"tie_word_embeddings": false,
|
| 107 |
+
"topk_group": 1,
|
| 108 |
+
"topk_method": "noaux_tc",
|
| 109 |
+
"use_cache": true,
|
| 110 |
+
"v_head_dim": 256,
|
| 111 |
+
"vocab_size": 154880,
|
| 112 |
+
"linear_head_dim": 128
|
| 113 |
+
},
|
| 114 |
+
"vision_config": {
|
| 115 |
+
"attention_bias": true,
|
| 116 |
+
"attention_dropout": 0.0,
|
| 117 |
+
"depth": 2,
|
| 118 |
+
"hidden_act": "silu",
|
| 119 |
+
"hidden_size": 128,
|
| 120 |
+
"image_size": 28,
|
| 121 |
+
"in_channels": 3,
|
| 122 |
+
"initializer_range": 0.02,
|
| 123 |
+
"intermediate_size": 256,
|
| 124 |
+
"model_type": "glm5_next_vision",
|
| 125 |
+
"num_heads": 4,
|
| 126 |
+
"out_hidden_size": 128,
|
| 127 |
+
"patch_size": 14,
|
| 128 |
+
"projection_intermediate_size": 64,
|
| 129 |
+
"rms_norm_eps": 1e-05,
|
| 130 |
+
"spatial_merge_size": 2,
|
| 131 |
+
"swiglu_limit": 10.0,
|
| 132 |
+
"temporal_patch_size": 2
|
| 133 |
+
},
|
| 134 |
+
"image_token_id": 154854,
|
| 135 |
+
"video_token_id": 154855,
|
| 136 |
+
"image_start_token_id": 154830,
|
| 137 |
+
"image_end_token_id": 154831,
|
| 138 |
+
"video_start_token_id": 154832,
|
| 139 |
+
"video_end_token_id": 154833,
|
| 140 |
+
"tie_word_embeddings": false,
|
| 141 |
+
"model_type": "glm5_next",
|
| 142 |
+
"transformers_version": "5.16.0",
|
| 143 |
+
"quantization_config": {
|
| 144 |
+
"activation_scheme": "dynamic",
|
| 145 |
+
"fmt": "e4m3",
|
| 146 |
+
"modules_to_not_convert": [
|
| 147 |
+
"lm_head",
|
| 148 |
+
"model.language_model.embed_tokens",
|
| 149 |
+
"model.language_model.layers.0.self_attn.b_proj",
|
| 150 |
+
"model.language_model.layers.0.self_attn.forget_gate.f_a_proj",
|
| 151 |
+
"model.language_model.layers.0.self_attn.forget_gate.f_b_proj",
|
| 152 |
+
"model.language_model.layers.0.self_attn.g_a_proj",
|
| 153 |
+
"model.language_model.layers.0.self_attn.g_b_proj",
|
| 154 |
+
"model.language_model.layers.0.self_attn.k_proj",
|
| 155 |
+
"model.language_model.layers.0.self_attn.o_proj",
|
| 156 |
+
"model.language_model.layers.0.self_attn.q_proj",
|
| 157 |
+
"model.language_model.layers.0.self_attn.v_proj",
|
| 158 |
+
"model.language_model.layers.1.self_attn.b_proj",
|
| 159 |
+
"model.language_model.layers.1.self_attn.forget_gate.f_a_proj",
|
| 160 |
+
"model.language_model.layers.1.self_attn.forget_gate.f_b_proj",
|
| 161 |
+
"model.language_model.layers.1.self_attn.g_a_proj",
|
| 162 |
+
"model.language_model.layers.1.self_attn.g_b_proj",
|
| 163 |
+
"model.language_model.layers.1.self_attn.k_proj",
|
| 164 |
+
"model.language_model.layers.1.self_attn.o_proj",
|
| 165 |
+
"model.language_model.layers.1.self_attn.q_proj",
|
| 166 |
+
"model.language_model.layers.1.self_attn.v_proj",
|
| 167 |
+
"model.language_model.layers.2.self_attn.b_proj",
|
| 168 |
+
"model.language_model.layers.2.self_attn.forget_gate.f_a_proj",
|
| 169 |
+
"model.language_model.layers.2.self_attn.forget_gate.f_b_proj",
|
| 170 |
+
"model.language_model.layers.2.self_attn.g_a_proj",
|
| 171 |
+
"model.language_model.layers.2.self_attn.g_b_proj",
|
| 172 |
+
"model.language_model.layers.2.self_attn.k_proj",
|
| 173 |
+
"model.language_model.layers.2.self_attn.o_proj",
|
| 174 |
+
"model.language_model.layers.2.self_attn.q_proj",
|
| 175 |
+
"model.language_model.layers.2.self_attn.v_proj",
|
| 176 |
+
"model.language_model.layers.3.self_attn.indexer.weights_proj",
|
| 177 |
+
"model.language_model.layers.3.self_attn.indexer.wk",
|
| 178 |
+
"model.language_model.layers.3.self_attn.indexer.wq_b",
|
| 179 |
+
"model.language_model.layers.3.self_attn.kv_b_proj",
|
| 180 |
+
"model.language_model.layers.4.self_attn.b_proj",
|
| 181 |
+
"model.language_model.layers.4.self_attn.forget_gate.f_a_proj",
|
| 182 |
+
"model.language_model.layers.4.self_attn.forget_gate.f_b_proj",
|
| 183 |
+
"model.language_model.layers.4.self_attn.g_a_proj",
|
| 184 |
+
"model.language_model.layers.4.self_attn.g_b_proj",
|
| 185 |
+
"model.language_model.layers.4.self_attn.k_proj",
|
| 186 |
+
"model.language_model.layers.4.self_attn.o_proj",
|
| 187 |
+
"model.language_model.layers.4.self_attn.q_proj",
|
| 188 |
+
"model.language_model.layers.4.self_attn.v_proj",
|
| 189 |
+
"model.language_model.layers.5.self_attn.b_proj",
|
| 190 |
+
"model.language_model.layers.5.self_attn.forget_gate.f_a_proj",
|
| 191 |
+
"model.language_model.layers.5.self_attn.forget_gate.f_b_proj",
|
| 192 |
+
"model.language_model.layers.5.self_attn.g_a_proj",
|
| 193 |
+
"model.language_model.layers.5.self_attn.g_b_proj",
|
| 194 |
+
"model.language_model.layers.5.self_attn.k_proj",
|
| 195 |
+
"model.language_model.layers.5.self_attn.o_proj",
|
| 196 |
+
"model.language_model.layers.5.self_attn.q_proj",
|
| 197 |
+
"model.language_model.layers.5.self_attn.v_proj",
|
| 198 |
+
"model.language_model.layers.6.self_attn.b_proj",
|
| 199 |
+
"model.language_model.layers.6.self_attn.forget_gate.f_a_proj",
|
| 200 |
+
"model.language_model.layers.6.self_attn.forget_gate.f_b_proj",
|
| 201 |
+
"model.language_model.layers.6.self_attn.g_a_proj",
|
| 202 |
+
"model.language_model.layers.6.self_attn.g_b_proj",
|
| 203 |
+
"model.language_model.layers.6.self_attn.k_proj",
|
| 204 |
+
"model.language_model.layers.6.self_attn.o_proj",
|
| 205 |
+
"model.language_model.layers.6.self_attn.q_proj",
|
| 206 |
+
"model.language_model.layers.6.self_attn.v_proj",
|
| 207 |
+
"model.language_model.layers.7.self_attn.indexer.weights_proj",
|
| 208 |
+
"model.language_model.layers.7.self_attn.indexer.wk",
|
| 209 |
+
"model.language_model.layers.7.self_attn.indexer.wq_b",
|
| 210 |
+
"model.language_model.layers.7.self_attn.kv_b_proj",
|
| 211 |
+
"model.visual",
|
| 212 |
+
"model.visual.blocks.0.attn.proj",
|
| 213 |
+
"model.visual.blocks.0.attn.qkv",
|
| 214 |
+
"model.visual.blocks.0.mlp.down_proj",
|
| 215 |
+
"model.visual.blocks.0.mlp.gate_proj",
|
| 216 |
+
"model.visual.blocks.0.mlp.up_proj",
|
| 217 |
+
"model.visual.blocks.1.attn.proj",
|
| 218 |
+
"model.visual.blocks.1.attn.qkv",
|
| 219 |
+
"model.visual.blocks.1.mlp.down_proj",
|
| 220 |
+
"model.visual.blocks.1.mlp.gate_proj",
|
| 221 |
+
"model.visual.blocks.1.mlp.up_proj",
|
| 222 |
+
"model.visual.merger.down_proj",
|
| 223 |
+
"model.visual.merger.gate_proj",
|
| 224 |
+
"model.visual.merger.proj",
|
| 225 |
+
"model.visual.merger.up_proj"
|
| 226 |
+
],
|
| 227 |
+
"quant_method": "fp8",
|
| 228 |
+
"weight_block_size": [
|
| 229 |
+
32,
|
| 230 |
+
32
|
| 231 |
+
]
|
| 232 |
+
}
|
| 233 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"top_p": 0.95,
|
| 11 |
+
"transformers_version": "5.16.0"
|
| 12 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d5e25e799ef65ee95f65470b78ebfc8bd6940ba23fda2f4edb5a5c9ed0926aa8
|
| 3 |
+
size 207311776
|
processor_config.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"image_processor": {
|
| 3 |
+
"do_rescale": true,
|
| 4 |
+
"patch_expand_factor": 1,
|
| 5 |
+
"merge_size": 2,
|
| 6 |
+
"image_mean": [
|
| 7 |
+
0.48145466,
|
| 8 |
+
0.4578275,
|
| 9 |
+
0.40821073
|
| 10 |
+
],
|
| 11 |
+
"image_std": [
|
| 12 |
+
0.26862954,
|
| 13 |
+
0.26130258,
|
| 14 |
+
0.27577711
|
| 15 |
+
],
|
| 16 |
+
"temporal_patch_size": 2,
|
| 17 |
+
"patch_size": 14,
|
| 18 |
+
"min_image_tokens": 16,
|
| 19 |
+
"max_image_tokens": 8000,
|
| 20 |
+
"image_processor_type": "Glm5NextImageProcessor"
|
| 21 |
+
},
|
| 22 |
+
"video_processor": {
|
| 23 |
+
"do_rescale": true,
|
| 24 |
+
"video_processor_type": "Glm5NextVideoProcessor",
|
| 25 |
+
"patch_expand_factor": 1,
|
| 26 |
+
"merge_size": 2,
|
| 27 |
+
"image_mean": [
|
| 28 |
+
0.48145466,
|
| 29 |
+
0.4578275,
|
| 30 |
+
0.40821073
|
| 31 |
+
],
|
| 32 |
+
"image_std": [
|
| 33 |
+
0.26862954,
|
| 34 |
+
0.26130258,
|
| 35 |
+
0.27577711
|
| 36 |
+
],
|
| 37 |
+
"temporal_patch_size": 2,
|
| 38 |
+
"patch_size": 14,
|
| 39 |
+
"min_image_tokens": 16,
|
| 40 |
+
"max_image_tokens": 240000,
|
| 41 |
+
"fps": 2
|
| 42 |
+
},
|
| 43 |
+
"processor_class": "Glm5NextProcessor"
|
| 44 |
+
}
|
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,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"clean_up_tokenization_spaces": false,
|
| 4 |
+
"do_lower_case": false,
|
| 5 |
+
"eos_token": "<|endoftext|>",
|
| 6 |
+
"extra_special_tokens": [
|
| 7 |
+
"<|endoftext|>",
|
| 8 |
+
"[MASK]",
|
| 9 |
+
"[gMASK]",
|
| 10 |
+
"[sMASK]",
|
| 11 |
+
"<sop>",
|
| 12 |
+
"<eop>",
|
| 13 |
+
"<|system|>",
|
| 14 |
+
"<|user|>",
|
| 15 |
+
"<|assistant|>",
|
| 16 |
+
"<|observation|>",
|
| 17 |
+
"<|begin_of_image|>",
|
| 18 |
+
"<|end_of_image|>",
|
| 19 |
+
"<|begin_of_video|>",
|
| 20 |
+
"<|end_of_video|>",
|
| 21 |
+
"<|begin_of_audio|>",
|
| 22 |
+
"<|end_of_audio|>",
|
| 23 |
+
"<|begin_of_transcription|>",
|
| 24 |
+
"<|end_of_transcription|>"
|
| 25 |
+
],
|
| 26 |
+
"is_local": true,
|
| 27 |
+
"model_max_length": 1048576,
|
| 28 |
+
"model_specific_special_tokens": {},
|
| 29 |
+
"pad_token": "<|endoftext|>",
|
| 30 |
+
"padding_side": "left",
|
| 31 |
+
"remove_space": false,
|
| 32 |
+
"tokenizer_class": "TokenizersBackend"
|
| 33 |
+
}
|