Update README.md
Browse files
README.md
CHANGED
|
@@ -1,4 +1,126 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
-
|
| 4 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
tags:
|
| 3 |
+
- fp8
|
| 4 |
+
- vllm
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
base_model: sarvamai/sarvam-30b
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
# sarvam-30b-FP8-dynamic
|
| 10 |
+
|
| 11 |
+
## Model Overview
|
| 12 |
+
- **Model Architecture:** sarvamai/sarvam-30b
|
| 13 |
+
- **Input:** Text
|
| 14 |
+
- **Output:** Text
|
| 15 |
+
- **Model Optimizations:**
|
| 16 |
+
- **Weight quantization:** FP8
|
| 17 |
+
- **Activation quantization:** FP8
|
| 18 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws).
|
| 19 |
+
- **Version:** 1.0
|
| 20 |
+
- **Model Developers:** RedHatAI
|
| 21 |
+
|
| 22 |
+
This model is a quantized version of [sarvamai/sarvam-30b](https://huggingface.co/sarvamai/sarvam-30b).
|
| 23 |
+
It was evaluated on several tasks to assess its quality in comparison to the unquantized model.
|
| 24 |
+
|
| 25 |
+
### Model Optimizations
|
| 26 |
+
|
| 27 |
+
This model was obtained by quantizing the weights and activations of [sarvamai/sarvam-30b](https://huggingface.co/sarvamai/sarvam-30b) to FP8 data type, ready for inference with vLLM.
|
| 28 |
+
|
| 29 |
+
Only the weights and activations of the linear operators within transformers blocks are quantized using [LLM Compressor](https://github.com/vllm-project/llm-compressor).
|
| 30 |
+
|
| 31 |
+
## Deployment
|
| 32 |
+
|
| 33 |
+
### Use with vLLM
|
| 34 |
+
|
| 35 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend.
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
1. Install vLLM from main:
|
| 39 |
+
```
|
| 40 |
+
uv pip install -U git+https://github.com/vllm-project/vllm.git \
|
| 41 |
+
--extra-index-url https://wheels.vllm.ai/nightly \
|
| 42 |
+
--no-deps \
|
| 43 |
+
--no-cache
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
2. Run using vLLM
|
| 47 |
+
```python
|
| 48 |
+
from vllm import LLM, SamplingParams
|
| 49 |
+
from transformers import AutoTokenizer
|
| 50 |
+
|
| 51 |
+
model_id = "RedHatAI/sarvam-30b-FP8-dynamic"
|
| 52 |
+
number_gpus = 1
|
| 53 |
+
|
| 54 |
+
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
|
| 55 |
+
|
| 56 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 57 |
+
|
| 58 |
+
messages = [
|
| 59 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
| 60 |
+
{"role": "user", "content": "Who are you?"},
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
|
| 64 |
+
|
| 65 |
+
llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
|
| 66 |
+
|
| 67 |
+
outputs = llm.generate(prompts, sampling_params)
|
| 68 |
+
|
| 69 |
+
generated_text = outputs[0].outputs[0].text
|
| 70 |
+
print(generated_text)
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
| 74 |
+
|
| 75 |
+
## Creation
|
| 76 |
+
|
| 77 |
+
This model was created by applying [LLM Compressor](https://github.com/vllm-project/llm-compressor), as presented in the code snippet below.
|
| 78 |
+
|
| 79 |
+
<details>
|
| 80 |
+
```python
|
| 81 |
+
from compressed_tensors.offload import dispatch_model
|
| 82 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 83 |
+
|
| 84 |
+
from llmcompressor import oneshot
|
| 85 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
| 86 |
+
|
| 87 |
+
MODEL_ID = "sarvamai/sarvam-30b"
|
| 88 |
+
|
| 89 |
+
# Load model.
|
| 90 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, dtype="auto", trust_remote_code=True)
|
| 91 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 92 |
+
|
| 93 |
+
# Configure the quantization algorithm and scheme.
|
| 94 |
+
# In this case, we:
|
| 95 |
+
# * quantize the weights to fp8 with per channel via ptq
|
| 96 |
+
# * quantize the activations to fp8 with dynamic per token
|
| 97 |
+
recipe = QuantizationModifier(
|
| 98 |
+
targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"]
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
# Apply quantization.
|
| 102 |
+
oneshot(model=model, recipe=recipe)
|
| 103 |
+
|
| 104 |
+
# Confirm generations of the quantized model look sane.
|
| 105 |
+
print("========== SAMPLE GENERATION ==============")
|
| 106 |
+
dispatch_model(model)
|
| 107 |
+
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
|
| 108 |
+
model.device
|
| 109 |
+
)
|
| 110 |
+
output = model.generate(input_ids, max_new_tokens=20)
|
| 111 |
+
print(tokenizer.decode(output[0]))
|
| 112 |
+
print("==========================================")
|
| 113 |
+
|
| 114 |
+
# Save to disk in compressed-tensors format.
|
| 115 |
+
SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-FP8-Dynamic"
|
| 116 |
+
model.save_pretrained(SAVE_DIR)
|
| 117 |
+
tokenizer.save_pretrained(SAVE_DIR)
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
</details>
|
| 121 |
+
|
| 122 |
+
## Evaluation
|
| 123 |
+
|
| 124 |
+
This model was evaluated on the well-known text benchmarks using [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness).
|
| 125 |
+
|
| 126 |
+
### Accuracy
|