初始化项目,由ModelHub XC社区提供模型

Model: RedHatAI/Phi-3-medium-128k-instruct-quantized.w8a8
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-09-10 08:16:12 +08:00
commit 1f768d8698
19 changed files with 583 additions and 0 deletions

35
.gitattributes vendored Normal file
View File

@@ -0,0 +1,35 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text

234
README.md Normal file
View File

@@ -0,0 +1,234 @@
---
language:
- en
pipeline_tag: text-generation
license: mit
---
# Phi-3-medium-128k-instruct-quantized.w8a8
## Model Overview
- **Model Architecture:** Phi-3
- **Input:** Text
- **Output:** Text
- **Model Optimizations:**
- **Activation quantization:** INT8
- **Weight quantization:** INT8
- **Intended Use Cases:** Intended for commercial and research use in English. Similarly to [Phi-3-medium-128k-instruct](https://huggingface.co/microsoft/Phi-3-medium-128k-instruct), this models is intended for assistant-like chat.
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
- **Release Date:** 7/11/2024
- **Version:** 1.0
- **License(s):** [MIT](https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/mit.md)
- **Model Developers:** Neural Magic
Quantized version of [Phi-3-medium-128k-instruct](https://huggingface.co/microsoft/Phi-3-medium-128k-instruct), a 14 billion-parameter open model trained using the Phi-3 datasets.
It achieves an average score of 73.90 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 74.10.
### Model Optimizations
This model was obtained by quantizing the weights of [Phi-3-medium-128k-instruct](https://huggingface.co/microsoft/Phi-3-medium-128k-instruct) to INT8 data type.
This optimization reduces the number of bits used to represent weights and activations from 16 to 8, reducing GPU memory requirements (by approximately 50%) and increasing matrix-multiply compute throughput (by approximately 2x).
Weight quantization also reduces disk size requirements by approximately 50%.
Only weights and activations of the linear operators within transformers blocks are quantized.
Weights are quantized with a symmetric static per-channel scheme, where a fixed linear scaling factor is applied between INT8 and floating point representations for each output channel dimension.
Activations are quantized with a symmetric dynamic per-token scheme, computing a linear scaling factor at runtime for each token between INT8 and floating point representations.
Linear scaling factors are computed via by minimizing the mean squarred error (MSE).
The [SmoothQuant](https://arxiv.org/abs/2211.10438) algorithm is used to alleviate outliers in the activations, whereas rhe [GPTQ](https://arxiv.org/abs/2210.17323) algorithm is applied for quantization.
Both algorithms are implemented in the [llm-compressor](https://github.com/vllm-project/llm-compressor) library.
GPTQ used a 1% damping factor and 512 sequences sequences taken from Neural Magic's [LLM compression calibration dataset](https://huggingface.co/datasets/neuralmagic/LLM_compression_calibration).
## Deployment
### Use with vLLM
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below (using 2 GPUs).
```python
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
model_id = "neuralmagic/Phi-3-medium-128k-instruct-quantized.w8a8"
number_gpus = 2
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
tokenizer = AutoTokenizer.from_pretrained(model_id)
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": "Who are you?"},
]
prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
llm = LLM(model=model_id, trust_remote_code=True, max_model_len=8196, tensor_parallel_size=number_gpus)
outputs = llm.generate(prompts, sampling_params)
generated_text = outputs[0].outputs[0].text
print(generated_text)
```
vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
## Creation
This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
```python
from transformers import AutoTokenizer
from datasets import Dataset
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
from llmcompressor.modifiers.quantization import GPTQModifier
import random
model_id = "microsoft/Phi-3-medium-128k-instruct"
num_samples = 512
max_seq_len = 8192
tokenizer = AutoTokenizer.from_pretrained(model_id)
def preprocess_fn(example):
return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
ds = ds.shuffle().select(range(num_samples))
ds = ds.map(preprocess_fn)
recipe = [
SmoothQuantModifier(
smoothing_strength=0.8,
mappings=[
[["re:.*qkv_proj"], "re:.*input_layernorm"],
[["re:.*gate_up_proj"], "re:.*post_attention_layernorm"],
],
),
GPTQModifier(
sequential=True,
targets="Linear",
scheme="W8A8",
ignore=["lm_head"],
dampening_frac=0.01,
observer="mse",
)
]
model = SparseAutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
trust_remote_code=True,
)
oneshot(
model=model,
dataset=ds,
recipe=recipe,
max_seq_length=max_seq_len,
num_calibration_samples=num_samples,
)
model.save_pretrained("Phi-3-medium-128k-instruct-quantized.w8a8")
```
## Evaluation
The model was evaluated on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) leaderboard tasks (version 1) with the [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness/tree/383bbd54bc621086e05aa1b030d8d4d5635b25e6) (commit 383bbd54bc621086e05aa1b030d8d4d5635b25e6) and the [vLLM](https://docs.vllm.ai/en/stable/) engine, using the following command (using 2 GPUs):
```
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Phi-3-medium-128k-instruct-quantized.w8a8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
--tasks openllm \
--batch_size auto
```
### Accuracy
#### Open LLM Leaderboard evaluation scores
<table>
<tr>
<td><strong>Benchmark</strong>
</td>
<td><strong>Phi-3-medium-128k-instruct </strong>
</td>
<td><strong>Phi-3-medium-128k-instruct-quantized.w8a8 (this model)</strong>
</td>
<td><strong>Recovery</strong>
</td>
</tr>
<tr>
<td>MMLU (5-shot)
</td>
<td>76.69
</td>
<td>76.74
</td>
<td>100.1%
</td>
</tr>
<tr>
<td>ARC Challenge (25-shot)
</td>
<td>69.45
</td>
<td>69.37
</td>
<td>99.9%
</td>
</tr>
<tr>
<td>GSM-8K (5-shot, strict-match)
</td>
<td>85.22
</td>
<td>84.15
</td>
<td>98.7%
</td>
</tr>
<tr>
<td>Hellaswag (10-shot)
</td>
<td>85.10
</td>
<td>84.76
</td>
<td>99.6%
</td>
</tr>
<tr>
<td>Winogrande (5-shot)
</td>
<td>73.56
</td>
<td>73.80
</td>
<td>100.3%
</td>
</tr>
<tr>
<td>TruthfulQA (0-shot)
</td>
<td>54.57
</td>
<td>54.57
</td>
<td>100.0%
</td>
</tr>
<tr>
<td><strong>Average</strong>
</td>
<td><strong>74.10</strong>
</td>
<td><strong>73.90</strong>
</td>
<td><strong>99.7%</strong>
</td>
</tr>
</table>

13
added_tokens.json Normal file
View File

@@ -0,0 +1,13 @@
{
"<|assistant|>": 32001,
"<|endoftext|>": 32000,
"<|end|>": 32007,
"<|placeholder1|>": 32002,
"<|placeholder2|>": 32003,
"<|placeholder3|>": 32004,
"<|placeholder4|>": 32005,
"<|placeholder5|>": 32008,
"<|placeholder6|>": 32009,
"<|system|>": 32006,
"<|user|>": 32010
}

210
config.json Normal file
View File

@@ -0,0 +1,210 @@
{
"_name_or_path": "/root/.cache/huggingface/hub/models--microsoft--Phi-3-medium-128k-instruct/snapshots/fa7d2aa4f5ea69b2e36b20d050cdae79c9bfbb3f",
"architectures": [
"Phi3ForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"auto_map": {
"AutoConfig": "configuration_phi3.Phi3Config",
"AutoModelForCausalLM": "modeling_phi3.Phi3ForCausalLM"
},
"bos_token_id": 1,
"embd_pdrop": 0.0,
"eos_token_id": 32000,
"hidden_act": "silu",
"hidden_size": 5120,
"initializer_range": 0.02,
"intermediate_size": 17920,
"max_position_embeddings": 131072,
"model_type": "phi3",
"num_attention_heads": 40,
"num_hidden_layers": 40,
"num_key_value_heads": 10,
"original_max_position_embeddings": 4096,
"pad_token_id": null,
"resid_pdrop": 0.0,
"rms_norm_eps": 1e-05,
"rope_scaling": {
"long_factor": [
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.25,
1.25,
1.5,
2.0,
2.75,
5.75,
5.75,
6.5,
9.25,
11.0,
13.25,
19.25,
19.75,
19.75,
21.25,
21.5,
26.5,
30.0,
33.75,
35.25,
38.5,
42.0,
42.25,
46.0,
47.0,
50.0,
50.5,
51.0,
52.0,
52.75,
53.75,
54.75,
57.0,
57.25,
58.5,
59.25,
59.5,
62.0,
62.5,
62.75,
63.25,
63.25,
63.25,
63.75,
64.0,
64.0,
64.25,
64.5,
64.5,
65.0,
65.0
],
"short_factor": [
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.01,
1.02,
1.02,
1.04,
1.04,
1.07,
1.07,
1.1,
1.3000000000000003,
1.3000000000000003,
1.5000000000000004,
1.5700000000000005,
1.9000000000000008,
2.3100000000000014,
2.759999999999992,
3.3899999999999784,
3.9399999999999666,
4.009999999999965,
4.289999999999959,
4.349999999999958,
5.349999999999937,
6.659999999999909,
7.029999999999901,
7.51999999999989,
8.00999999999988,
8.249999999999876,
8.279999999999875,
9.629999999999846,
9.89999999999984,
10.589999999999826,
11.049999999999816,
11.7899999999998,
12.189999999999792,
12.889999999999777,
13.129999999999772,
13.16999999999977,
13.20999999999977,
13.479999999999764,
13.539999999999763,
13.779999999999758,
13.929999999999755,
14.429999999999744,
14.759999999999737,
15.149999999999729,
15.419999999999723,
15.53999999999972,
15.659999999999718,
15.749999999999716,
15.759999999999716,
15.799999999999715,
16.05999999999971,
16.079999999999714,
16.11999999999972,
16.11999999999972,
16.18999999999973,
16.31999999999975,
16.539999999999786,
16.799999999999827
],
"type": "su"
},
"rope_theta": 10000.0,
"sliding_window": 131072,
"tie_word_embeddings": false,
"torch_dtype": "bfloat16",
"transformers_version": "4.44.1",
"use_cache": true,
"vocab_size": 32064,
"quantization_config": {
"config_groups": {
"group_0": {
"input_activations": {
"block_structure": null,
"dynamic": true,
"group_size": null,
"num_bits": 8,
"observer": "memoryless",
"observer_kwargs": {},
"strategy": "token",
"symmetric": true,
"type": "int"
},
"output_activations": null,
"targets": [
"Linear"
],
"weights": {
"block_structure": null,
"dynamic": false,
"group_size": null,
"num_bits": 8,
"observer": "minmax",
"observer_kwargs": {},
"strategy": "channel",
"symmetric": true,
"type": "int"
}
}
},
"format": "int-quantized",
"global_compression_ratio": 1.1652744252495255,
"ignore": [
"lm_head"
],
"kv_cache_scheme": null,
"quant_method": "compressed-tensors",
"quantization_status": "compressed"
}
}

1
configuration.json Normal file
View File

@@ -0,0 +1 @@
{"framework": "pytorch", "task": "text-generation", "allow_remote": true}

3
configuration_phi3.py Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:18b06d379f5199bfb8b7da26da14c580f3852e792895d2bf6158b2ef33c92d52
size 10411

11
generation_config.json Normal file
View File

@@ -0,0 +1,11 @@
{
"_from_model_config": true,
"bos_token_id": 1,
"eos_token_id": [
32000,
32001,
32007
],
"pad_token_id": 32000,
"transformers_version": "4.44.1"
}

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1e92fd69d892de671d369e3d152c4f95473a2ce70b210bbf4f8085df52581ac7
size 4825810264

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ad44d52535ed9465e6814928178cc34b2e68ddd99244c3f7a8cfb89a834b95e8
size 4956401472

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:61f91273431a3e5f871441c546e8fcdd4ffa79285a962561dfbfb6b9c89658cc
size 4511123824

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2ff8c594af9ea86b784513274930dddb3e37ca81cb09aa9206039098c7b0095e
size 34524

3
modeling_phi3.py Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4887efb948d0ab263c44794e19fdb91074a677614d6d5271ae7650c4f4cb8404
size 73778

16
recipe.yaml Normal file
View File

@@ -0,0 +1,16 @@
quant_stage:
quant_modifiers:
SmoothQuantModifier:
smoothing_strength: 0.8
mappings:
- - ['re:.*qkv_proj']
- re:.*input_layernorm
- - ['re:.*gate_up_proj']
- re:.*post_attention_layernorm
GPTQModifier:
sequential_update: true
dampening_frac: 0.01
ignore: [lm_head]
scheme: W8A8
targets: Linear
observer: mse

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fc45f95bfcf0498331d659d20ba38f1cdc103da41859bde37bb036c82fb59f87
size 119474

3
sample_finetune.py Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5f811ce5cad430ea154fe7039f19f32d8d47d9d5fc826694b5020b7cf3815d21
size 6192

30
special_tokens_map.json Normal file
View File

@@ -0,0 +1,30 @@
{
"bos_token": {
"content": "<s>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"eos_token": {
"content": "<|endoftext|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"pad_token": {
"content": "<|endoftext|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"unk_token": {
"content": "<unk>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
}
}

3
tokenizer.json Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1996d98fd01946ea6e769f2a5c2bcfb429ba8223d74e7a64d23d774a4c69a6bc
size 1844535

BIN
tokenizer.model (Stored with Git LFS) Normal file

Binary file not shown.

3
tokenizer_config.json Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9331c8a2d4bb08383814c78103f6ac5fbbe058a81b1c5e6c5c6d875b4b26d25d
size 3185