Update README.md
Browse files
README.md
CHANGED
|
@@ -43,7 +43,7 @@ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
|
|
| 43 |
|
| 44 |
if __name__ == '__main__':
|
| 45 |
# Create an LLM.
|
| 46 |
-
llm = LLM(model="pytorch/Phi-4-mini-instruct-
|
| 47 |
# Generate texts from the prompts.
|
| 48 |
# The output is a list of RequestOutput objects
|
| 49 |
# that contain the prompt, generated text, and other information.
|
|
@@ -64,7 +64,7 @@ this is expected be resolved in pytorch 2.8.
|
|
| 64 |
## Serving
|
| 65 |
Then we can serve with the following command:
|
| 66 |
```Shell
|
| 67 |
-
vllm serve pytorch/Phi-4-mini-instruct-
|
| 68 |
```
|
| 69 |
|
| 70 |
# Inference with Transformers
|
|
@@ -84,7 +84,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
|
| 84 |
|
| 85 |
torch.random.manual_seed(0)
|
| 86 |
|
| 87 |
-
model_path = "pytorch/Phi-4-mini-instruct-
|
| 88 |
|
| 89 |
model = AutoModelForCausalLM.from_pretrained(
|
| 90 |
model_path,
|
|
@@ -146,7 +146,7 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
| 146 |
# Push to hub
|
| 147 |
USER_ID = "YOUR_USER_ID"
|
| 148 |
MODEL_NAME = model_id.split("/")[-1]
|
| 149 |
-
save_to = f"{USER_ID}/{MODEL_NAME}-
|
| 150 |
quantized_model.push_to_hub(save_to, safe_serialization=False)
|
| 151 |
tokenizer.push_to_hub(save_to)
|
| 152 |
|
|
@@ -189,7 +189,7 @@ We rely on [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-h
|
|
| 189 |
|
| 190 |
| Benchmark | | |
|
| 191 |
|----------------------------------|----------------|-------------------------------|
|
| 192 |
-
| | Phi-4-mini-ins | Phi-4-mini-instruct-
|
| 193 |
| **Popular aggregated benchmark** | | |
|
| 194 |
| mmlu (0-shot) | 66.73 | 66.61 |
|
| 195 |
| mmlu_pro (5-shot) | 46.43 | 44.58 |
|
|
@@ -221,9 +221,9 @@ https://github.com/EleutherAI/lm-evaluation-harness#install
|
|
| 221 |
lm_eval --model hf --model_args pretrained=microsoft/Phi-4-mini-instruct --tasks hellaswag --device cuda:0 --batch_size 8
|
| 222 |
```
|
| 223 |
|
| 224 |
-
## float8 dynamic activation and float8 weight quantization (
|
| 225 |
```Shell
|
| 226 |
-
lm_eval --model hf --model_args pretrained=pytorch/Phi-4-mini-instruct-
|
| 227 |
```
|
| 228 |
</details>
|
| 229 |
|
|
@@ -235,7 +235,7 @@ lm_eval --model hf --model_args pretrained=pytorch/Phi-4-mini-instruct-float8dq
|
|
| 235 |
|
| 236 |
| Benchmark | | |
|
| 237 |
|------------------|----------------|--------------------------------|
|
| 238 |
-
| | Phi-4 mini-Ins | Phi-4-mini-instruct-
|
| 239 |
| Peak Memory (GB) | 8.91 | 5.70 (36% reduction) |
|
| 240 |
|
| 241 |
|
|
@@ -249,8 +249,8 @@ We can use the following code to get a sense of peak memory usage during inferen
|
|
| 249 |
import torch
|
| 250 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TorchAoConfig
|
| 251 |
|
| 252 |
-
# use "microsoft/Phi-4-mini-instruct" or "pytorch/Phi-4-mini-instruct-
|
| 253 |
-
model_id = "pytorch/Phi-4-mini-instruct-
|
| 254 |
quantized_model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16)
|
| 255 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 256 |
|
|
@@ -292,7 +292,7 @@ print(f"Peak Memory Usage: {mem:.02f} GB")
|
|
| 292 |
## Results (H100 machine)
|
| 293 |
| Benchmark | | |
|
| 294 |
|----------------------------------|----------------|---------------------------------|
|
| 295 |
-
| | Phi-4 mini-Ins | Phi-4-mini-instruct-
|
| 296 |
| latency (batch_size=1) | 1.64s | 1.41s (1.16x speedup) |
|
| 297 |
| latency (batch_size=128) | 3.1s | 2.72s (1.14x speedup) |
|
| 298 |
| serving (num_prompts=1) | 1.35 req/s | 1.57 req/s (1.16x speedup) |
|
|
@@ -323,9 +323,9 @@ Run the benchmarks under `vllm` root folder:
|
|
| 323 |
python benchmarks/benchmark_latency.py --input-len 256 --output-len 256 --model microsoft/Phi-4-mini-instruct --batch-size 1
|
| 324 |
```
|
| 325 |
|
| 326 |
-
###
|
| 327 |
```Shell
|
| 328 |
-
VLLM_DISABLE_COMPILE_CACHE=1 python benchmarks/benchmark_latency.py --input-len 256 --output-len 256 --model pytorch/Phi-4-mini-instruct-
|
| 329 |
```
|
| 330 |
|
| 331 |
## benchmark_serving
|
|
@@ -352,15 +352,15 @@ Client:
|
|
| 352 |
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
|
| 353 |
```
|
| 354 |
|
| 355 |
-
###
|
| 356 |
Server:
|
| 357 |
```Shell
|
| 358 |
-
VLLM_DISABLE_COMPILE_CACHE=1 vllm serve pytorch/Phi-4-mini-instruct-
|
| 359 |
```
|
| 360 |
|
| 361 |
Client:
|
| 362 |
```Shell
|
| 363 |
-
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-
|
| 364 |
```
|
| 365 |
|
| 366 |
</details>
|
|
|
|
| 43 |
|
| 44 |
if __name__ == '__main__':
|
| 45 |
# Create an LLM.
|
| 46 |
+
llm = LLM(model="pytorch/Phi-4-mini-instruct-FP8")
|
| 47 |
# Generate texts from the prompts.
|
| 48 |
# The output is a list of RequestOutput objects
|
| 49 |
# that contain the prompt, generated text, and other information.
|
|
|
|
| 64 |
## Serving
|
| 65 |
Then we can serve with the following command:
|
| 66 |
```Shell
|
| 67 |
+
vllm serve pytorch/Phi-4-mini-instruct-FP8 --tokenizer microsoft/Phi-4-mini-instruct -O3
|
| 68 |
```
|
| 69 |
|
| 70 |
# Inference with Transformers
|
|
|
|
| 84 |
|
| 85 |
torch.random.manual_seed(0)
|
| 86 |
|
| 87 |
+
model_path = "pytorch/Phi-4-mini-instruct-FP8"
|
| 88 |
|
| 89 |
model = AutoModelForCausalLM.from_pretrained(
|
| 90 |
model_path,
|
|
|
|
| 146 |
# Push to hub
|
| 147 |
USER_ID = "YOUR_USER_ID"
|
| 148 |
MODEL_NAME = model_id.split("/")[-1]
|
| 149 |
+
save_to = f"{USER_ID}/{MODEL_NAME}-FP8"
|
| 150 |
quantized_model.push_to_hub(save_to, safe_serialization=False)
|
| 151 |
tokenizer.push_to_hub(save_to)
|
| 152 |
|
|
|
|
| 189 |
|
| 190 |
| Benchmark | | |
|
| 191 |
|----------------------------------|----------------|-------------------------------|
|
| 192 |
+
| | Phi-4-mini-ins | Phi-4-mini-instruct-FP8 |
|
| 193 |
| **Popular aggregated benchmark** | | |
|
| 194 |
| mmlu (0-shot) | 66.73 | 66.61 |
|
| 195 |
| mmlu_pro (5-shot) | 46.43 | 44.58 |
|
|
|
|
| 221 |
lm_eval --model hf --model_args pretrained=microsoft/Phi-4-mini-instruct --tasks hellaswag --device cuda:0 --batch_size 8
|
| 222 |
```
|
| 223 |
|
| 224 |
+
## float8 dynamic activation and float8 weight quantization (FP8)
|
| 225 |
```Shell
|
| 226 |
+
lm_eval --model hf --model_args pretrained=pytorch/Phi-4-mini-instruct-FP8 --tasks hellaswag --device cuda:0 --batch_size 8
|
| 227 |
```
|
| 228 |
</details>
|
| 229 |
|
|
|
|
| 235 |
|
| 236 |
| Benchmark | | |
|
| 237 |
|------------------|----------------|--------------------------------|
|
| 238 |
+
| | Phi-4 mini-Ins | Phi-4-mini-instruct-FP8 |
|
| 239 |
| Peak Memory (GB) | 8.91 | 5.70 (36% reduction) |
|
| 240 |
|
| 241 |
|
|
|
|
| 249 |
import torch
|
| 250 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TorchAoConfig
|
| 251 |
|
| 252 |
+
# use "microsoft/Phi-4-mini-instruct" or "pytorch/Phi-4-mini-instruct-FP8"
|
| 253 |
+
model_id = "pytorch/Phi-4-mini-instruct-FP8"
|
| 254 |
quantized_model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16)
|
| 255 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 256 |
|
|
|
|
| 292 |
## Results (H100 machine)
|
| 293 |
| Benchmark | | |
|
| 294 |
|----------------------------------|----------------|---------------------------------|
|
| 295 |
+
| | Phi-4 mini-Ins | Phi-4-mini-instruct-FP8 |
|
| 296 |
| latency (batch_size=1) | 1.64s | 1.41s (1.16x speedup) |
|
| 297 |
| latency (batch_size=128) | 3.1s | 2.72s (1.14x speedup) |
|
| 298 |
| serving (num_prompts=1) | 1.35 req/s | 1.57 req/s (1.16x speedup) |
|
|
|
|
| 323 |
python benchmarks/benchmark_latency.py --input-len 256 --output-len 256 --model microsoft/Phi-4-mini-instruct --batch-size 1
|
| 324 |
```
|
| 325 |
|
| 326 |
+
### FP8
|
| 327 |
```Shell
|
| 328 |
+
VLLM_DISABLE_COMPILE_CACHE=1 python benchmarks/benchmark_latency.py --input-len 256 --output-len 256 --model pytorch/Phi-4-mini-instruct-FP8 --batch-size 1
|
| 329 |
```
|
| 330 |
|
| 331 |
## benchmark_serving
|
|
|
|
| 352 |
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
|
| 353 |
```
|
| 354 |
|
| 355 |
+
### FP8
|
| 356 |
Server:
|
| 357 |
```Shell
|
| 358 |
+
VLLM_DISABLE_COMPILE_CACHE=1 vllm serve pytorch/Phi-4-mini-instruct-FP8 --tokenizer microsoft/Phi-4-mini-instruct -O3
|
| 359 |
```
|
| 360 |
|
| 361 |
Client:
|
| 362 |
```Shell
|
| 363 |
+
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-FP8 --num-prompts 1
|
| 364 |
```
|
| 365 |
|
| 366 |
</details>
|