From 680f0ea2f2488c93baa3a80104b9aea0ef8c5e24 Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Thu, 22 Oct 2026 01:26: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-8b-base-FP8-dynamic Source: Original Platform --- .gitattributes | 35 +++ README.md | 357 +++++++++++++++++++++++++++++++ added_tokens.json | 5 + config.json | 3 + configuration.json | 1 + generation_config.json | 7 + merges.txt | 3 + model-00001-of-00002.safetensors | 3 + model-00002-of-00002.safetensors | 3 + model.safetensors.index.json | 3 + recipe.yaml | 10 + special_tokens_map.json | 51 +++++ tokenizer.json | 3 + tokenizer_config.json | 3 + vocab.json | 3 + 15 files changed, 490 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-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 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..3569c7c --- /dev/null +++ b/README.md @@ -0,0 +1,357 @@ +--- +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-8b-base +library_name: transformers +--- + +# granite-3.1-8b-base-FP8-dynamic + +## Model Overview +- **Model Architecture:** granite-3.1-8b-base + - **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-8b-base](https://huggingface.co/ibm-granite/granite-3.1-8b-base). +It achieves an average score of 66.94 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 67.44. + +### Model Optimizations + +This model was obtained by quantizing the weights and activations of [ibm-granite/granite-3.1-8b-base](https://huggingface.co/ibm-granite/granite-3.1-8b-base) 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-8b-base-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-8b-base --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-8B-base")') + 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-8b-base-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 +``` + +#### HumanEval +##### Generation +``` +python3 codegen/generate.py \ + --model neuralmagic/granite-3.1-8b-base-FP8-dynamic \ + --bs 16 \ + --temperature 0.2 \ + --n_samples 50 \ + --root "." \ + --dataset humaneval +``` +##### Sanitization +``` +python3 evalplus/sanitize.py \ + humaneval/neuralmagic--granite-3.1-8b-base-FP8-dynamic_vllm_temp_0.2 +``` +##### Evaluation +``` +evalplus.evaluate \ + --dataset humaneval \ + --samples humaneval/neuralmagic--granite-3.1-8b-base-FP8-dynamic_vllm_temp_0.2-sanitized +``` +
+ +### Accuracy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CategoryMetricibm-granite/granite-3.1-8b-baseneuralmagic/granite-3.1-8b-base-FP8-dynamicRecovery (%)
OpenLLM V1ARC-Challenge (Acc-Norm, 25-shot)64.6864.1699.20
GSM8K (Strict-Match, 5-shot)60.8858.4595.99
HellaSwag (Acc-Norm, 10-shot)83.5283.4699.93
MMLU (Acc, 5-shot)63.3363.35100.03
TruthfulQA (MC2, 0-shot)51.3351.56100.45
Winogrande (Acc, 5-shot)80.9080.6699.70
Average Score67.4466.9499.26
CodingHumanEval Pass@144.1044.80101.59
+ + + +## Inference Performance + + +This model achieves up to 1.5x speedup in single-stream deployment and up to 1.1x speedup in multi-stream asynchronous 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-8b-base-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-8b-base25.13.225.33.23.26.313.4
granite-3.1-8b-base-FP8-dynamic
(this model)
1.4716.82.217.12.22.14.29.3
granite-3.1-8b-base-quantized.w4a162.728.91.29.21.21.12.35.3
+ + +### Multi-stream asynchronous performance (measured with vLLM version 0.6.6.post1) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Maximum Throughput (Queries per Second)
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-8b-base1.47.81.16.215.56.00.7
granite-3.1-8b-base-FP8-dynamic
(this model)
1.122.17.41.35.915.36.90.8
granite-3.1-2b-base-quantized.w4a161.292.48.91.47.117.87.81.0
+ + 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..7979290 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57cdbfae746b4c308a6ed08415710d58ae8aebd2c61e6d853707da1ad8a91eba +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-00001-of-00002.safetensors b/model-00001-of-00002.safetensors new file mode 100644 index 0000000..dee1d42 --- /dev/null +++ b/model-00001-of-00002.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:833b6e4890c8b7893dba55d6cd80373e7ba13c8da11fea19e1c53a9f4a428df1 +size 4987187648 diff --git a/model-00002-of-00002.safetensors b/model-00002-of-00002.safetensors new file mode 100644 index 0000000..92a3fc3 --- /dev/null +++ b/model-00002-of-00002.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e7a94a04a176136f8c90efbc8e9114903dc8850741a421cde5e1b29a3ea15f4 +size 3791230544 diff --git a/model.safetensors.index.json b/model.safetensors.index.json new file mode 100644 index 0000000..688cec6 --- /dev/null +++ b/model.safetensors.index.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d9d01380666457b3c0787f94d508d0ee304ccc83ffbca8c9c653c62a8d1e970e +size 54303 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..7dec8d5 --- /dev/null +++ b/special_tokens_map.json @@ -0,0 +1,51 @@ +{ + "additional_special_tokens": [ + "<|endoftext|>", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" + ], + "bos_token": { + "content": "<|endoftext|>", + "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": "<|endoftext|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + } +} diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..1712579 --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:34e9e8a6dcb204fadad8f55ea8915a08c6dfaf770b4b16bf04ec9b620a9387f4 +size 3475389 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..2047874 --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a65886cabc33b82795df74cbcf99e88f4be3e93a72808eb7c006a8ae3d66afb3 +size 4156 diff --git a/vocab.json b/vocab.json new file mode 100644 index 0000000..fdc0b09 --- /dev/null +++ b/vocab.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20175afb9f164fad4829aca2279f8df7eeff1e2e3f671378aaa287a740aff09f +size 776993