From f7f7ff89976e60922e5716dece2a2e902053d2be Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Thu, 22 Oct 2026 22:55: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/granite-3.1-2b-instruct-FP8-dynamic Source: Original Platform --- .gitattributes | 35 ++++ README.md | 354 ++++++++++++++++++++++++++++++++++++++++ added_tokens.json | 5 + config.json | 3 + configuration.json | 1 + generation_config.json | 7 + merges.txt | 3 + model.safetensors | 3 + recipe.yaml | 10 ++ special_tokens_map.json | 35 ++++ tokenizer.json | 3 + tokenizer_config.json | 3 + vocab.json | 3 + 13 files changed, 465 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 generation_config.json create mode 100644 merges.txt create mode 100644 model.safetensors create mode 100644 recipe.yaml create mode 100644 special_tokens_map.json create mode 100644 tokenizer.json create mode 100644 tokenizer_config.json create mode 100644 vocab.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..52592c8 --- /dev/null +++ b/README.md @@ -0,0 +1,354 @@ +--- +tags: +- fp8 +- vllm +license: apache-2.0 +license_link: https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md +language: + - en +base_model: ibm-granite/granite-3.1-2b-instruct +library_name: transformers +--- + +# granite-3.1-2b-instruct-FP8-dynamic + +## Model Overview +- **Model Architecture:** granite-3.1-2b-instruct + - **Input:** Text + - **Output:** Text +- **Model Optimizations:** + - **Weight quantization:** FP8 + - **Activation quantization:** FP8 +- **Release Date:** 1/8/2025 +- **Version:** 1.0 +- **Model Developers:** Neural Magic + +Quantized version of [ibm-granite/granite-3.1-2b-instruct](https://huggingface.co/ibm-granite/granite-3.1-2b-instruct). +It achieves an average score of 61.84 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 61.98. + +### Model Optimizations + +This model was obtained by quantizing the weights and activations of [ibm-granite/granite-3.1-2b-instruct](https://huggingface.co/ibm-granite/granite-3.1-2b-instruct) to FP8 data type, ready for inference with vLLM >= 0.5.2. +This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%. Only the weights and activations of the linear operators within transformers blocks are quantized. + +## 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 transformers import AutoTokenizer +from vllm import LLM, SamplingParams + +max_model_len, tp_size = 4096, 1 +model_name = "neuralmagic/granite-3.1-2b-instruct-FP8-dynamic" +tokenizer = AutoTokenizer.from_pretrained(model_name) +llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True) +sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id]) + +messages_list = [ + [{"role": "user", "content": "Who are you? Please respond in pirate speak!"}], +] + +prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list] + +outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params) + +generated_text = [output.outputs[0].text for output in outputs] +print(generated_text) +``` + +vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details. + +## Creation + +This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below. + +
+ Model Creation Code + +```bash +python quantize.py --model_id ibm-granite/granite-3.1-2b-instruct --save_path "output_dir/" +``` + +```python +import argparse +from transformers import AutoModelForCausalLM, AutoTokenizer +from llmcompressor.modifiers.quantization import QuantizationModifier +from llmcompressor.transformers import oneshot +import os + +def main(): + parser = argparse.ArgumentParser(description='Quantize a transformer model to FP8') + parser.add_argument('--model_id', type=str, required=True, + help='The model ID from HuggingFace (e.g., "meta-llama/Meta-Llama-3-2b-Instruct")') + parser.add_argument('--save_path', type=str, default='.', + help='Custom path to save the quantized model. If not provided, will use model_name-FP8-dynamic') + args = parser.parse_args() + + # Load model + model = AutoModelForCausalLM.from_pretrained( + args.model_id, device_map="auto", torch_dtype="auto", trust_remote_code=True, + ) + tokenizer = AutoTokenizer.from_pretrained(args.model_id) + + # Configure the quantization algorithm and scheme + recipe = QuantizationModifier( + targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"] + ) + + # Apply quantization + oneshot(model=model, recipe=recipe) + + save_path = os.path.join(args.save_path, args.model_id.split("/")[1] + "-FP8-dynamic") + os.makedirs(save_path, exist_ok=True) + + # Save to disk in compressed-tensors format + model.save_pretrained(save_path) + tokenizer.save_pretrained(save_path) + print(f"Model and tokenizer saved to: {save_path}") + +if __name__ == "__main__": + main() +``` +
+ +## Evaluation + +The model was evaluated on OpenLLM Leaderboard [V1](https://huggingface.co/spaces/open-llm-leaderboard-old/open_llm_leaderboard), OpenLLM Leaderboard [V2](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard#/) and on [HumanEval](https://github.com/neuralmagic/evalplus), using the following commands: + +
+Evaluation Commands + +OpenLLM Leaderboard V1: +``` +lm_eval \ + --model vllm \ + --model_args pretrained="neuralmagic/granite-3.1-2b-instruct-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \ + --tasks openllm \ + --write_out \ + --batch_size auto \ + --output_path output_dir \ + --show_config +``` +OpenLLM Leaderboard V2: +``` +lm_eval \ + --model vllm \ + --model_args pretrained="neuralmagic/granite-3.1-2b-instruct-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \ + --tasks leaderboard \ + --write_out \ + --batch_size auto \ + --output_path output_dir \ + --show_config +``` + +#### HumanEval +##### Generation +``` +python3 codegen/generate.py \ + --model neuralmagic/granite-3.1-2b-instruct-FP8-dynamic \ + --bs 16 \ + --temperature 0.2 \ + --n_samples 50 \ + --root "." \ + --dataset humaneval +``` +##### Sanitization +``` +python3 evalplus/sanitize.py \ + humaneval/neuralmagic--granite-3.1-2b-instruct-FP8-dynamic_vllm_temp_0.2 +``` +##### Evaluation +``` +evalplus.evaluate \ + --dataset humaneval \ + --samples humaneval/neuralmagic--granite-3.1-2b-instruct-FP8-dynamic_vllm_temp_0.2-sanitized +``` +
+ +### Accuracy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CategoryMetricibm-granite/granite-3.1-2b-instructneuralmagic/granite-3.1-2b-instruct-FP8-dynamicRecovery (%)
OpenLLM V1ARC-Challenge (Acc-Norm, 25-shot)55.6355.0398.92
GSM8K (Strict-Match, 5-shot)60.9661.49100.87
HellaSwag (Acc-Norm, 10-shot)75.2175.26100.07
MMLU (Acc, 5-shot)54.3854.2499.74
TruthfulQA (MC2, 0-shot)55.9355.4299.09
Winogrande (Acc, 5-shot)69.6769.6199.91
Average Score61.9861.8499.78
OpenLLM V2IFEval (Inst Level Strict Acc, 0-shot)67.9966.7998.24
BBH (Acc-Norm, 3-shot)44.1144.24100.29
Math-Hard (Exact-Match, 4-shot)8.667.8991.12
GPQA (Acc-Norm, 0-shot)28.3026.9095.06
MUSR (Acc-Norm, 0-shot)35.1235.12100.00
MMLU-Pro (Acc, 5-shot)26.8728.33105.42
Average Score35.1734.8899.16
CodingHumanEval Pass@153.4054.90102.81
+ + + +## Inference Performance + + +This model achieves up to 1.2x speedup in single-stream deployment on L40 GPUs. +The following performance benchmarks were conducted with [vLLM](https://docs.vllm.ai/en/latest/) version 0.6.6.post1, and [GuideLLM](https://github.com/neuralmagic/guidellm). + +
+Benchmarking Command + +``` +guidellm --model neuralmagic/granite-3.1-2b-instruct-FP8-dynamic --target "http://localhost:8000/v1" --data-type emulated --data "prompt_tokens=,generated_tokens=" --max seconds 360 --backend aiohttp_server +``` + +
+ +### Single-stream performance (measured with vLLM version 0.6.6.post1) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Latency (s)
GPU classModelSpeedupCode Completion
prefill: 256 tokens
decode: 1024 tokens
Docstring Generation
prefill: 768 tokens
decode: 128 tokens
Code Fixing
prefill: 1024 tokens
decode: 1024 tokens
RAG
prefill: 1024 tokens
decode: 128 tokens
Instruction Following
prefill: 256 tokens
decode: 128 tokens
Multi-turn Chat
prefill: 512 tokens
decode: 256 tokens
Large Summarization
prefill: 4096 tokens
decode: 512 tokens
L40granite-3.1-2b-instruct9.31.29.41.21.22.35.0
granite-3.1-2b-instruct-FP8-dynamic
(this model)
1.267.30.97.41.00.91.84.1
granite-3.1-2b-instruct-quantized.w4a161.884.80.64.90.60.61.22.8
\ No newline at end of file diff --git a/added_tokens.json b/added_tokens.json new file mode 100644 index 0000000..183eb81 --- /dev/null +++ b/added_tokens.json @@ -0,0 +1,5 @@ +{ + "<|end_of_role|>": 49153, + "<|start_of_role|>": 49152, + "<|tool_call|>": 49154 +} diff --git a/config.json b/config.json new file mode 100644 index 0000000..8222cd8 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a618f2ed28da3f0e9190ac3d59c6d245acfc567150999ebbfa73a53c20d056e5 +size 1915 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..614b75d --- /dev/null +++ b/generation_config.json @@ -0,0 +1,7 @@ +{ + "_from_model_config": true, + "bos_token_id": 0, + "eos_token_id": 0, + "pad_token_id": 0, + "transformers_version": "4.47.1" +} diff --git a/merges.txt b/merges.txt new file mode 100644 index 0000000..f9f6899 --- /dev/null +++ b/merges.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:303127a244b0078878156c17229f36d11b7a3a3f8e47b7cfdbb304ff46be5030 +size 441810 diff --git a/model.safetensors b/model.safetensors new file mode 100644 index 0000000..1dfe60a --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dff87c32c34fd8d4f7791b9f5e480d353c2d0e8f37e9a9258615225c67b38960 +size 2837665368 diff --git a/recipe.yaml b/recipe.yaml new file mode 100644 index 0000000..044a5bf --- /dev/null +++ b/recipe.yaml @@ -0,0 +1,10 @@ +quant_stage: + quant_modifiers: + QuantizationModifier: + ignore: [lm_head] + config_groups: + group_0: + targets: [Linear] + weights: {num_bits: 8, type: float, symmetric: true, strategy: channel, observer: mse} + input_activations: {num_bits: 8, type: float, symmetric: true, strategy: token, + dynamic: true, observer: memoryless} diff --git a/special_tokens_map.json b/special_tokens_map.json new file mode 100644 index 0000000..386500a --- /dev/null +++ b/special_tokens_map.json @@ -0,0 +1,35 @@ +{ + "additional_special_tokens": [ + "<|start_of_role|>", + "<|end_of_role|>", + "<|tool_call|>" + ], + "bos_token": { + "content": "<|end_of_text|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "eos_token": { + "content": "<|end_of_text|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "pad_token": { + "content": "<|end_of_text|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "unk_token": { + "content": "<|end_of_text|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + } +} diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..c339025 --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:361ffc73a874f5b46651bed2e0d5d6ff5c6b3448ddf28dc97c29a0c2c569ec33 +size 3475905 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..0fe3c95 --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab17e0d532ecf47e9d8451939dd81f25dd98c5fba4b6742584549bbf9c1f06b9 +size 8072 diff --git a/vocab.json b/vocab.json new file mode 100644 index 0000000..8236182 --- /dev/null +++ b/vocab.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:80ab859339a2525fdfbda14bc39df02dffb824aefdaf86426217bbb146d17e01 +size 776995