From 676108e834ecd36cf63476987134a3d6c388f84b Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Thu, 3 Sep 2026 12:38:13 +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/Llama-2-7b-chat-quantized.w8a8 Source: Original Platform --- .gitattributes | 35 ++++ README.md | 267 ++++++++++++++++++++++++ config.json | 70 +++++++ configuration.json | 1 + generation_config.json | 10 + model-00001-of-00002.safetensors | 3 + model-00002-of-00002.safetensors | 3 + model.safetensors.index.json | 3 + recipe.yaml | 11 + results_2024-07-04T17-06-35.145108.json | 3 + special_tokens_map.json | 24 +++ tokenizer.json | 3 + tokenizer_config.json | 3 + 13 files changed, 436 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 config.json create mode 100644 configuration.json create mode 100644 generation_config.json create mode 100644 model-00001-of-00002.safetensors create mode 100644 model-00002-of-00002.safetensors create mode 100644 model.safetensors.index.json create mode 100644 recipe.yaml create mode 100644 results_2024-07-04T17-06-35.145108.json create mode 100644 special_tokens_map.json create mode 100644 tokenizer.json 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..855a5ee --- /dev/null +++ b/README.md @@ -0,0 +1,267 @@ +--- +language: +- en +pipeline_tag: text-generation +license: llama2 +--- + +# Llama-2-7b-chat-quantized.w8a8 + +## Model Overview +- **Model Architecture:** Llama-2 + - **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 [Llama-2-7b-chat](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf), 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/2/2024 +- **Version:** 1.0 +- **License(s)**: [LLama2](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf/blob/main/LICENSE.txt) +- **Model Developers:** Neural Magic + +Quantized version of [Llama-2-7b-chat](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf). +It achieves an average score of 53.38 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 53.41. + +### Model Optimizations + +This model was obtained by quantizing the weights of [Llama-2-7b-chat](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf) 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. +The [GPTQ](https://arxiv.org/abs/2210.17323) algorithm is applied for quantization, as implemented in the [llm-compressor](https://github.com/vllm-project/llm-compressor) library. +GPTQ used a 1% damping factor and 256 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. + +```python +from vllm import LLM, SamplingParams +from transformers import AutoTokenizer + +model_id = "neuralmagic/Llama-2-7b-chat-quantized.w8a8" +number_gpus = 1 + +sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256) + +tokenizer = AutoTokenizer.from_pretrained(model_id, tensor_parallel_size=number_gpus) + +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, 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. + +### Use with transformers + +The following example contemplates how the model can be deployed in Transformers using the `generate()` function. + + +```python +from transformers import AutoTokenizer, AutoModelForCausalLM + +model_id = "neuralmagic/Llama-2-7b-chat-quantized.w8a8" + +tokenizer = AutoTokenizer.from_pretrained(model_id) +model = AutoModelForCausalLM.from_pretrained( + model_id, + torch_dtype="auto", + device_map="auto", +) + +messages = [ + {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"}, + {"role": "user", "content": "Who are you?"}, +] + +input_ids = tokenizer.apply_chat_template( + messages, + add_generation_prompt=True, + return_tensors="pt" +).to(model.device) + +terminators = [ + tokenizer.eos_token_id, + tokenizer.convert_tokens_to_ids("<|eot_id|>") +] + +outputs = model.generate( + input_ids, + max_new_tokens=256, + eos_token_id=terminators, + do_sample=True, + temperature=0.6, + top_p=0.9, +) +response = outputs[0][input_ids.shape[-1]:] +print(tokenizer.decode(response, skip_special_tokens=True)) +``` + +## 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 +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 load_dataset +from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot +from llmcompressor.modifiers.quantization import GPTQModifier + +model_id = "meta-llama/Llama-2-7b-chat-hf" + +num_samples = 256 +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 = GPTQModifier( + targets="Linear", + scheme="W8A8", + ignore=["lm_head"], + dampening_frac=0.01, +) + +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("Llama-2-7b-chat-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: +``` +lm_eval \ + --model vllm \ + --model_args pretrained="neuralmagic/Llama-2-7b-chat-quantized.w8a8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \ + --tasks openllm \ + --batch_size auto +``` + +### Accuracy + +#### Open LLM Leaderboard evaluation scores + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Benchmark + Llama-2-7b-chat + Llama-2-7b-chat-quantized.w8a8 (this model) + Recovery +
MMLU (5-shot) + 47.34 + 47.04 + 99.4% +
ARC Challenge (25-shot) + 53.24 + 54.52 + 102.4% +
GSM-8K (5-shot, strict-match) + 23.20 + 22.21 + 95.8% +
Hellaswag (10-shot) + 78.65 + 78.17 + 99.4% +
Winogrande (5-shot) + 72.45 + 72.85 + 100.5% +
TruthfulQA (0-shot) + 45.58 + 45.50 + 99.8% +
Average + 53.41 + 53.38 + 99.9% +
diff --git a/config.json b/config.json new file mode 100644 index 0000000..e79874e --- /dev/null +++ b/config.json @@ -0,0 +1,70 @@ +{ + "_name_or_path": "/nm/drive0/alexandre/cache/hub/models--meta-llama--Llama-2-7b-chat-hf/snapshots/f5db02db724555f92da89c216ac04704f23d4590", + "architectures": [ + "LlamaForCausalLM" + ], + "attention_bias": false, + "attention_dropout": 0.0, + "bos_token_id": 1, + "eos_token_id": 2, + "hidden_act": "silu", + "hidden_size": 4096, + "initializer_range": 0.02, + "intermediate_size": 11008, + "max_position_embeddings": 4096, + "mlp_bias": false, + "model_type": "llama", + "num_attention_heads": 32, + "num_hidden_layers": 32, + "num_key_value_heads": 32, + "pretraining_tp": 1, + "rms_norm_eps": 1e-05, + "rope_scaling": null, + "rope_theta": 10000.0, + "tie_word_embeddings": false, + "torch_dtype": "float16", + "transformers_version": "4.42.3", + "use_cache": true, + "vocab_size": 32000, + "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.2397987000162187, + "ignore": [ + "lm_head" + ], + "kv_cache_scheme": null, + "quant_method": "compressed-tensors", + "quantization_status": "compressed", + "sparsity_config": {} + } +} 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/generation_config.json b/generation_config.json new file mode 100644 index 0000000..2893557 --- /dev/null +++ b/generation_config.json @@ -0,0 +1,10 @@ +{ + "bos_token_id": 1, + "do_sample": true, + "eos_token_id": 2, + "max_length": 4096, + "pad_token_id": 0, + "temperature": 0.6, + "top_p": 0.9, + "transformers_version": "4.42.3" +} diff --git a/model-00001-of-00002.safetensors b/model-00001-of-00002.safetensors new file mode 100644 index 0000000..1e7d660 --- /dev/null +++ b/model-00001-of-00002.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3eb2ca126c77611182b9ce4094fe521fec5bafb6e239b2acce297547f255f11b +size 4986289512 diff --git a/model-00002-of-00002.safetensors b/model-00002-of-00002.safetensors new file mode 100644 index 0000000..c52f612 --- /dev/null +++ b/model-00002-of-00002.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27342ae9df167a65ad15686cf8f06399b94320f6ba3ee29b2614bc3337633bf3 +size 2017315320 diff --git a/model.safetensors.index.json b/model.safetensors.index.json new file mode 100644 index 0000000..9b632c8 --- /dev/null +++ b/model.safetensors.index.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:298c39e1979ef888fb66feded37e446310127967bfa84760306edc3b37cd65bc +size 43463 diff --git a/recipe.yaml b/recipe.yaml new file mode 100644 index 0000000..cc7dba1 --- /dev/null +++ b/recipe.yaml @@ -0,0 +1,11 @@ +quant_stage: + quant_modifiers: + GPTQModifier: + sequential_update: false + dampening_frac: 1 + ignore: [lm_head] + config_groups: + group_0: + targets: [Linear] + weights: {num_bits: 8, type: int, symmetric: true, strategy: channel} + input_activations: {num_bits: 8, type: int, symmetric: true, dynamic: true, strategy: token} diff --git a/results_2024-07-04T17-06-35.145108.json b/results_2024-07-04T17-06-35.145108.json new file mode 100644 index 0000000..2f36bd1 --- /dev/null +++ b/results_2024-07-04T17-06-35.145108.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca3ed4f3d6ee3bfcfdee521d0134b332cd0e69d92d994a7187dbcfc71599955b +size 121338 diff --git a/special_tokens_map.json b/special_tokens_map.json new file mode 100644 index 0000000..72ecfee --- /dev/null +++ b/special_tokens_map.json @@ -0,0 +1,24 @@ +{ + "bos_token": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "eos_token": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "pad_token": "", + "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..5d592ae --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf467c9e0f536bda271283c6ef85eb1a943e3196b621c8a912d64953b205df83 +size 1842795 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..2052769 --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a72a826a359b4cc4f84c90e86754b592ba74395b73f91163dd8c283e3ed3e19 +size 1790