Skip to content

Commit debcdd6

Browse files
carinapengCarina Peng
authored andcommitted
Add Gemma 4 E2B vision-language Python export
1 parent aa3bbf6 commit debcdd6

17 files changed

Lines changed: 3313 additions & 87 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
quantization_config:
2+
execution_mode: eager
3+
4+
# By default, 4-bit quantize all weights
5+
global_config:
6+
op_state_spec:
7+
weight:
8+
dtype: uint4
9+
qscheme: asymmetric
10+
granularity:
11+
type: per_block
12+
block_size: 32
13+
qformulation: minval
14+
15+
# No activation quantization
16+
op_input_spec: null
17+
op_output_spec: null
18+
19+
# Do not quantize these modules at all
20+
module_type_configs:
21+
"coreai_models.primitives.macos.sdpa.SDPA": null
22+
"coreai_models.models.macos.gemma4_text._ProportionalRoPE": null
23+
"coreai_models.models.macos.gemma4_text.MoERouter": null
24+
"coreai_models.primitives.macos.rope.RoPE": null
25+
"coreai_models.primitives.macos.rms_norm.RMSNorm": null
26+
"coreai_models.primitives.macos.switch.SwitchLinear":
27+
module_state_spec:
28+
weight:
29+
dtype: uint4
30+
qscheme: asymmetric
31+
granularity:
32+
type: per_block
33+
block_size: [1, 1, 1, 32]
34+
qformulation: minval
35+
op_input_spec: null
36+
op_output_spec: null

python/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ dependencies = [
3434
"numpy>=2.2,<3.0",
3535
"tqdm>=4.67,<5.0",
3636
"rich>=14.0,<15.0",
37-
"transformers>=4.57,<5.0",
38-
"huggingface-hub>=0.34,<1.0",
37+
"transformers==5.10.2",
38+
"huggingface-hub",
3939
"safetensors>=0.5,<1.0",
4040
"sentencepiece>=0.2,<1.0",
4141
"tokenizers>=0.22,<1.0",

python/src/coreai_models/export/_constants.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55

66
"""Constants for the export pipeline."""
77

8-
# KV cache names used by the Swift runner
8+
# KV cache names used by the Swift runner. keyCache/valueCache always name the
9+
# growable, full-attention-equivalent cache (the only cache for single-cache
10+
# models; the full-attention cache for dual-cache models like Gemma4).
911
KEY_CACHE_NAME = "keyCache"
1012
VALUE_CACHE_NAME = "valueCache"
1113

14+
# Secondary KV cache names for models with dual caches (e.g. Gemma4's bounded
15+
# sliding-window cache, which is distinct from its full-attention cache above).
16+
KEY_CACHE_SLIDING_NAME = "slidingKeyCache"
17+
VALUE_CACHE_SLIDING_NAME = "slidingValueCache"
18+
1219
# Trace-time KV cache sequence length. Used only for export/quantization tracing
1320
# to bound peak memory; at inference the actual cache size is determined
1421
# dynamically.

0 commit comments

Comments
 (0)