Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "RedHatAI/MiniMax-M2.5-quantized.w4a16"
5number_gpus = 1
6sampling_params = SamplingParams(temperature=1.0, top_p=0.95, top_k=40, min_p=0, max_tokens=256)
7
8messages = [
9 {"role": "user", "content": prompt}
10]
11
12tokenizer = AutoTokenizer.from_pretrained(model_id)
13
14messages = [{"role": "user", "content": "Give me a short introduction to large language model."}]
15
16prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
17
18llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
19
20outputs = llm.generate(prompts, sampling_params)
21
22generated_text = outputs[0].outputs[0].text
23print(generated_text)1from datasets import load_dataset
2from transformers import AutoModelForCausalLM, AutoTokenizer, AutoProcessor
3from llmcompressor import oneshot
4from llmcompressor.modifiers.quantization import GPTQModifier
5
6MODEL_ID = "RedHatAI/MiniMax-M2.5-BF16"
7
8# Load model.
9model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto", trust_remote_code=True)
10tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
11processor = AutoProcessor.from_pretrained(MODEL_ID)
12
13
14NUM_CALIBRATION_SAMPLES=512
15MAX_SEQUENCE_LENGTH=2048
16
17# Load dataset.
18ds = load_dataset("HuggingFaceH4/ultrachat_200k", split=f"train_sft[:{NUM_CALIBRATION_SAMPLES}]", trust_remote_code=True)
19ds = ds.shuffle(seed=42)
20
21# Preprocess the data into the format the model is trained with.
22def preprocess(example):
23 return {"text": tokenizer.apply_chat_template(example["messages"], tokenize=False, )}
24
25ds = ds.map(preprocess)
26
27# Tokenize the data (be careful with bos tokens - we need add_special_tokens=False since the chat_template already added it).
28def tokenize(sample):
29 return tokenizer(sample["text"], padding=False, max_length=MAX_SEQUENCE_LENGTH, truncation=True, add_special_tokens=False)
30ds = ds.map(tokenize, remove_columns=ds.column_names)
31
32# Configure the quantization algorithm to run.
33recipe = GPTQModifier( scheme="W4A16", weight_observer="mse", targets= [r"re:.*block_sparse_moe\.experts\.\d+\.w[1-3]$", r"re:.*mlp\.experts\.\d+\.(gate|up|gate_up|down)_proj$" ], ignore=["re:.*self_attn.*", "lm_head"])
34
35
36# Apply quantization.
37oneshot(
38 model=model, dataset=ds,
39 recipe=recipe,
40 max_seq_length=MAX_SEQUENCE_LENGTH,
41 processor=processor,
42 num_calibration_samples=NUM_CALIBRATION_SAMPLES
43)
44
45# Save to disk compressed.
46SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + ".w4a16"
47model.save_pretrained(SAVE_DIR, save_compressed=True)
48tokenizer.save_pretrained(SAVE_DIR)vllm serve RedHatAI/MiniMax-M2.5.w4a16 --max-model-len 262144 --reasoning-parser deepseek_r1lm_eval --model local-chat-completions \
--tasks mmlu_pro_chat \
--model_args "model=RedHatAI/MiniMax-M2.5.w4a16,max_length=262144,base_url=http://0.0.0.0:8000/v1/chat/completions,num_concurrent=64,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=1200" \
--num_fewshot 0 \
--apply_chat_template \
--gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,top_k=40,min_p=0.0,max_gen_toks=64000lm_eval --model local-chat-completions \
--tasks ifeval \
--model_args "model=RedHatAI/MiniMax-M2.5.w4a16,max_length=262144,base_url=http://0.0.0.0:8000/v1/chat/completions,num_concurrent=64,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=1200" \
--num_fewshot 0 \
--apply_chat_template \
--gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,top_k=40,min_p=0.0,max_gen_toks=64000lm_eval --model local-chat-completions \
--tasks gsm8k_platinum_cot_llama \
--model_args "model=RedHatAI/MiniMax-M2.5.w4a16,max_length=262144,base_url=http://0.0.0.0:8000/v1/chat/completions,num_concurrent=64,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=1200" \
--num_fewshot 0 \
--apply_chat_template \
--gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,top_k=40,min_p=0.0,max_gen_toks=640001model_parameters:
2 model_name: RedHatAI/MiniMax-M2.5.w4a16
3 dtype: auto
4 gpu_memory_utilization: 0.9
5 max_model_length: 40960
6 generation_parameters:
7 temperature: 1.0
8 top_k: 40
9 min_p: 0.0
10 top_p: 0.95
11 max_new_tokens: 64000lighteval endpoint litellm lighteval_model_arguments.yaml \
"aime25|0,math_500|0,gpqa:diamond|0"| Benchmark | RedHatAI/MiniMax-M2.5-BF16 | RedHatAI/MiniMax-M2.5.w4a16 | Recovery (%) |
|---|---|---|---|
| GSM8k Platinum (0-shot) | 95.15 | 96.36 | 101.27 |
| IfEval (0-shot) | 92.05 | 90.45 | 98.26 |
| AIME 2025 | 87.50 | 84.17 | 96.19 |
| GPQA diamond | 83.67 | 84.51 | 101.01 |
| Math 500 | 87.33 | 87.60 | 100.31 |
| MMLU Pro Chat | 80.83 | 81.25 | 100.51 |