Views
No views yet


vllm serve inference-optimization/Qwen3-Coder-Next-NVFP4 --port 8000 --tensor-parallel-size 2 --enable-auto-tool-choice --tool-call-parser qwen3_coder
1# Your tool implementation
2def square_the_number(num: float) -> dict:
3 return num ** 2
4
5# Define Tools
6tools=[
7 {
8 "type":"function",
9 "function":{
10 "name": "square_the_number",
11 "description": "output the square of the number.",
12 "parameters": {
13 "type": "object",
14 "required": ["input_num"],
15 "properties": {
16 'input_num': {
17 'type': 'number',
18 'description': 'input_num is a number that will be squared'
19 }
20 },
21 }
22 }
23 }
24]
25
26from openai import OpenAI
27# Define LLM
28client = OpenAI(
29 # Use a custom endpoint compatible with OpenAI API
30 base_url='http://localhost:8000/v1', # api_base
31 api_key="EMPTY"
32)
33
34messages = [{'role': 'user', 'content': 'square the number 1024'}]
35
36completion = client.chat.completions.create(
37 messages=messages,
38 model="RedHatAI/Qwen3-Coder-Next-NVFP4",
39 max_tokens=65536,
40 tools=tools,
41)
42
43print(completion.choices[0])1from transformers import AutoModelForCausalLM, AutoTokenizer
2from datasets import load_dataset
3
4from llmcompressor import oneshot
5from llmcompressor.modifiers.quantization import QuantizationModifier
6from compressed_tensors.offload import dispatch_model
7
8MODEL_ID = "Qwen/Qwen3-Coder-Next"
9
10# Load model.
11model = AutoModelForCausalLM.from_pretrained(
12 MODEL_ID,
13 torch_dtype="auto",
14 low_cpu_mem_usage=True,
15 trust_remote_code=True,
16)
17tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
18
19DATASET_ID = "HuggingFaceH4/ultrachat_200k"
20DATASET_SPLIT = "train_sft"
21
22# Select number of samples
23NUM_CALIBRATION_SAMPLES = 20
24MAX_SEQUENCE_LENGTH = 2048
25
26# Load dataset and preprocess.
27ds = load_dataset(DATASET_ID, split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES}]")
28ds = ds.shuffle(seed=42)
29
30
31def preprocess(example):
32 return {
33 "text": tokenizer.apply_chat_template(
34 example["messages"],
35 tokenize=False,
36 )
37 }
38
39
40ds = ds.map(preprocess)
41
42
43# Tokenize inputs.
44def tokenize(sample):
45 return tokenizer(
46 sample["text"],
47 padding=False,
48 max_length=MAX_SEQUENCE_LENGTH,
49 truncation=True,
50 add_special_tokens=False,
51 )
52
53
54ds = ds.map(tokenize, remove_columns=ds.column_names)
55
56
57
58recipe = QuantizationModifier(
59 targets="Linear",
60 scheme="NVFP4",
61 weight_observer="mse",
62 ignore= ['re:.*lm_head', 're:.*mlp.gate$', 're:.*mlp.shared_expert_gate$', 're:.*linear_attn.*'],
63)
64
65
66oneshot(
67 model=model,
68 dataset=ds,
69 recipe=recipe,
70 max_seq_length=MAX_SEQUENCE_LENGTH,
71 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
72 moe_calibrate_all_experts=True,
73)
74
75
76print("\n\n")
77print("========== SAMPLE GENERATION ==============")
78
79dispatch_model(model)
80
81input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
82 model.device
83)
84output = model.generate(input_ids, max_new_tokens=100)
85print(tokenizer.decode(output[0]))
86print("==========================================\n\n")
87
88
89# Save to disk in compressed-tensors format.
90SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4"
91model.save_pretrained(SAVE_DIR, save_compressed=True)
92tokenizer.save_pretrained(SAVE_DIR)python -m swebench.harness.run_evaluation \
--dataset_name princeton-nlp/SWE-bench_Lite \
--predictions_path preds.json \
--run_id validate-preds| Category | Metric | Qwen3-Coder-Next | Qwen3-Coder-Next-NVFP4 | Recovery (%) |
|---|---|---|---|---|
| SWE-Bench | Lite | 49.33 | 52 | 105.4 |