Views
No views yet
vllm serve inference-optimization/Qwen3-Coder-Next.w8a8 --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.w8a8",
39 max_tokens=65536,
40 tools=tools,
41)
42
43print(completion.choices[0])1from datasets import load_dataset
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from llmcompressor import oneshot
4from llmcompressor.modifiers.quantization import GPTQModifier
5
6MODEL_ID = "Qwen/Qwen3-Coder-Next"
7
8# Load model.
9model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
10tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
11
12
13NUM_CALIBRATION_SAMPLES=512
14MAX_SEQUENCE_LENGTH=2048
15
16# Load dataset.
17ds = load_dataset("HuggingFaceH4/ultrachat_200k", split=f"train_sft[:{NUM_CALIBRATION_SAMPLES}]")
18ds = ds.shuffle(seed=42)
19
20# Preprocess the data into the format the model is trained with.
21def preprocess(example):
22 return {"text": tokenizer.apply_chat_template(example["messages"], tokenize=False, )}
23
24ds = ds.map(preprocess)
25
26# Tokenize the data (be careful with bos tokens - we need add_special_tokens=False since the chat_template already added it).
27def tokenize(sample):
28 return tokenizer(sample["text"], padding=False, max_length=MAX_SEQUENCE_LENGTH, truncation=True, add_special_tokens=False)
29ds = ds.map(tokenize, remove_columns=ds.column_names)
30
31# Configure the quantization algorithm to run.
32recipe = GPTQModifier(targets="Linear", scheme="W8A8", weight_observer="mse", ignore= ['re:.*lm_head', 're:.*mlp.gate$', 're:.*mlp.shared_expert_gate$', 're:.*linear_attn.*'])
33
34# Apply quantization.
35oneshot(
36 model=model, dataset=ds,
37 recipe=recipe,
38 max_seq_length=MAX_SEQUENCE_LENGTH,
39 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
40)
41
42# Save to disk compressed.
43SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-w8a8-G128"
44model.save_pretrained(SAVE_DIR, save_compressed=True)
45tokenizer.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.w8a8 | Recovery (%) |
|---|---|---|---|---|
| SWE-Bench | Lite | 49.33 | 42 | 85.1 |