From 1f768d8698588efa8dbbafa46881a29560c5e324 Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Thu, 10 Sep 2026 08:16:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=8C=E7=94=B1ModelHub=20XC=E7=A4=BE=E5=8C=BA=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Model: RedHatAI/Phi-3-medium-128k-instruct-quantized.w8a8 Source: Original Platform --- .gitattributes | 35 ++++ README.md | 234 ++++++++++++++++++++++++ added_tokens.json | 13 ++ config.json | 210 +++++++++++++++++++++ configuration.json | 1 + configuration_phi3.py | 3 + generation_config.json | 11 ++ model-00001-of-00003.safetensors | 3 + model-00002-of-00003.safetensors | 3 + model-00003-of-00003.safetensors | 3 + model.safetensors.index.json | 3 + modeling_phi3.py | 3 + recipe.yaml | 16 ++ results_2024-07-10T15-10-40.715163.json | 3 + sample_finetune.py | 3 + special_tokens_map.json | 30 +++ tokenizer.json | 3 + tokenizer.model | 3 + tokenizer_config.json | 3 + 19 files changed, 583 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 added_tokens.json create mode 100644 config.json create mode 100644 configuration.json create mode 100644 configuration_phi3.py create mode 100644 generation_config.json create mode 100644 model-00001-of-00003.safetensors create mode 100644 model-00002-of-00003.safetensors create mode 100644 model-00003-of-00003.safetensors create mode 100644 model.safetensors.index.json create mode 100644 modeling_phi3.py create mode 100644 recipe.yaml create mode 100644 results_2024-07-10T15-10-40.715163.json create mode 100644 sample_finetune.py create mode 100644 special_tokens_map.json create mode 100644 tokenizer.json create mode 100644 tokenizer.model create mode 100644 tokenizer_config.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a6344aa --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..68809da --- /dev/null +++ b/README.md @@ -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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Benchmark + Phi-3-medium-128k-instruct + Phi-3-medium-128k-instruct-quantized.w8a8 (this model) + Recovery +
MMLU (5-shot) + 76.69 + 76.74 + 100.1% +
ARC Challenge (25-shot) + 69.45 + 69.37 + 99.9% +
GSM-8K (5-shot, strict-match) + 85.22 + 84.15 + 98.7% +
Hellaswag (10-shot) + 85.10 + 84.76 + 99.6% +
Winogrande (5-shot) + 73.56 + 73.80 + 100.3% +
TruthfulQA (0-shot) + 54.57 + 54.57 + 100.0% +
Average + 74.10 + 73.90 + 99.7% +
\ No newline at end of file diff --git a/added_tokens.json b/added_tokens.json new file mode 100644 index 0000000..c9d3d3a --- /dev/null +++ b/added_tokens.json @@ -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 +} diff --git a/config.json b/config.json new file mode 100644 index 0000000..d7b1a42 --- /dev/null +++ b/config.json @@ -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" + } +} diff --git a/configuration.json b/configuration.json new file mode 100644 index 0000000..bbeeda1 --- /dev/null +++ b/configuration.json @@ -0,0 +1 @@ +{"framework": "pytorch", "task": "text-generation", "allow_remote": true} \ No newline at end of file diff --git a/configuration_phi3.py b/configuration_phi3.py new file mode 100644 index 0000000..d5276d9 --- /dev/null +++ b/configuration_phi3.py @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18b06d379f5199bfb8b7da26da14c580f3852e792895d2bf6158b2ef33c92d52 +size 10411 diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..a51fa89 --- /dev/null +++ b/generation_config.json @@ -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" +} diff --git a/model-00001-of-00003.safetensors b/model-00001-of-00003.safetensors new file mode 100644 index 0000000..a54414d --- /dev/null +++ b/model-00001-of-00003.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e92fd69d892de671d369e3d152c4f95473a2ce70b210bbf4f8085df52581ac7 +size 4825810264 diff --git a/model-00002-of-00003.safetensors b/model-00002-of-00003.safetensors new file mode 100644 index 0000000..7a8ca76 --- /dev/null +++ b/model-00002-of-00003.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad44d52535ed9465e6814928178cc34b2e68ddd99244c3f7a8cfb89a834b95e8 +size 4956401472 diff --git a/model-00003-of-00003.safetensors b/model-00003-of-00003.safetensors new file mode 100644 index 0000000..1793eab --- /dev/null +++ b/model-00003-of-00003.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:61f91273431a3e5f871441c546e8fcdd4ffa79285a962561dfbfb6b9c89658cc +size 4511123824 diff --git a/model.safetensors.index.json b/model.safetensors.index.json new file mode 100644 index 0000000..fd6c6f3 --- /dev/null +++ b/model.safetensors.index.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2ff8c594af9ea86b784513274930dddb3e37ca81cb09aa9206039098c7b0095e +size 34524 diff --git a/modeling_phi3.py b/modeling_phi3.py new file mode 100644 index 0000000..d8c4cd3 --- /dev/null +++ b/modeling_phi3.py @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4887efb948d0ab263c44794e19fdb91074a677614d6d5271ae7650c4f4cb8404 +size 73778 diff --git a/recipe.yaml b/recipe.yaml new file mode 100644 index 0000000..2569227 --- /dev/null +++ b/recipe.yaml @@ -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 diff --git a/results_2024-07-10T15-10-40.715163.json b/results_2024-07-10T15-10-40.715163.json new file mode 100644 index 0000000..dbda66a --- /dev/null +++ b/results_2024-07-10T15-10-40.715163.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc45f95bfcf0498331d659d20ba38f1cdc103da41859bde37bb036c82fb59f87 +size 119474 diff --git a/sample_finetune.py b/sample_finetune.py new file mode 100644 index 0000000..70558cb --- /dev/null +++ b/sample_finetune.py @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f811ce5cad430ea154fe7039f19f32d8d47d9d5fc826694b5020b7cf3815d21 +size 6192 diff --git a/special_tokens_map.json b/special_tokens_map.json new file mode 100644 index 0000000..50b4d34 --- /dev/null +++ b/special_tokens_map.json @@ -0,0 +1,30 @@ +{ + "bos_token": { + "content": "", + "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": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + } +} diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..8872e03 --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1996d98fd01946ea6e769f2a5c2bcfb429ba8223d74e7a64d23d774a4c69a6bc +size 1844535 diff --git a/tokenizer.model b/tokenizer.model new file mode 100644 index 0000000..6c00c74 --- /dev/null +++ b/tokenizer.model @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347 +size 499723 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..a7d6e3e --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9331c8a2d4bb08383814c78103f6ac5fbbe058a81b1c5e6c5c6d875b4b26d25d +size 3185