Views
No views yet
vllm serve inference-optimization/Qwen3-Coder-Next-FP8-dynamic --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-FP8-dynamic",
39 max_tokens=65536,
40 tools=tools,
41)
42
43print(completion.choices[0])1from datasets import load_dataset
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4from llmcompressor import oneshot
5from llmcompressor.modifiers.quantization import QuantizationModifier
6from llmcompressor.utils import dispatch_for_generation
7
8# NOTE: Requires a minimum of transformers 4.57.0
9
10MODEL_ID = "Qwen/Qwen3-Coder-Next"
11
12# Load model.
13model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
14tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
15
16
17# Configure the quantization algorithm and scheme.
18# In this case, we:
19# * quantize the weights to fp8 with per channel via ptq
20# * quantize the activations to fp8 with dynamic per token
21recipe = QuantizationModifier(
22 targets="Linear", scheme="FP8_DYNAMIC", ignore=[
23 "re:.*lm_head",
24 "re:.*mlp.gate$",
25 "re:.*mlp.shared_expert_gate$",
26 "re:.*linear_attn.*",
27 ],
28 weight_observer="mse"
29)
30
31# Apply quantization.
32oneshot(model=model, recipe=recipe)
33
34# Confirm generations of the quantized model look sane.
35print("========== SAMPLE GENERATION ==============")
36dispatch_for_generation(model)
37input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
38 model.device
39)
40output = model.generate(input_ids, max_new_tokens=20)
41print(tokenizer.decode(output[0]))
42print("==========================================")
43
44# Save to disk in compressed-tensors format.
45SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-FP8-dynamic"
46model.save_pretrained(SAVE_DIR)
47tokenizer.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-FP8-dynamic | Recovery (%) |
|---|---|---|---|---|
| SWE-Bench | Lite | 49.33 | 53 | 107.4 |