Views
No views yet


uv pip install -U git+https://github.com/vllm-project/vllm.git \
--extra-index-url https://wheels.vllm.ai/nightly \
--no-deps \
--no-cache1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "RedHatAI/sarvam-30b-FP8-dynamic"
5number_gpus = 1
6
7sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
8
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11messages = [
12 {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
13 {"role": "user", "content": "Who are you?"},
14]
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)uv pip install git+https://github.com/vllm-project/llm-compressor.git
uv pip install --upgrade torchvision --break-system-packages --no-cache1from compressed_tensors.offload import dispatch_model
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4from llmcompressor import oneshot
5from llmcompressor.modifiers.quantization import QuantizationModifier
6
7MODEL_ID = "sarvamai/sarvam-30b"
8
9# Load model.
10model = AutoModelForCausalLM.from_pretrained(MODEL_ID, dtype="auto", trust_remote_code=True)
11tokenizer = AutoTokenizer.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", scheme="FP8_DYNAMIC", ignore=["lm_head"]
19)
20
21# Apply quantization.
22oneshot(model=model, recipe=recipe)
23
24# Confirm generations of the quantized model look sane.
25print("========== SAMPLE GENERATION ==============")
26dispatch_model(model)
27input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
28 model.device
29)
30output = model.generate(input_ids, max_new_tokens=20)
31print(tokenizer.decode(output[0]))
32print("==========================================")
33
34# Save to disk in compressed-tensors format.
35SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-FP8-Dynamic"
36model.save_pretrained(SAVE_DIR)
37tokenizer.save_pretrained(SAVE_DIR) lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/sarvam-30b-FP8-Dynamic",dtype=auto,add_bos_token=True,max_model_len=16384,tensor_parallel_size=2,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
--tasks openllm \
--write_out \
--batch_size auto \
--show_config| Benchmark | sarvamai/sarvam-30b | RedHatAI/sarvam-30b-FP8-Dynamic | Recovery (%) |
|---|---|---|---|
| BBH (exact_match) | 63.32 | 62.95 | 99.42% |
| GSM8K (strict-match) | 72.33 | 72.40 | 100.10% |
| GSM8K (flexible-extract) | 69.67 | 70.81 | 101.63% |
| IFEval (inst_level_strict_acc) | 34.17 | 31.65 | 92.63% |
| MMLU-Pro (exact_match) | 45.69 | 45.81 | 100.25% |
| ARC-Challenge (acc) | 58.28 | 57.76 | 99.12% |
| HellaSwag (acc) | 53.98 | 53.98 | 100.00% |
| MMLU (acc) | 66.20 | 66.15 | 99.92% |
| TruthfulQA MC2 (acc) | 50.34 | 50.58 | 100.48% |
| Winogrande (acc) | 61.09 | 61.17 | 100.13% |