commit 260c7e91b92472caebc2111777dd8a62e96299eb Author: ModelHub XC Date: Thu Oct 22 23:05:13 2026 +0800 初始化项目,由ModelHub XC社区提供模型 Model: RedHatAI/granite-3.1-2b-base-FP8-dynamic Source: Original Platform 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..5af7cf0 --- /dev/null +++ b/README.md @@ -0,0 +1,300 @@ +--- +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-base +library_name: transformers +--- + +# granite-3.1-2b-base-FP8-dynamic + +## Model Overview +- **Model Architecture:** granite-3.1-2b-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-2b-base](https://huggingface.co/ibm-granite/granite-3.1-2b-base). +It achieves an average score of 57.37 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 57.65. + +### Model Optimizations + +This model was obtained by quantizing the weights and activations of [ibm-granite/granite-3.1-2b-base](https://huggingface.co/ibm-granite/granite-3.1-2b-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-2b-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-2b-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-2b-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-2b-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-2b-base-FP8-dynamic \ + --bs 16 \ + --temperature 0.2 \ + --n_samples 50 \ + --root "." \ + --dataset humaneval +``` +##### Sanitization +``` +python3 evalplus/sanitize.py \ + humaneval/neuralmagic--granite-3.1-2b-base-FP8-dynamic_vllm_temp_0.2 +``` +##### Evaluation +``` +evalplus.evaluate \ + --dataset humaneval \ + --samples humaneval/neuralmagic--granite-3.1-2b-base-FP8-dynamic_vllm_temp_0.2-sanitized +``` +
+ +### Accuracy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CategoryMetricibm-granite/granite-3.1-2b-baseneuralmagic/granite-3.1-2b-base-FP8-dynamicRecovery (%)
OpenLLM V1ARC-Challenge (Acc-Norm, 25-shot)53.7553.5099.54
GSM8K (Strict-Match, 5-shot)47.8446.1096.36
HellaSwag (Acc-Norm, 10-shot)77.9477.7699.77
MMLU (Acc, 5-shot)52.8852.6199.49
TruthfulQA (MC2, 0-shot)39.0439.84102.05
Winogrande (Acc, 5-shot)74.4374.43100.00
Average Score57.6557.3799.52
CodingHumanEval Pass@130.0030.40101.33
+ + +## 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-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-2b-base9.31.29.41.21.22.35.0
granite-3.1-2b-base-FP8-dynamic
(this model)
1.267.30.97.41.00.91.84.1
granite-3.1-2b-base-quantized.w4a161.884.80.64.90.60.61.22.8
+ + + diff --git a/config.json b/config.json new file mode 100644 index 0000000..864acc5 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7254833e2c713d9c7b22a114a9822badfac9fd094432353436e97945eeb2934d +size 1912 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..f098bbd --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67387ea9d7bf03c69777534997c5359c7f3cb0817bbc319afefa871d6cca956c +size 2837640792 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