Views
No views yet
1from vllm import LLM, SamplingParams
2
3# Initialize the LLM
4model_name = "neuralmagic/pixtral-12b-FP8-dynamic"
5llm = LLM(model=model_name, max_model_len=10000)
6
7# Create the prompt
8image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
9messages = [
10 {
11 "role": "user",
12 "content": [
13 {"type": "text", "text": "Describe the image."},
14 {"type": "image_url", "image_url": {"url": image_url}},
15 ],
16 },
17]
18
19# Set up sampling parameters
20sampling_params = SamplingParams(temperature=0.2, max_tokens=100)
21
22# Generate the response
23outputs = llm.chat(messages, sampling_params=sampling_params)
24
25# Print the generated text
26for output in outputs:
27 print(output.outputs[0].text)vllm serve neuralmagic/pixtral-12b-FP8-dynamic1from transformers import AutoProcessor, LlavaForConditionalGeneration
2
3from llmcompressor.modifiers.quantization import QuantizationModifier
4from llmcompressor.transformers import oneshot, wrap_hf_model_class
5
6MODEL_ID = "mistral-community/pixtral-12b"
7
8# Load model.
9model_class = wrap_hf_model_class(LlavaForConditionalGeneration)
10model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
11processor = AutoProcessor.from_pretrained(MODEL_ID)
12
13# Configure the quantization algorithm and scheme.
14# In this case, we:
15# * quantize the weights to fp8 with per channel via ptq
16# * quantize the activations to fp8 with dynamic per token
17recipe = QuantizationModifier(
18 targets="Linear",
19 scheme="FP8_DYNAMIC",
20 ignore=["re:.*lm_head", "re:multi_modal_projector.*", "re:vision_model.*"],
21)
22
23# Apply quantization and save to disk in compressed-tensors format.
24SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"
25oneshot(model=model, recipe=recipe, output_dir=SAVE_DIR)
26processor.save_pretrained(SAVE_DIR)
27
28# Confirm generations of the quantized model look sane.
29print("========== SAMPLE GENERATION ==============")
30input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
31output = model.generate(input_ids, max_new_tokens=20)
32print(processor.decode(output[0]))
33print("==========================================")| pixtral-12b | pixtral-12b-FP8-dynamic | |
|---|---|---|
| MMMU (CoT) | 49.44 | 51.11 |
| Mathvista (CoT) | 58.1 | 59.4 |
| ChartQA (CoT) | 82.64 | 82.68 |
| DocVQA (ANLS) | 89.36 | 89.35 |
| pixtral-12b | pixtral-12b-FP8-dynamic | |
|---|---|---|
| MMLU (5-shot) | 69.27 | 68.96 |
| Math (0-shot) | 43.82 | 43.27 |
| Human Eval (Pass@1) | 77.80 | 76.4 |