Instructions to use yujiepan/glm-4-tiny-random with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yujiepan/glm-4-tiny-random with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yujiepan/glm-4-tiny-random") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("yujiepan/glm-4-tiny-random") model = AutoModelForCausalLM.from_pretrained("yujiepan/glm-4-tiny-random", 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use yujiepan/glm-4-tiny-random with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yujiepan/glm-4-tiny-random" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yujiepan/glm-4-tiny-random", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/yujiepan/glm-4-tiny-random
- SGLang
How to use yujiepan/glm-4-tiny-random 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 "yujiepan/glm-4-tiny-random" \ --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": "yujiepan/glm-4-tiny-random", "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 "yujiepan/glm-4-tiny-random" \ --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": "yujiepan/glm-4-tiny-random", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use yujiepan/glm-4-tiny-random with Docker Model Runner:
docker model run hf.co/yujiepan/glm-4-tiny-random
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +50 -45
- chat_template.jinja +41 -0
- config.json +15 -34
- generation_config.json +2 -5
- model.safetensors +2 -2
- special_tokens_map.json +1 -1
- tokenizer.json +3 -0
- tokenizer_config.json +7 -8
.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
CHANGED
|
@@ -3,64 +3,69 @@ library_name: transformers
|
|
| 3 |
pipeline_tag: text-generation
|
| 4 |
inference: true
|
| 5 |
widget:
|
| 6 |
-
- text: Hello!
|
| 7 |
-
|
| 8 |
-
|
| 9 |
---
|
| 10 |
|
| 11 |
-
This model is randomly initialized
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
```python
|
| 16 |
-
import transformers
|
| 17 |
import torch
|
| 18 |
-
import os
|
| 19 |
-
from huggingface_hub import create_repo, upload_folder
|
| 20 |
-
import accelerate
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
source_model_id,
|
| 30 |
-
trust_remote_code=True,
|
| 31 |
)
|
| 32 |
-
|
| 33 |
-
config.hidden_size = 8
|
| 34 |
-
config.ffn_hidden_size = 16
|
| 35 |
-
config.kv_channels = 2
|
| 36 |
-
config.num_attention_heads = 4
|
| 37 |
-
config.multi_query_group_num = 2
|
| 38 |
-
config.num_hidden_layers = 2
|
| 39 |
-
config.num_layers = 2
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
config,
|
|
|
|
| 43 |
trust_remote_code=True,
|
| 44 |
)
|
| 45 |
-
model.generation_config =
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
with torch.no_grad():
|
| 49 |
-
for p in model.parameters():
|
| 50 |
-
torch.nn.init.normal_(p)
|
| 51 |
-
|
| 52 |
-
model.save_pretrained(save_path)
|
| 53 |
-
|
| 54 |
-
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
| 55 |
-
source_model_id,
|
| 56 |
-
trust_remote_code=True,
|
| 57 |
)
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
create_repo(repo_id, exist_ok=True)
|
| 65 |
-
upload_folder(repo_id=repo_id, folder_path=save_path)
|
| 66 |
```
|
|
|
|
| 3 |
pipeline_tag: text-generation
|
| 4 |
inference: true
|
| 5 |
widget:
|
| 6 |
+
- text: Hello!
|
| 7 |
+
example_title: Hello world
|
| 8 |
+
group: Python
|
| 9 |
---
|
| 10 |
|
| 11 |
+
This tiny model is for debugging. It is randomly initialized with the config adapted from [THUDM/GLM-4-32B-0414](https://huggingface.co/THUDM/GLM-4-32B-0414).
|
| 12 |
|
| 13 |
+
### Example usage:
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
from transformers import pipeline
|
| 17 |
+
model_id = "yujiepan/glm-4-tiny-random"
|
| 18 |
+
pipe = pipeline(
|
| 19 |
+
"text-generation", model=model_id, device="cuda",
|
| 20 |
+
trust_remote_code=True, max_new_tokens=20,
|
| 21 |
+
)
|
| 22 |
+
print(pipe("Hello World!"))
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
### Codes to create this repo:
|
| 26 |
|
| 27 |
```python
|
|
|
|
| 28 |
import torch
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
from transformers import (
|
| 31 |
+
AutoConfig,
|
| 32 |
+
AutoModelForCausalLM,
|
| 33 |
+
AutoTokenizer,
|
| 34 |
+
GenerationConfig,
|
| 35 |
+
pipeline,
|
| 36 |
+
set_seed,
|
| 37 |
+
)
|
| 38 |
|
| 39 |
+
source_model_id = "THUDM/GLM-4-32B-0414"
|
| 40 |
+
save_folder = "/tmp/yujiepan/glm-4-tiny-random"
|
| 41 |
|
| 42 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 43 |
+
source_model_id, trust_remote_code=True,
|
|
|
|
| 44 |
)
|
| 45 |
+
tokenizer.save_pretrained(save_folder)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
config = AutoConfig.from_pretrained(
|
| 48 |
+
source_model_id, trust_remote_code=True,
|
| 49 |
+
)
|
| 50 |
+
config.hidden_size = 16
|
| 51 |
+
config.head_dim = 16
|
| 52 |
+
config.intermediate_size = 32
|
| 53 |
+
config.num_attention_heads = 1
|
| 54 |
+
config.num_hidden_layers = 2
|
| 55 |
+
config.num_key_value_heads = 1
|
| 56 |
+
config.tie_word_embeddings = False
|
| 57 |
+
model = AutoModelForCausalLM.from_config(
|
| 58 |
config,
|
| 59 |
+
torch_dtype=torch.bfloat16,
|
| 60 |
trust_remote_code=True,
|
| 61 |
)
|
| 62 |
+
model.generation_config = GenerationConfig.from_pretrained(
|
| 63 |
+
source_model_id, trust_remote_code=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
)
|
| 65 |
+
set_seed(42)
|
| 66 |
+
with torch.no_grad():
|
| 67 |
+
for name, p in sorted(model.named_parameters()):
|
| 68 |
+
torch.nn.init.normal_(p, 0, 0.5)
|
| 69 |
+
print(name, p.shape)
|
| 70 |
+
model.save_pretrained(save_folder)
|
|
|
|
|
|
|
| 71 |
```
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[gMASK]<sop>
|
| 2 |
+
{%- if tools -%}
|
| 3 |
+
<|system|>
|
| 4 |
+
# 可用工具
|
| 5 |
+
{% for tool in tools %}
|
| 6 |
+
{%- set function = tool.function if tool.get("function") else tool %}
|
| 7 |
+
|
| 8 |
+
## {{ function.name }}
|
| 9 |
+
|
| 10 |
+
{{ function | tojson(indent=4, ensure_ascii=False) }}
|
| 11 |
+
在调用上述函数时,请使用 Json 格式表示调用的参数。
|
| 12 |
+
{%- endfor %}
|
| 13 |
+
{%- endif -%}
|
| 14 |
+
|
| 15 |
+
{%- for msg in messages %}
|
| 16 |
+
{%- if msg.role == 'system' %}
|
| 17 |
+
<|system|>
|
| 18 |
+
{{ msg.content }}
|
| 19 |
+
{%- endif %}
|
| 20 |
+
{%- endfor %}
|
| 21 |
+
|
| 22 |
+
{%- for message in messages if message.role != 'system' %}
|
| 23 |
+
{%- set role = message['role'] %}
|
| 24 |
+
{%- set content = message['content'] %}
|
| 25 |
+
{%- set meta = message.get("metadata", "") %}
|
| 26 |
+
|
| 27 |
+
{%- if role == 'user' %}
|
| 28 |
+
<|user|>
|
| 29 |
+
{{ content }}
|
| 30 |
+
{%- elif role == 'assistant' and not meta %}
|
| 31 |
+
<|assistant|>
|
| 32 |
+
{{ content }}
|
| 33 |
+
{%- elif role == 'assistant' and meta %}
|
| 34 |
+
<|assistant|>{{ meta }}
|
| 35 |
+
{{ content }}
|
| 36 |
+
{%- elif role == 'observation' %}
|
| 37 |
+
<|observation|>
|
| 38 |
+
{{ content }}
|
| 39 |
+
{%- endif %}
|
| 40 |
+
{%- endfor %}
|
| 41 |
+
{% if add_generation_prompt %}<|assistant|>{% endif %}
|
config.json
CHANGED
|
@@ -1,50 +1,31 @@
|
|
| 1 |
{
|
| 2 |
-
"_name_or_path": "THUDM/glm-4-9b-chat",
|
| 3 |
-
"add_bias_linear": false,
|
| 4 |
-
"add_qkv_bias": true,
|
| 5 |
-
"apply_query_key_layer_scaling": true,
|
| 6 |
-
"apply_residual_connection_post_layernorm": false,
|
| 7 |
"architectures": [
|
| 8 |
-
"
|
| 9 |
],
|
|
|
|
| 10 |
"attention_dropout": 0.0,
|
| 11 |
-
"attention_softmax_in_fp32": true,
|
| 12 |
-
"auto_map": {
|
| 13 |
-
"AutoConfig": "THUDM/glm-4-9b-chat--configuration_chatglm.ChatGLMConfig",
|
| 14 |
-
"AutoModel": "THUDM/glm-4-9b-chat--modeling_chatglm.ChatGLMForConditionalGeneration",
|
| 15 |
-
"AutoModelForCausalLM": "THUDM/glm-4-9b-chat--modeling_chatglm.ChatGLMForConditionalGeneration",
|
| 16 |
-
"AutoModelForSeq2SeqLM": "THUDM/glm-4-9b-chat--modeling_chatglm.ChatGLMForConditionalGeneration",
|
| 17 |
-
"AutoModelForSequenceClassification": "THUDM/glm-4-9b-chat--modeling_chatglm.ChatGLMForSequenceClassification"
|
| 18 |
-
},
|
| 19 |
-
"bias_dropout_fusion": true,
|
| 20 |
-
"classifier_dropout": null,
|
| 21 |
"eos_token_id": [
|
| 22 |
151329,
|
| 23 |
151336,
|
| 24 |
151338
|
| 25 |
],
|
| 26 |
-
"
|
| 27 |
-
"
|
| 28 |
-
"
|
| 29 |
-
"
|
| 30 |
-
"
|
| 31 |
-
"
|
| 32 |
-
"model_type": "
|
| 33 |
-
"
|
| 34 |
-
"multi_query_group_num": 2,
|
| 35 |
-
"num_attention_heads": 4,
|
| 36 |
"num_hidden_layers": 2,
|
| 37 |
-
"
|
| 38 |
-
"original_rope": true,
|
| 39 |
"pad_token_id": 151329,
|
| 40 |
-
"
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"rope_ratio": 500,
|
| 44 |
-
"seq_length": 131072,
|
| 45 |
"tie_word_embeddings": false,
|
| 46 |
"torch_dtype": "bfloat16",
|
| 47 |
-
"transformers_version": "4.
|
| 48 |
"use_cache": true,
|
| 49 |
"vocab_size": 151552
|
| 50 |
}
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"architectures": [
|
| 3 |
+
"Glm4ForCausalLM"
|
| 4 |
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
"attention_dropout": 0.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
"eos_token_id": [
|
| 8 |
151329,
|
| 9 |
151336,
|
| 10 |
151338
|
| 11 |
],
|
| 12 |
+
"head_dim": 16,
|
| 13 |
+
"hidden_act": "silu",
|
| 14 |
+
"hidden_size": 16,
|
| 15 |
+
"initializer_range": 0.02,
|
| 16 |
+
"intermediate_size": 32,
|
| 17 |
+
"max_position_embeddings": 32768,
|
| 18 |
+
"model_type": "glm4",
|
| 19 |
+
"num_attention_heads": 1,
|
|
|
|
|
|
|
| 20 |
"num_hidden_layers": 2,
|
| 21 |
+
"num_key_value_heads": 1,
|
|
|
|
| 22 |
"pad_token_id": 151329,
|
| 23 |
+
"partial_rotary_factor": 0.5,
|
| 24 |
+
"rms_norm_eps": 1e-05,
|
| 25 |
+
"rope_theta": 10000.0,
|
|
|
|
|
|
|
| 26 |
"tie_word_embeddings": false,
|
| 27 |
"torch_dtype": "bfloat16",
|
| 28 |
+
"transformers_version": "4.52.0.dev0",
|
| 29 |
"use_cache": true,
|
| 30 |
"vocab_size": 151552
|
| 31 |
}
|
generation_config.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
| 1 |
{
|
| 2 |
-
"
|
| 3 |
"eos_token_id": [
|
| 4 |
151329,
|
| 5 |
151336,
|
| 6 |
151338
|
| 7 |
],
|
| 8 |
-
"max_length": 128000,
|
| 9 |
"pad_token_id": 151329,
|
| 10 |
-
"
|
| 11 |
-
"top_p": 0.8,
|
| 12 |
-
"transformers_version": "4.38.2"
|
| 13 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
"eos_token_id": [
|
| 4 |
151329,
|
| 5 |
151336,
|
| 6 |
151338
|
| 7 |
],
|
|
|
|
| 8 |
"pad_token_id": 151329,
|
| 9 |
+
"transformers_version": "4.52.0.dev0"
|
|
|
|
|
|
|
| 10 |
}
|
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:e34426f6099c2c1c6b73631a4cdc6c9f08f744f5a7ebca24d87c1c9b1c71cef2
|
| 3 |
+
size 9712304
|
special_tokens_map.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
| 16 |
"<|end_of_video|>"
|
| 17 |
],
|
| 18 |
"eos_token": {
|
| 19 |
-
"content": "<|
|
| 20 |
"lstrip": false,
|
| 21 |
"normalized": false,
|
| 22 |
"rstrip": false,
|
|
|
|
| 16 |
"<|end_of_video|>"
|
| 17 |
],
|
| 18 |
"eos_token": {
|
| 19 |
+
"content": "<|user|>",
|
| 20 |
"lstrip": false,
|
| 21 |
"normalized": false,
|
| 22 |
"rstrip": false,
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:76ebeac0d8bd7879ead7b43c16b44981f277e47225de2bd7de9ae1a6cc664a8c
|
| 3 |
+
size 19966496
|
tokenizer_config.json
CHANGED
|
@@ -129,18 +129,17 @@
|
|
| 129 |
"<|begin_of_video|>",
|
| 130 |
"<|end_of_video|>"
|
| 131 |
],
|
| 132 |
-
"auto_map": {
|
| 133 |
-
"AutoTokenizer": [
|
| 134 |
-
"THUDM/glm-4-9b-chat--tokenization_chatglm.ChatGLM4Tokenizer",
|
| 135 |
-
null
|
| 136 |
-
]
|
| 137 |
-
},
|
| 138 |
"clean_up_tokenization_spaces": false,
|
| 139 |
"do_lower_case": false,
|
| 140 |
-
"eos_token": "<|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
"model_max_length": 128000,
|
| 142 |
"pad_token": "<|endoftext|>",
|
| 143 |
"padding_side": "left",
|
| 144 |
"remove_space": false,
|
| 145 |
-
"tokenizer_class": "
|
| 146 |
}
|
|
|
|
| 129 |
"<|begin_of_video|>",
|
| 130 |
"<|end_of_video|>"
|
| 131 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
"clean_up_tokenization_spaces": false,
|
| 133 |
"do_lower_case": false,
|
| 134 |
+
"eos_token": "<|user|>",
|
| 135 |
+
"extra_special_tokens": {},
|
| 136 |
+
"model_input_names": [
|
| 137 |
+
"input_ids",
|
| 138 |
+
"attention_mask"
|
| 139 |
+
],
|
| 140 |
"model_max_length": 128000,
|
| 141 |
"pad_token": "<|endoftext|>",
|
| 142 |
"padding_side": "left",
|
| 143 |
"remove_space": false,
|
| 144 |
+
"tokenizer_class": "PreTrainedTokenizer"
|
| 145 |
}
|