fhai50032 commited on
Commit
6ea7dad
·
verified ·
1 Parent(s): f32cd80

MedGemma 27B text-it FP8 dynamic (compressed-tensors)

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: health-ai-developer-foundations
4
+ base_model: google/medgemma-27b-text-it
5
+ tags: [fp8, compressed-tensors, sglang, vllm, medical]
6
+ ---
7
+
8
+ # medgemma-auto-fp8
9
+
10
+ `google/medgemma-27b-text-it` quantized to **FP8 (W8A8 dynamic)** with llm-compressor, in
11
+ **compressed-tensors** format.
12
+
13
+ ## Why this exists
14
+
15
+ Serving the BF16 checkpoint with `--quantization fp8` on a 48 GB card **OOMs**: SGLang/vLLM
16
+ allocate `params_dtype` (BF16, ~51 GiB for 27B) in `create_weights` and only compress *after*
17
+ loading. A pre-quantized checkpoint makes `create_weights` allocate FP8 directly (~26 GiB).
18
+ Measured peak while producing this artifact: 51.0 GiB VRAM.
19
+
20
+ ## Recipe
21
+
22
+ ```python
23
+ QuantizationModifier(targets="Linear", scheme="FP8_DYNAMIC", ignore=['lm_head', 're:.*embed_tokens.*', 're:model\\.layers\\.0\\..*'])
24
+ ```
25
+
26
+ - weights: 8-bit float, **per-channel**, symmetric
27
+ - activations: 8-bit float, **dynamic per-token** (data-free, no calibration set)
28
+ - **left in BF16:** `lm_head` (tied to `embed_tokens` in Gemma 3), `embed_tokens`,
29
+ and **decoder layer 0** (the most quantization-sensitive block)
30
+
31
+ ## Serving with SGLang
32
+
33
+ ```bash
34
+ python -m sglang.launch_server --model-path fhai50032/medgemma-auto-fp8 --kv-cache-dtype fp8_e4m3 --attention-backend triton --context-length 65536
35
+ ```
36
+
37
+ **Do not pass `--quantization fp8`** - it is auto-detected from `quantization_config`, and
38
+ passing it explicitly can select the wrong quant method for a compressed-tensors checkpoint.
39
+
40
+ Use `--attention-backend triton`: FlashInfer silently disables Gemma 3 sliding window (vLLM #20865).
41
+ SGLang also disables hybrid SWA memory for **all** Gemma 2/3/3n architectures, so every layer
42
+ caches the full context - budget KV cache accordingly.
43
+
44
+ ## Accuracy
45
+
46
+ Not formally evaluated. No recovery figure is claimed for this artifact.
chat_template.jinja ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{ bos_token }}
2
+ {%- if messages[0]['role'] == 'system' -%}
3
+ {%- if messages[0]['content'] is string -%}
4
+ {%- set first_user_prefix = messages[0]['content'] + '
5
+
6
+ ' -%}
7
+ {%- else -%}
8
+ {%- set first_user_prefix = messages[0]['content'][0]['text'] + '
9
+
10
+ ' -%}
11
+ {%- endif -%}
12
+ {%- set loop_messages = messages[1:] -%}
13
+ {%- else -%}
14
+ {%- set first_user_prefix = "" -%}
15
+ {%- set loop_messages = messages -%}
16
+ {%- endif -%}
17
+ {%- for message in loop_messages -%}
18
+ {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
19
+ {{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
20
+ {%- endif -%}
21
+ {%- if (message['role'] == 'assistant') -%}
22
+ {%- set role = "model" -%}
23
+ {%- else -%}
24
+ {%- set role = message['role'] -%}
25
+ {%- endif -%}
26
+ {{ '<start_of_turn>' + role + '
27
+ ' + (first_user_prefix if loop.first else "") }}
28
+ {%- if message['content'] is string -%}
29
+ {{ message['content'] | trim }}
30
+ {%- elif message['content'] is iterable -%}
31
+ {%- for item in message['content'] -%}
32
+ {%- if item['type'] == 'image' -%}
33
+ {{ '<start_of_image>' }}
34
+ {%- elif item['type'] == 'text' -%}
35
+ {{ item['text'] | trim }}
36
+ {%- endif -%}
37
+ {%- endfor -%}
38
+ {%- else -%}
39
+ {{ raise_exception("Invalid content type") }}
40
+ {%- endif -%}
41
+ {{ '<end_of_turn>
42
+ ' }}
43
+ {%- endfor -%}
44
+ {%- if add_generation_prompt -%}
45
+ {{'<start_of_turn>model
46
+ '}}
47
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_sliding_window_pattern": 6,
3
+ "architectures": [
4
+ "Gemma3ForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "attn_logit_softcapping": null,
9
+ "bos_token_id": 2,
10
+ "cache_implementation": "hybrid",
11
+ "dtype": "bfloat16",
12
+ "eos_token_id": 1,
13
+ "final_logit_softcapping": null,
14
+ "head_dim": 128,
15
+ "hidden_activation": "gelu_pytorch_tanh",
16
+ "hidden_size": 5376,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 21504,
19
+ "layer_types": [
20
+ "sliding_attention",
21
+ "sliding_attention",
22
+ "sliding_attention",
23
+ "sliding_attention",
24
+ "sliding_attention",
25
+ "full_attention",
26
+ "sliding_attention",
27
+ "sliding_attention",
28
+ "sliding_attention",
29
+ "sliding_attention",
30
+ "sliding_attention",
31
+ "full_attention",
32
+ "sliding_attention",
33
+ "sliding_attention",
34
+ "sliding_attention",
35
+ "sliding_attention",
36
+ "sliding_attention",
37
+ "full_attention",
38
+ "sliding_attention",
39
+ "sliding_attention",
40
+ "sliding_attention",
41
+ "sliding_attention",
42
+ "sliding_attention",
43
+ "full_attention",
44
+ "sliding_attention",
45
+ "sliding_attention",
46
+ "sliding_attention",
47
+ "sliding_attention",
48
+ "sliding_attention",
49
+ "full_attention",
50
+ "sliding_attention",
51
+ "sliding_attention",
52
+ "sliding_attention",
53
+ "sliding_attention",
54
+ "sliding_attention",
55
+ "full_attention",
56
+ "sliding_attention",
57
+ "sliding_attention",
58
+ "sliding_attention",
59
+ "sliding_attention",
60
+ "sliding_attention",
61
+ "full_attention",
62
+ "sliding_attention",
63
+ "sliding_attention",
64
+ "sliding_attention",
65
+ "sliding_attention",
66
+ "sliding_attention",
67
+ "full_attention",
68
+ "sliding_attention",
69
+ "sliding_attention",
70
+ "sliding_attention",
71
+ "sliding_attention",
72
+ "sliding_attention",
73
+ "full_attention",
74
+ "sliding_attention",
75
+ "sliding_attention",
76
+ "sliding_attention",
77
+ "sliding_attention",
78
+ "sliding_attention",
79
+ "full_attention",
80
+ "sliding_attention",
81
+ "sliding_attention"
82
+ ],
83
+ "max_position_embeddings": 131072,
84
+ "model_type": "gemma3_text",
85
+ "num_attention_heads": 32,
86
+ "num_hidden_layers": 62,
87
+ "num_key_value_heads": 16,
88
+ "pad_token_id": 0,
89
+ "quantization_config": {
90
+ "config_groups": {
91
+ "group_0": {
92
+ "format": "float-quantized",
93
+ "input_activations": {
94
+ "actorder": null,
95
+ "block_structure": null,
96
+ "dynamic": true,
97
+ "group_size": null,
98
+ "num_bits": 8,
99
+ "observer": null,
100
+ "observer_kwargs": {},
101
+ "scale_dtype": null,
102
+ "strategy": "token",
103
+ "symmetric": true,
104
+ "type": "float",
105
+ "zp_dtype": null
106
+ },
107
+ "output_activations": null,
108
+ "targets": [
109
+ "Linear"
110
+ ],
111
+ "weights": {
112
+ "actorder": null,
113
+ "block_structure": null,
114
+ "dynamic": false,
115
+ "group_size": null,
116
+ "num_bits": 8,
117
+ "observer": "memoryless_minmax",
118
+ "observer_kwargs": {},
119
+ "scale_dtype": null,
120
+ "strategy": "channel",
121
+ "symmetric": true,
122
+ "type": "float",
123
+ "zp_dtype": null
124
+ }
125
+ }
126
+ },
127
+ "format": "float-quantized",
128
+ "global_compression_ratio": null,
129
+ "ignore": [
130
+ "model.layers.0.self_attn.q_proj",
131
+ "model.layers.0.self_attn.k_proj",
132
+ "model.layers.0.self_attn.v_proj",
133
+ "model.layers.0.self_attn.o_proj",
134
+ "model.layers.0.mlp.gate_proj",
135
+ "model.layers.0.mlp.up_proj",
136
+ "model.layers.0.mlp.down_proj",
137
+ "lm_head"
138
+ ],
139
+ "kv_cache_scheme": null,
140
+ "quant_method": "compressed-tensors",
141
+ "quantization_status": "compressed",
142
+ "sparsity_config": {},
143
+ "transform_config": {},
144
+ "version": "0.17.1"
145
+ },
146
+ "query_pre_attn_scalar": 168,
147
+ "rms_norm_eps": 1e-06,
148
+ "rope_parameters": {
149
+ "full_attention": {
150
+ "factor": 8.0,
151
+ "rope_theta": 1000000,
152
+ "rope_type": "linear"
153
+ },
154
+ "sliding_attention": {
155
+ "rope_theta": 10000,
156
+ "rope_type": "default"
157
+ }
158
+ },
159
+ "sliding_window": 1024,
160
+ "sliding_window_pattern": 6,
161
+ "tie_word_embeddings": true,
162
+ "transformers_version": "5.10.1",
163
+ "use_bidirectional_attention": false,
164
+ "use_cache": true,
165
+ "vocab_size": 262144
166
+ }
generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cache_implementation": "hybrid",
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 1,
6
+ 106
7
+ ],
8
+ "top_k": 64,
9
+ "top_p": 0.95,
10
+ "transformers_version": "5.10.1"
11
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ea02e18c2311281809c45b86ff327271c9b76c1509d26a2ced5d2b3fef073fb
3
+ size 28840225144
recipe.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ default_stage:
2
+ default_modifiers:
3
+ QuantizationModifier:
4
+ targets: [Linear]
5
+ ignore: [lm_head, 're:.*embed_tokens.*', 're:model\.layers\.0\..*']
6
+ scheme: FP8_DYNAMIC
7
+ bypass_divisibility_checks: false
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:daab2354f8a74e70d70b4d1f804939b68a8c9624dd06cb7858e52dd8970e9726
3
+ size 33384567
tokenizer_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "boi_token": "<start_of_image>",
4
+ "bos_token": "<bos>",
5
+ "clean_up_tokenization_spaces": false,
6
+ "eoi_token": "<end_of_image>",
7
+ "eos_token": "<eos>",
8
+ "image_token": "<image_soft_token>",
9
+ "is_local": true,
10
+ "local_files_only": false,
11
+ "mask_token": "<mask>",
12
+ "model_max_length": 1000000000000000019884624838656,
13
+ "model_specific_special_tokens": {
14
+ "boi_token": "<start_of_image>",
15
+ "eoi_token": "<end_of_image>",
16
+ "image_token": "<image_soft_token>"
17
+ },
18
+ "pad_token": "<pad>",
19
+ "sp_model_kwargs": null,
20
+ "spaces_between_special_tokens": false,
21
+ "tokenizer_class": "GemmaTokenizer",
22
+ "unk_token": "<unk>",
23
+ "use_default_system_prompt": false
24
+ }