Update README.md
Browse files
README.md
CHANGED
|
@@ -45,7 +45,7 @@ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
|
|
| 45 |
|
| 46 |
if __name__ == '__main__':
|
| 47 |
# Create an LLM.
|
| 48 |
-
llm = LLM(model="pytorch/Phi-4-mini-instruct-
|
| 49 |
# Generate texts from the prompts.
|
| 50 |
# The output is a list of RequestOutput objects
|
| 51 |
# that contain the prompt, generated text, and other information.
|
|
@@ -68,7 +68,7 @@ this is expected be resolved in pytorch 2.8.
|
|
| 68 |
## Serving
|
| 69 |
Then we can serve with the following command:
|
| 70 |
```Shell
|
| 71 |
-
vllm serve pytorch/Phi-4-mini-instruct-
|
| 72 |
```
|
| 73 |
|
| 74 |
|
|
@@ -89,7 +89,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
|
| 89 |
|
| 90 |
torch.random.manual_seed(0)
|
| 91 |
|
| 92 |
-
model_path = "pytorch/Phi-4-mini-instruct-
|
| 93 |
|
| 94 |
model = AutoModelForCausalLM.from_pretrained(
|
| 95 |
model_path,
|
|
@@ -149,7 +149,7 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
| 149 |
# Push to hub
|
| 150 |
USER_ID = "YOUR_USER_ID"
|
| 151 |
MODEL_NAME = model_id.split("/")[-1]
|
| 152 |
-
save_to = f"{USER_ID}/{MODEL_NAME}-
|
| 153 |
quantized_model.push_to_hub(save_to, safe_serialization=False)
|
| 154 |
tokenizer.push_to_hub(save_to)
|
| 155 |
|
|
@@ -193,7 +193,7 @@ We rely on [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-h
|
|
| 193 |
|
| 194 |
| Benchmark | | |
|
| 195 |
|----------------------------------|----------------|---------------------------|
|
| 196 |
-
| | Phi-4-mini-ins | Phi-4-mini-ins-
|
| 197 |
| **Popular aggregated benchmark** | | |
|
| 198 |
| mmlu (0-shot) | 66.73 | 63.56 |
|
| 199 |
| mmlu_pro (5-shot) | 46.43 | 36.74 |
|
|
@@ -224,9 +224,9 @@ https://github.com/EleutherAI/lm-evaluation-harness#install
|
|
| 224 |
lm_eval --model hf --model_args pretrained=microsoft/Phi-4-mini-instruct --tasks hellaswag --device cuda:0 --batch_size 8
|
| 225 |
```
|
| 226 |
|
| 227 |
-
## int4 weight only quantization with hqq (
|
| 228 |
```Shell
|
| 229 |
-
lm_eval --model hf --model_args pretrained=pytorch/Phi-4-mini-instruct-
|
| 230 |
```
|
| 231 |
</details>
|
| 232 |
|
|
@@ -236,7 +236,7 @@ lm_eval --model hf --model_args pretrained=pytorch/Phi-4-mini-instruct-int4wo-hq
|
|
| 236 |
|
| 237 |
| Benchmark | | |
|
| 238 |
|------------------|----------------|--------------------------------|
|
| 239 |
-
| | Phi-4 mini-Ins | Phi-4-mini-instruct-
|
| 240 |
| Peak Memory (GB) | 8.91 | 2.98 (67% reduction) |
|
| 241 |
|
| 242 |
|
|
@@ -248,8 +248,8 @@ We can use the following code to get a sense of peak memory usage during inferen
|
|
| 248 |
import torch
|
| 249 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TorchAoConfig
|
| 250 |
|
| 251 |
-
# use "microsoft/Phi-4-mini-instruct" or "pytorch/Phi-4-mini-instruct-
|
| 252 |
-
model_id = "pytorch/Phi-4-mini-instruct-
|
| 253 |
quantized_model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16)
|
| 254 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 255 |
|
|
@@ -292,7 +292,7 @@ Our int4wo is only optimized for batch size 1, so expect some slowdown with larg
|
|
| 292 |
## Results (A100 machine)
|
| 293 |
| Benchmark (Latency) | | |
|
| 294 |
|----------------------------------|----------------|----------------------------|
|
| 295 |
-
| | Phi-4 mini-Ins | phi4-mini-
|
| 296 |
| latency (batch_size=1) | 2.46s | 2.2s (1.12x speedup) |
|
| 297 |
| serving (num_prompts=1) | 0.87 req/s | 1.05 req/s (1.20x speedup) |
|
| 298 |
|
|
@@ -322,9 +322,9 @@ Run the benchmarks under `vllm` root folder:
|
|
| 322 |
python benchmarks/benchmark_latency.py --input-len 256 --output-len 256 --model microsoft/Phi-4-mini-instruct --batch-size 1
|
| 323 |
```
|
| 324 |
|
| 325 |
-
###
|
| 326 |
```Shell
|
| 327 |
-
VLLM_DISABLE_COMPILE_CACHE=1 python benchmarks/benchmark_latency.py --input-len 256 --output-len 256 --model pytorch/Phi-4-mini-instruct-
|
| 328 |
```
|
| 329 |
|
| 330 |
## benchmark_serving
|
|
@@ -354,15 +354,15 @@ Client:
|
|
| 354 |
python benchmarks/benchmark_serving.py --backend vllm --dataset-name sharegpt --tokenizer microsoft/Phi-4-mini-instruct --dataset-path ./ShareGPT_V3_unfiltered_cleaned_split.json --model microsoft/Phi-4-mini-instruct --num-prompts 1
|
| 355 |
```
|
| 356 |
|
| 357 |
-
###
|
| 358 |
Server:
|
| 359 |
```Shell
|
| 360 |
-
VLLM_DISABLE_COMPILE_CACHE=1 vllm serve pytorch/Phi-4-mini-instruct-
|
| 361 |
```
|
| 362 |
|
| 363 |
Client:
|
| 364 |
```Shell
|
| 365 |
-
python benchmarks/benchmark_serving.py --backend vllm --dataset-name sharegpt --tokenizer microsoft/Phi-4-mini-instruct --dataset-path ./ShareGPT_V3_unfiltered_cleaned_split.json --model pytorch/Phi-4-mini-instruct-
|
| 366 |
```
|
| 367 |
</details>
|
| 368 |
|
|
|
|
| 45 |
|
| 46 |
if __name__ == '__main__':
|
| 47 |
# Create an LLM.
|
| 48 |
+
llm = LLM(model="pytorch/Phi-4-mini-instruct-INT4")
|
| 49 |
# Generate texts from the prompts.
|
| 50 |
# The output is a list of RequestOutput objects
|
| 51 |
# that contain the prompt, generated text, and other information.
|
|
|
|
| 68 |
## Serving
|
| 69 |
Then we can serve with the following command:
|
| 70 |
```Shell
|
| 71 |
+
vllm serve pytorch/Phi-4-mini-instruct-INT4 --tokenizer microsoft/Phi-4-mini-instruct -O3
|
| 72 |
```
|
| 73 |
|
| 74 |
|
|
|
|
| 89 |
|
| 90 |
torch.random.manual_seed(0)
|
| 91 |
|
| 92 |
+
model_path = "pytorch/Phi-4-mini-instruct-INT4"
|
| 93 |
|
| 94 |
model = AutoModelForCausalLM.from_pretrained(
|
| 95 |
model_path,
|
|
|
|
| 149 |
# Push to hub
|
| 150 |
USER_ID = "YOUR_USER_ID"
|
| 151 |
MODEL_NAME = model_id.split("/")[-1]
|
| 152 |
+
save_to = f"{USER_ID}/{MODEL_NAME}-INT4"
|
| 153 |
quantized_model.push_to_hub(save_to, safe_serialization=False)
|
| 154 |
tokenizer.push_to_hub(save_to)
|
| 155 |
|
|
|
|
| 193 |
|
| 194 |
| Benchmark | | |
|
| 195 |
|----------------------------------|----------------|---------------------------|
|
| 196 |
+
| | Phi-4-mini-ins | Phi-4-mini-ins-INT4 |
|
| 197 |
| **Popular aggregated benchmark** | | |
|
| 198 |
| mmlu (0-shot) | 66.73 | 63.56 |
|
| 199 |
| mmlu_pro (5-shot) | 46.43 | 36.74 |
|
|
|
|
| 224 |
lm_eval --model hf --model_args pretrained=microsoft/Phi-4-mini-instruct --tasks hellaswag --device cuda:0 --batch_size 8
|
| 225 |
```
|
| 226 |
|
| 227 |
+
## int4 weight only quantization with hqq (INT4)
|
| 228 |
```Shell
|
| 229 |
+
lm_eval --model hf --model_args pretrained=pytorch/Phi-4-mini-instruct-INT4 --tasks hellaswag --device cuda:0 --batch_size 8
|
| 230 |
```
|
| 231 |
</details>
|
| 232 |
|
|
|
|
| 236 |
|
| 237 |
| Benchmark | | |
|
| 238 |
|------------------|----------------|--------------------------------|
|
| 239 |
+
| | Phi-4 mini-Ins | Phi-4-mini-instruct-INT4 |
|
| 240 |
| Peak Memory (GB) | 8.91 | 2.98 (67% reduction) |
|
| 241 |
|
| 242 |
|
|
|
|
| 248 |
import torch
|
| 249 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TorchAoConfig
|
| 250 |
|
| 251 |
+
# use "microsoft/Phi-4-mini-instruct" or "pytorch/Phi-4-mini-instruct-INT4"
|
| 252 |
+
model_id = "pytorch/Phi-4-mini-instruct-INT4"
|
| 253 |
quantized_model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16)
|
| 254 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 255 |
|
|
|
|
| 292 |
## Results (A100 machine)
|
| 293 |
| Benchmark (Latency) | | |
|
| 294 |
|----------------------------------|----------------|----------------------------|
|
| 295 |
+
| | Phi-4 mini-Ins | phi4-mini-INT4 |
|
| 296 |
| latency (batch_size=1) | 2.46s | 2.2s (1.12x speedup) |
|
| 297 |
| serving (num_prompts=1) | 0.87 req/s | 1.05 req/s (1.20x speedup) |
|
| 298 |
|
|
|
|
| 322 |
python benchmarks/benchmark_latency.py --input-len 256 --output-len 256 --model microsoft/Phi-4-mini-instruct --batch-size 1
|
| 323 |
```
|
| 324 |
|
| 325 |
+
### INT4
|
| 326 |
```Shell
|
| 327 |
+
VLLM_DISABLE_COMPILE_CACHE=1 python benchmarks/benchmark_latency.py --input-len 256 --output-len 256 --model pytorch/Phi-4-mini-instruct-INT4 --batch-size 1
|
| 328 |
```
|
| 329 |
|
| 330 |
## benchmark_serving
|
|
|
|
| 354 |
python benchmarks/benchmark_serving.py --backend vllm --dataset-name sharegpt --tokenizer microsoft/Phi-4-mini-instruct --dataset-path ./ShareGPT_V3_unfiltered_cleaned_split.json --model microsoft/Phi-4-mini-instruct --num-prompts 1
|
| 355 |
```
|
| 356 |
|
| 357 |
+
### INT4
|
| 358 |
Server:
|
| 359 |
```Shell
|
| 360 |
+
VLLM_DISABLE_COMPILE_CACHE=1 vllm serve pytorch/Phi-4-mini-instruct-INT4 --tokenizer microsoft/Phi-4-mini-instruct -O3 --pt-load-map-location cuda:0
|
| 361 |
```
|
| 362 |
|
| 363 |
Client:
|
| 364 |
```Shell
|
| 365 |
+
python benchmarks/benchmark_serving.py --backend vllm --dataset-name sharegpt --tokenizer microsoft/Phi-4-mini-instruct --dataset-path ./ShareGPT_V3_unfiltered_cleaned_split.json --model pytorch/Phi-4-mini-instruct-INT4 --num-prompts 1
|
| 366 |
```
|
| 367 |
</details>
|
| 368 |
|