GLM4模型開源,意料之中的尺寸,意料之外的效果
今天智譜開了GLM-4-9B的模型,不是6B,是9B。
一共開源了四個模型,Base版本模型(GLM-4-9B)、Chat版本模型(GLM-4-9B-Chat和GLM-4-9B-Chat-1M)和多模態模型(GLM-4V-9B-Chat)。
其中,模型為多語言模型除了支持中文、英文之外,還支持日語,韓語,德語在內的26種語言;Chat系列模型支持網頁瀏覽、代碼執行、自定義工具調用(Function Call)的能力;GLM-4V-9B模型支持中英雙語多輪對話能力。
Github: https://github.com/THUDM/GLM-4
HF: https://huggingface.co/collections/THUDM/glm-4-665fcf188c414b03c2f7e3b7
模型說明
GLM-4-9B模型的結構與GLM-3-6B模型結構一致,主要修改為模型層數、詞表大小、支持更長的上下文。
- 詞表由65024增加到151552;
- 模型層數由28增加到40;
- 最大長度之前的32K、128K到128K、1M。
模型的License還是免費學術研究、商業需要登記,但必須遵守相關條款和條件,與GLM3一致。
效果說明
效果一句話總結,全面領先Llama-3-8B模型,全面領先上一代ChatGLM3-6B模型。(這讓我更加期待過兩天即將開源的Qwen2系列模型的效果啦,開源真的越來越好了)
下面效果來自于官方Github效果截圖。
在Base和Chat模型上,GLM-4-9B均優于Llama-3-8B模型。
Base
Chat
1M模型上進行大海撈針,效果全綠。
工具調用上,也是優于Llama-3-8B模型。
最后是GLM-4V-9B多模態模型效果,全面領先前一陣爆火的面壁MiniCPM-Llama3-V2.5多模態模型(畢竟斯坦福都來抄)。
現在這些榜單的效果雖然可以展現出來一定能力,但我還是更相信對戰榜單,后面不知道lmsys上會不會有GLM-4-9B-Chat的效果,真實場景中PK一把,看看誰弱誰強。
快速調用
直接transformers走起,以GLM-4-9B-Chat模型為例。
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": 5}
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))
贊
收藏
回復
分享
微博
QQ
微信
舉報

回復
相關推薦