微信扫码
添加专属顾问
我要投稿
对话模型
基座模型
长上下文
在上下文长度为1M的情况下进行大海捞针实验,结果如下:
在LongBench-Chat上进一步评估长文本能力,结果如下:
多语言
GLM-4-9B-Chat 和 Llama-3-8B-Instruct 的测试在六个多语言数据集上进行。测试结果以及每个数据集选择的对应语言如下表所示:
函数调用
多模态
GLM-4V-9B是一种具有视觉理解能力的多模态语言模型。其相关经典任务的评测结果如下:
使用 transformers 后端进行推理:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained("THUDM/glm-4-9b-chat", trust_remote_code=True)
query = "你好"
inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}],
add_generation_prompt=True,
tokenize=True,
return_tensors="pt",
return_dict=True
)
inputs = inputs.to(device)
model = AutoModelForCausalLM.from_pretrained(
"THUDM/glm-4-9b-chat",
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
trust_remote_code=True
).to(device).eval()
gen_kwargs = {"max_length": 2500, "do_sample": True, "top_k": 1}
with torch.no_grad():
outputs = model.generate(**inputs, **gen_kwargs)
outputs = outputs[:, inputs['input_ids'].shape[1]:]
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
使用 vLLM 后端进行推理:
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams
# GLM-4-9B-Chat-1M
# max_model_len, tp_size = 1048576, 4
# 如果遇见 OOM 现象,建议减少max_model_len,或者增加tp_size
max_model_len, tp_size = 131072, 1
model_name = "THUDM/glm-4-9b-chat"
prompt = [{"role": "user", "content": "你好"}]
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
llm = LLM(
model=model_name,
tensor_parallel_size=tp_size,
max_model_len=max_model_len,
trust_remote_code=True,
enforce_eager=True,
# GLM-4-9B-Chat-1M 如果遇见 OOM 现象,建议开启下述参数
# enable_chunked_prefill=True,
# max_num_batched_tokens=8192
)
stop_token_ids = [151329, 151336, 151338]
sampling_params = SamplingParams(temperature=0.95, max_tokens=1024, stop_token_ids=stop_token_ids)
inputs = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
outputs = llm.generate(prompts=inputs, sampling_params=sampling_params)
print(outputs[0].outputs[0].text)
快速调用 GLM-4V-9B 多模态模型:
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained("THUDM/glm-4v-9b", trust_remote_code=True)
query = '描述这张图片'
image = Image.open("your image").convert('RGB')
inputs = tokenizer.apply_chat_template([{"role": "user", "image": image, "content": query}],
add_generation_prompt=True, tokenize=True, return_tensors="pt",
return_dict=True)# chat mode
inputs = inputs.to(device)
model = AutoModelForCausalLM.from_pretrained(
"THUDM/glm-4v-9b",
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
trust_remote_code=True
).to(device).eval()
gen_kwargs = {"max_length": 2500, "do_sample": True, "top_k": 1}
with torch.no_grad():
outputs = model.generate(**inputs, **gen_kwargs)
outputs = outputs[:, inputs['input_ids'].shape[1]:]
print(tokenizer.decode(outputs[0]))
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-08-30
大模型的“思维链”(Chain-of-Thought):AI 是怎么一步步“推理”的
2025-08-30
Agentic AI与WorkFlow的相互成就
2025-08-29
刚刚,xAI 发布 Grok Code Fast 1 编程模型,快、便宜、免费
2025-08-29
大模型时代有了自己的「价值高速公路」
2025-08-29
A I智能革命——上下文工程新突破
2025-08-29
知识库检索准不准,关键看模型选没选对!一份评测指南请收好
2025-08-29
我如何用Prompt工程将大模型调教成风控专家
2025-08-29
度小满金融大模型技术创新与应用探索
2025-08-21
2025-06-21
2025-08-21
2025-08-19
2025-06-07
2025-06-12
2025-06-19
2025-06-13
2025-07-29
2025-06-15
2025-08-28
2025-08-28
2025-08-28
2025-08-28
2025-08-27
2025-08-26
2025-08-25
2025-08-25