Views
No views yet

1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4path = "openbmb/MiniCPM4-0.5B-QAT-Int4-unquantized"
5device = "cuda"
6
7tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
8model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)
9
10messages = [
11 {"role": "user", "content": "推荐5个北京的景点。"},
12]
13model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(device)
14
15model_outputs = model.generate(
16 model_inputs,
17 max_new_tokens=1024,
18 top_p=0.7,
19 temperature=0.7
20)
21
22output_token_ids = [
23 model_outputs[i][len(model_inputs[i]):] for i in range(len(model_inputs))
24]
25
26responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0]
27print(responses)
281from transformers import AutoTokenizer
2from vllm import LLM, SamplingParams
3
4model_name = "openbmb/MiniCPM4-0.5B-QAT-Int4-unquantized"
5prompt = [{"role": "user", "content": "推荐5个北京的景点。"}]
6
7tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
8input_text = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
9
10llm = LLM(
11 model=model_name,
12 trust_remote_code=True,
13 max_num_batched_tokens=32768,
14 dtype="bfloat16",
15 gpu_memory_utilization=0.8,
16)
17sampling_params = SamplingParams(top_p=0.7, temperature=0.7, max_tokens=1024, repetition_penalty=1.02)
18
19outputs = llm.generate(prompts=input_text, sampling_params=sampling_params)
20
21print(outputs[0].outputs[0].text)| Model | Qwen3 | Llama3.2 | Gemma3 | MiniCPM4 | MiniCPM4 | MiniCPM4 |
|---|---|---|---|---|---|---|
| #Paramete | 0.6B | 1B | 1B | 0.5B | 0.5B | 0.5B |
| #Precision | BF16 | BF16 | BF16 | BF16 | Int4(Fake) | Int4(GPTQ) |
| MMLU | 42.95 | 46.89 | 41.64 | 55.55 | 55.46 | 53.93 |
| CMMLU | 42.05 | 23.73 | 25.09 | 65.22 | 63.91 | 63.73 |
| Ceval | 45.53 | 36.74 | 31.83 | 66.11 | 64.85 | 65.22 |
| BBH | 28.32 | 25.42 | 33.21 | 49.87 | 48.81 | 49.09 |
| GSM8K | 61.71 | 39.76 | 61.26 | 52.08 | 45.41 | 45.49 |
| MBPP | 47.86 | 47.47 | 59.92 | 59.14 | 55.64 | 55.25 |
| AVERAGE | 44.73 | 36.66 | 42.15 | 58.00 | 55.68 | 55.45 |
1@article{minicpm4,
2 title={{MiniCPM4}: Ultra-Efficient LLMs on End Devices},
3 author={MiniCPM Team},
4 year={2025}
5}