puretensor commited on
Commit
84530db
·
verified ·
1 Parent(s): 41d7086

NVFP4A16 (GPTQ, weights only) quantization of openbmb/MiniCPM5-2B

Browse files
README.md ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: openbmb/MiniCPM5-2B
4
+ base_model_relation: quantized
5
+ library_name: transformers
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - nvfp4
9
+ - nvfp4a16
10
+ - 4-bit
11
+ - compressed-tensors
12
+ - llm-compressor
13
+ - gptq
14
+ - quantized
15
+ - vllm
16
+ ---
17
+
18
+ # MiniCPM5-2B NVFP4A16 (GPTQ, weights only)
19
+
20
+ NVFP4 quantization of [openbmb/MiniCPM5-2B](https://huggingface.co/openbmb/MiniCPM5-2B), made by PureTensor from the official BF16 weights. Weights are 4-bit; activations stay 16-bit (W4A16). The file is 2.18 GB against 5.03 GB for BF16.
21
+
22
+ This is a test release. It is not affiliated with or endorsed by OpenBMB.
23
+
24
+ **Read this first:** this checkpoint is measurably below BF16: 2.7 points on MMLU and 4.0 on GSM8K, both statistically significant. In exchange it served about 40% faster than BF16 for a single stream on vLLM in our test. Numbers below.
25
+
26
+ ## What was done
27
+
28
+ | | |
29
+ |---|---|
30
+ | Source | `openbmb/MiniCPM5-2B`, BF16 |
31
+ | Format | compressed-tensors `nvfp4-pack-quantized`, scheme `NVFP4A16`: 4-bit E2M1 values, one FP8 E4M3 scale per group of 16, one FP32 scale per tensor |
32
+ | Quantized | the weights of every `Linear` layer in the 42 transformer blocks |
33
+ | Kept in BF16 | token embeddings, output head, all norms, all activations |
34
+ | Method | GPTQ (`block_size` 128, `dampening_frac` 0.01, `actorder` static) |
35
+ | Calibration | the first 512 samples of `mlabonne/open-perfectblend`, up to 2,048 tokens each |
36
+ | Tools | llm-compressor 0.15.0, compressed-tensors 0.20.1, transformers 5.21.0, torch 2.14.1 |
37
+
38
+ ```python
39
+ from llmcompressor import oneshot
40
+ from llmcompressor.modifiers.quantization import GPTQModifier
41
+
42
+ recipe = GPTQModifier(targets="Linear", scheme="NVFP4A16", ignore=["lm_head"])
43
+ oneshot(model=model, processor=tokenizer, recipe=recipe, dataset="perfectblend",
44
+ splits="train[:512]", num_calibration_samples=512, max_seq_length=2048)
45
+ model.save_pretrained(out_dir, save_compressed=True)
46
+ ```
47
+
48
+ ## Measured quality
49
+
50
+ Measured by us in one harness with the BF16 model as reference. The saved checkpoint reloaded from disk to logits identical to the in-memory quantized model.
51
+
52
+ | | BF16 | This checkpoint | Change | Paired test |
53
+ |---|---:|---:|---:|---|
54
+ | MMLU, accuracy (14,042 questions) | 57.29 | 54.60 | -2.69 | 1,176 lost, 799 gained, p = 2e-17 |
55
+ | GSM8K, exact match (1,319 problems) | 72.48 | 68.46 | -4.02 | 130 lost, 77 gained, p = 3e-4 |
56
+ | WikiText-2 perplexity (131,072 tokens) | 15.64 | 16.27 | +0.63 | |
57
+
58
+ | Text | Tokens | Mean KL divergence | 99th percentile KL | Same top token as BF16 |
59
+ |---|---:|---:|---:|---:|
60
+ | WikiText-2 test | 131,072 | 0.064 | 0.52 | 87.5% |
61
+ | Chat (`HuggingFaceH4/ultrachat_200k`, `test_sft`, 256 conversations) | 224,534 | 0.068 | 0.97 | 90.2% |
62
+
63
+ - MMLU and GSM8K: default `mmlu` and `gsm8k` configurations of lm-evaluation-harness 0.4.13, no chat template, GSM8K flexible-extract. The paired test is an exact McNemar test on per-question correctness.
64
+ - KL divergence: full next-token distribution, teacher-forced, windows of 1,024 tokens.
65
+ - Calibration caveat: 180 of the 512 calibration samples are math word problems (MetaMathQA and Orca-Math), and 75 come from UltraChat, the dataset family our chat evaluation set is drawn from. MetaMathQA is built from the GSM8K and MATH training sets. The GSM8K and chat rows may therefore flatter this checkpoint; the MMLU and WikiText rows are unrelated to the calibration data.
66
+
67
+ ### On a real serving engine
68
+
69
+ Served with vLLM 0.34.0 on one NVIDIA Blackwell workstation GPU (compute capability 12.0). vLLM runs this checkpoint with its weight-only FP4 kernel (`MarlinNvFp4LinearKernel`).
70
+
71
+ | | BF16 | This checkpoint |
72
+ |---|---:|---:|
73
+ | GSM8K through the completions API (flexible-extract) | 72.10 | 68.23 |
74
+ | Throughput, single stream | 1.00x | 1.40x |
75
+ | Throughput, 8 concurrent | 1.00x | 1.53x |
76
+ | Throughput, 32 concurrent | 1.00x | 1.28x |
77
+
78
+ The served GSM8K score matches the offline one (68.23 against 68.46), so the offline numbers above describe what the engine does. Throughput is fixed 256-token generations, greedy, and will differ on other hardware.
79
+
80
+ ### How it compares with other 4-bit builds of this model
81
+
82
+ All scored by us in the same harness. Public builds are described by method.
83
+
84
+ | Build | Activations | MMLU | GSM8K | KL, wiki | KL, chat |
85
+ |---|---|---:|---:|---:|---:|
86
+ | BF16 reference | 16-bit | 57.29 | 72.48 | 0 | 0 |
87
+ | **This checkpoint: GPTQ, dampening 0.01** | 16-bit | 54.60 | **68.46** | **0.064** | **0.068** |
88
+ | A public GPTQ build, dampening 0.1 | 16-bit | **55.92** | 62.93 | 0.069 | 0.099 |
89
+ | A public AWQ build with searched scales | 16-bit | 50.45 | 61.71 | 0.103 | 0.149 |
90
+ | Our GPTQ build with 4-bit activations (not published) | 4-bit | 49.88 | 59.59 | 0.167 | 0.205 |
91
+ | A public AWQ build with 4-bit activations | 4-bit | 47.14 | 52.92 | 0.208 | 0.286 |
92
+
93
+ This checkpoint is the closest to BF16 on token-level agreement and on GSM8K. The public GPTQ build with heavier dampening is 1.3 points better on MMLU. With 4-bit activations this model loses 7 to 10 MMLU points, which is why we publish the weights-only form.
94
+
95
+ ## Usage
96
+
97
+ vLLM:
98
+
99
+ ```bash
100
+ vllm serve puretensor/MiniCPM5-2B-NVFP4A16
101
+ ```
102
+
103
+ Transformers (requires `pip install compressed-tensors`):
104
+
105
+ ```python
106
+ import torch
107
+ from transformers import AutoModelForCausalLM, AutoTokenizer
108
+
109
+ repo = "puretensor/MiniCPM5-2B-NVFP4A16"
110
+ tok = AutoTokenizer.from_pretrained(repo)
111
+ model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16).to("cuda")
112
+
113
+ msgs = [{"role": "user", "content": "Summarise the water cycle in two sentences."}]
114
+ ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt", return_dict=True).to("cuda")
115
+ out = model.generate(**ids, max_new_tokens=128)
116
+ print(tok.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True))
117
+ ```
118
+
119
+ ## Limitations
120
+
121
+ - Quality is below BF16, as measured above. If you need the base model's quality, use BF16.
122
+ - In Transformers the weights are expanded back to 16-bit at load, so there the saving is disk and download size only. The speed gain needs an engine with an FP4 weight kernel, such as vLLM.
123
+ - English-language benchmarks only. One calibration draw, no repeated seeds. No safety, multilingual, or long-context evaluation was run on the quantized model.
124
+
125
+ ## License
126
+
127
+ Apache-2.0, as the base model. Changes from the base release: the `Linear` weights are quantized to NVFP4 and stored packed, and `config.json` gains a `quantization_config` block.
chat_template.jinja ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- bos_token }}{%- if tools %}
2
+ {%- set tool_definitions %}
3
+ {{- "# Tools\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
4
+ {%- for tool in tools %}
5
+ {{- "\n" }}
6
+ {{- tool | tojson(ensure_ascii=False) }}
7
+ {%- endfor %}
8
+ {{- '\n</tools>\n\nTool usage guidelines:\n- You may call zero or more functions. If no function calls are needed, just answer normally and do not include any <function ... </function>.\n- When calling a function, return an XML object within <function ... </function> using:\n<function name="function-name"><param name="param-name">param-value</param></function>\n- param-value may be multi-line. If it contains <, & or newline characters, wrap it in a CDATA block: <param name="param-name"><![CDATA[...multi-line value...]]></param>' }}
9
+ {%- endset %}
10
+
11
+ {{- '<|im_start|>system\n' }}
12
+ {%- if messages[0].role == 'system' %}
13
+ {%- if '<tool_def_sep>' in messages[0].content %}
14
+ {{- messages[0].content.replace('<tool_def_sep>', tool_definitions) }}
15
+ {%- else %}
16
+ {{- messages[0].content + '\n\n' + tool_definitions }}
17
+ {%- endif %}
18
+ {%- else %}
19
+ {{- tool_definitions.lstrip() }}
20
+ {%- endif %}
21
+ {{- '<|im_end|>\n' }}
22
+ {%- else %}
23
+ {%- if messages[0].role == 'system' %}
24
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
25
+ {%- endif %}
26
+ {%- endif %}
27
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
28
+ {%- for message in messages[::-1] %}
29
+ {%- set index = (messages|length - 1) - loop.index0 %}
30
+ {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
31
+ {%- set ns.multi_step_tool = false %}
32
+ {%- set ns.last_query_index = index %}
33
+ {%- endif %}
34
+ {%- endfor %}
35
+ {%- for message in messages %}
36
+ {%- if message.content is string %}
37
+ {%- set content = message.content %}
38
+ {%- else %}
39
+ {%- set content = '' %}
40
+ {%- endif %}
41
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
42
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
43
+ {%- elif message.role == "assistant" %}
44
+ {%- set reasoning_content = '' %}
45
+ {%- if message.reasoning_content is string %}
46
+ {%- set reasoning_content = message.reasoning_content %}
47
+ {%- else %}
48
+ {%- if '</think>' in content %}
49
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
50
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
51
+ {%- endif %}
52
+ {%- endif %}
53
+
54
+ {%- if reasoning_content %}
55
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
56
+ {%- elif '<think>' not in content and '</think>' not in content %}
57
+ {{- '<|im_start|>' + message.role + '\n<think>\n\n</think>\n\n' + content.lstrip('\n') }}
58
+ {%- else %}
59
+ {{- '<|im_start|>' + message.role + '\n' + content }}
60
+ {%- endif %}
61
+
62
+ {%- if message.tool_calls %}
63
+ {%- for tool_call in message.tool_calls %}
64
+ {%- if (loop.first and content) or (not loop.first) %}
65
+ {{- '\n' }}
66
+ {%- endif %}
67
+ {%- if tool_call.function %}
68
+ {%- set tool_call = tool_call.function %}
69
+ {%- endif %}
70
+ {{- '<function name="' ~ tool_call.name ~ '">' }}
71
+ {%- if tool_call.arguments %}
72
+ {%- set args_dict = tool_call.arguments %}
73
+ {%- for param_name, param_value in args_dict.items() %}
74
+ {{- '<param name="' ~ param_name ~ '">' }}
75
+ {%- if param_value is string and ('<' in param_value or '&' in param_value or '\n' in param_value) %}
76
+ {{- '<![CDATA[' + param_value + ']]>' }}
77
+ {%- else %}
78
+ {{- param_value }}
79
+ {%- endif %}
80
+ {{- '</param>' }}
81
+ {%- endfor %}
82
+ {%- endif %}
83
+ {{- '</function>' }}
84
+ {%- endfor %}
85
+ {%- endif %}
86
+ {{- '<|im_end|>\n' }}
87
+ {%- elif message.role == "tool" %}
88
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
89
+ {{- '<|im_start|>user' }}
90
+ {%- endif %}
91
+ {{- '\n<tool_response>\n' }}
92
+ {%- if message.content is string %}
93
+ {{- content }}
94
+ {%- else %}
95
+ {{- message.content | tojson(ensure_ascii=False) }}
96
+ {%- endif %}
97
+ {{- '\n</tool_response>' }}
98
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
99
+ {{- '<|im_end|>\n' }}
100
+ {%- endif %}
101
+ {%- endif %}
102
+ {%- endfor %}
103
+ {%- if add_generation_prompt %}
104
+ {{- '<|im_start|>assistant\n' }}
105
+ {%- if enable_thinking is defined %}
106
+ {%- if enable_thinking is false %}
107
+ {{- '<think>\n\n</think>\n\n' }}
108
+ {%- elif enable_thinking is true %}
109
+ {{- '<think>\n' }}
110
+ {%- endif %}
111
+ {%- endif %}
112
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "openbmb/MiniCPM5-2B",
3
+ "architectures": [
4
+ "LlamaForCausalLM"
5
+ ],
6
+ "bos_token_id": 0,
7
+ "eos_token_id": [
8
+ 1,
9
+ 130073
10
+ ],
11
+ "head_dim": 128,
12
+ "hidden_act": "silu",
13
+ "hidden_size": 2048,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 6144,
16
+ "max_position_embeddings": 131072,
17
+ "model_type": "llama",
18
+ "num_attention_heads": 16,
19
+ "num_hidden_layers": 42,
20
+ "num_key_value_heads": 2,
21
+ "pad_token_id": 1,
22
+ "quantization_config": {
23
+ "config_groups": {
24
+ "group_0": {
25
+ "format": "nvfp4-pack-quantized",
26
+ "input_activations": null,
27
+ "output_activations": null,
28
+ "targets": [
29
+ "Linear"
30
+ ],
31
+ "weights": {
32
+ "actorder": "static",
33
+ "dynamic": false,
34
+ "group_size": 16,
35
+ "num_bits": 4,
36
+ "observer": "memoryless_minmax",
37
+ "scale_dtype": "torch.float8_e4m3fn",
38
+ "strategy": "tensor_group",
39
+ "symmetric": true,
40
+ "type": "float"
41
+ }
42
+ }
43
+ },
44
+ "format": "nvfp4-pack-quantized",
45
+ "global_compression_ratio": null,
46
+ "ignore": [
47
+ "lm_head"
48
+ ],
49
+ "kv_cache_scheme": null,
50
+ "moe_sparsity_config": null,
51
+ "quant_method": "compressed-tensors",
52
+ "quantization_status": "compressed",
53
+ "sparsity_config": {},
54
+ "transform_config": {},
55
+ "version": "0.20.1"
56
+ },
57
+ "rms_norm_eps": 1e-06,
58
+ "rope_scaling": null,
59
+ "rope_theta": 5000000,
60
+ "tie_word_embeddings": false,
61
+ "torch_dtype": "bfloat16",
62
+ "transformers_version": "5.6.2",
63
+ "use_cache": true,
64
+ "vocab_size": 130560
65
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 0,
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 1,
7
+ 130073
8
+ ],
9
+ "pad_token_id": 1,
10
+ "temperature": 1.0,
11
+ "top_p": 0.95,
12
+ "transformers_version": "5.21.0"
13
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fcf3bb3a87cce432716d5e775d9b50b5f02a04e2d8e3ba6ee65b37f2999824b0
3
+ size 2184777536
recipe.yaml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ default_stage:
2
+ default_modifiers:
3
+ GPTQModifier:
4
+ targets: [Linear]
5
+ ignore: [lm_head]
6
+ scheme: NVFP4A16
7
+ bypass_divisibility_checks: false
8
+ requires_calibration_data: true
9
+ block_size: 128
10
+ dampening_frac: 0.01
11
+ actorder: static
12
+ batched_quantization: auto
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": null,
3
+ "backend": "tokenizers",
4
+ "bos_token": "<s>",
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "</s>",
7
+ "is_local": true,
8
+ "legacy": true,
9
+ "local_files_only": false,
10
+ "model_max_length": 131072,
11
+ "pad_token": "</s>",
12
+ "sp_model_kwargs": {},
13
+ "spaces_between_special_tokens": false,
14
+ "tokenizer_class": "TokenizersBackend",
15
+ "unk_token": "<unk>",
16
+ "use_default_system_prompt": false
17
+ }