Instructions to use tiny-random/glm-5.2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/glm-5.2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tiny-random/glm-5.2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tiny-random/glm-5.2") model = AutoModelForCausalLM.from_pretrained("tiny-random/glm-5.2", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/glm-5.2 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.2" # 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.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tiny-random/glm-5.2
- SGLang
How to use tiny-random/glm-5.2 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.2" \ --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.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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.2" \ --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.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tiny-random/glm-5.2 with Docker Model Runner:
docker model run hf.co/tiny-random/glm-5.2
Upload folder using huggingface_hub
Browse files- README.md +10 -3
- config.json +6 -1
- model.safetensors +2 -2
README.md
CHANGED
|
@@ -57,7 +57,7 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 57 |
dtype=torch.bfloat16,
|
| 58 |
device_map=device,
|
| 59 |
)
|
| 60 |
-
generated_ids = model.generate(input_ids, max_new_tokens=8)
|
| 61 |
output_text = tokenizer.decode(generated_ids[0][input_ids.shape[1]:])
|
| 62 |
print(output_text)
|
| 63 |
```
|
|
@@ -85,7 +85,7 @@ from transformers import (
|
|
| 85 |
)
|
| 86 |
|
| 87 |
source_model_id = "zai-org/GLM-5.2"
|
| 88 |
-
save_folder = "/tmp/tiny-random/glm-52"
|
| 89 |
|
| 90 |
processor = AutoProcessor.from_pretrained(
|
| 91 |
source_model_id, trust_remote_code=True)
|
|
@@ -100,6 +100,7 @@ config_json.update({
|
|
| 100 |
"hidden_size": 8,
|
| 101 |
"index_n_heads": 4,
|
| 102 |
"indexer_types": ['full'] + ['shared'] * 3,
|
|
|
|
| 103 |
"intermediate_size": 32,
|
| 104 |
"moe_intermediate_size": 32,
|
| 105 |
"num_hidden_layers": 4,
|
|
@@ -149,7 +150,7 @@ model.model.layers.append(nn.ModuleDict(dict(
|
|
| 149 |
hnorm=nn.RMSNorm(config.hidden_size),
|
| 150 |
input_layernorm=nn.RMSNorm(config.hidden_size),
|
| 151 |
post_attention_layernorm=nn.RMSNorm(config.hidden_size),
|
| 152 |
-
self_attn=deepcopy(model.model.layers[
|
| 153 |
mlp=deepcopy(model.model.layers[1].mlp),
|
| 154 |
)))
|
| 155 |
for i in range(1, len(model.model.layers)):
|
|
@@ -237,6 +238,12 @@ GlmMoeDsaForCausalLM(
|
|
| 237 |
(kv_a_layernorm): GlmMoeDsaRMSNorm((512,), eps=1e-06)
|
| 238 |
(kv_b_proj): Linear(in_features=512, out_features=3584, bias=False)
|
| 239 |
(o_proj): Linear(in_features=2048, out_features=8, bias=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
)
|
| 241 |
(mlp): GlmMoeDsaMoE(
|
| 242 |
(experts): GlmMoeDsaExperts(
|
|
|
|
| 57 |
dtype=torch.bfloat16,
|
| 58 |
device_map=device,
|
| 59 |
)
|
| 60 |
+
generated_ids = model.generate(input_ids, max_new_tokens=8) # pyright: ignore[reportAttributeAccessIssue]
|
| 61 |
output_text = tokenizer.decode(generated_ids[0][input_ids.shape[1]:])
|
| 62 |
print(output_text)
|
| 63 |
```
|
|
|
|
| 85 |
)
|
| 86 |
|
| 87 |
source_model_id = "zai-org/GLM-5.2"
|
| 88 |
+
save_folder = "/tmp/tiny-random/glm-52" # pyright: ignore[reportUnusedExpression]
|
| 89 |
|
| 90 |
processor = AutoProcessor.from_pretrained(
|
| 91 |
source_model_id, trust_remote_code=True)
|
|
|
|
| 100 |
"hidden_size": 8,
|
| 101 |
"index_n_heads": 4,
|
| 102 |
"indexer_types": ['full'] + ['shared'] * 3,
|
| 103 |
+
"index_topk_pattern": ['F'] + ['S'] * 3,
|
| 104 |
"intermediate_size": 32,
|
| 105 |
"moe_intermediate_size": 32,
|
| 106 |
"num_hidden_layers": 4,
|
|
|
|
| 150 |
hnorm=nn.RMSNorm(config.hidden_size),
|
| 151 |
input_layernorm=nn.RMSNorm(config.hidden_size),
|
| 152 |
post_attention_layernorm=nn.RMSNorm(config.hidden_size),
|
| 153 |
+
self_attn=deepcopy(model.model.layers[0].self_attn),
|
| 154 |
mlp=deepcopy(model.model.layers[1].mlp),
|
| 155 |
)))
|
| 156 |
for i in range(1, len(model.model.layers)):
|
|
|
|
| 238 |
(kv_a_layernorm): GlmMoeDsaRMSNorm((512,), eps=1e-06)
|
| 239 |
(kv_b_proj): Linear(in_features=512, out_features=3584, bias=False)
|
| 240 |
(o_proj): Linear(in_features=2048, out_features=8, bias=False)
|
| 241 |
+
(indexer): GlmMoeDsaIndexer(
|
| 242 |
+
(wq_b): Linear(in_features=32, out_features=512, bias=False)
|
| 243 |
+
(wk): Linear(in_features=8, out_features=128, bias=False)
|
| 244 |
+
(k_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True)
|
| 245 |
+
(weights_proj): Linear(in_features=8, out_features=4, bias=False)
|
| 246 |
+
)
|
| 247 |
)
|
| 248 |
(mlp): GlmMoeDsaMoE(
|
| 249 |
(experts): GlmMoeDsaExperts(
|
config.json
CHANGED
|
@@ -22,7 +22,12 @@
|
|
| 22 |
"index_skip_topk_offset": 3,
|
| 23 |
"index_topk": 2048,
|
| 24 |
"index_topk_freq": 4,
|
| 25 |
-
"index_topk_pattern":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
"indexer_rope_interleave": true,
|
| 27 |
"indexer_types": [
|
| 28 |
"full",
|
|
|
|
| 22 |
"index_skip_topk_offset": 3,
|
| 23 |
"index_topk": 2048,
|
| 24 |
"index_topk_freq": 4,
|
| 25 |
+
"index_topk_pattern": [
|
| 26 |
+
"F",
|
| 27 |
+
"S",
|
| 28 |
+
"S",
|
| 29 |
+
"S"
|
| 30 |
+
],
|
| 31 |
"indexer_rope_interleave": true,
|
| 32 |
"indexer_types": [
|
| 33 |
"full",
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:151d405ef695562d64c615d24d4f0cbf0aec60d7b563c545ceb41484959a0744
|
| 3 |
+
size 26216056
|