|
144 | 144 | ) |
145 | 145 |
|
146 | 146 |
|
| 147 | +gemma4_e2b_dict = { |
| 148 | + "architectures": ["Gemma4ForConditionalGeneration"], |
| 149 | + "audio_config": None, |
| 150 | + "audio_token_id": 258881, |
| 151 | + "boa_token_id": 256000, |
| 152 | + "boi_token_id": 255999, |
| 153 | + "dtype": "bfloat16", |
| 154 | + "eoa_token_id": 258883, |
| 155 | + "eoa_token_index": 258883, |
| 156 | + "eoi_token_id": 258882, |
| 157 | + "eos_token_id": [1, 106], |
| 158 | + "image_token_id": 258880, |
| 159 | + "initializer_range": 0.02, |
| 160 | + "model_type": "gemma4", |
| 161 | + "text_config": { |
| 162 | + "attention_bias": False, |
| 163 | + "attention_dropout": 0.0, |
| 164 | + "attention_k_eq_v": False, |
| 165 | + "bos_token_id": 2, |
| 166 | + "dtype": "bfloat16", |
| 167 | + "enable_moe_block": False, |
| 168 | + "eos_token_id": 1, |
| 169 | + "expert_intermediate_size": None, |
| 170 | + "final_logit_softcapping": 30.0, |
| 171 | + "global_head_dim": 512, |
| 172 | + "head_dim": 256, |
| 173 | + "hidden_activation": "gelu_pytorch_tanh", |
| 174 | + "hidden_size": 1536, |
| 175 | + "hidden_size_per_layer_input": 256, |
| 176 | + "initializer_range": 0.02, |
| 177 | + "intermediate_size": 6144, |
| 178 | + "layer_types": [ |
| 179 | + "sliding_attention", |
| 180 | + "sliding_attention", |
| 181 | + "sliding_attention", |
| 182 | + "sliding_attention", |
| 183 | + "full_attention", |
| 184 | + ] |
| 185 | + * 7, |
| 186 | + "max_position_embeddings": 131072, |
| 187 | + "model_type": "gemma4_text", |
| 188 | + "num_attention_heads": 8, |
| 189 | + "num_experts": None, |
| 190 | + "num_global_key_value_heads": None, |
| 191 | + "num_hidden_layers": 35, |
| 192 | + "num_key_value_heads": 1, |
| 193 | + "num_kv_shared_layers": 20, |
| 194 | + "pad_token_id": 0, |
| 195 | + "rms_norm_eps": 1e-06, |
| 196 | + "rope_parameters": { |
| 197 | + "full_attention": { |
| 198 | + "partial_rotary_factor": 0.25, |
| 199 | + "rope_theta": 1_000_000.0, |
| 200 | + "rope_type": "proportional", |
| 201 | + }, |
| 202 | + "sliding_attention": {"rope_theta": 10_000.0, "rope_type": "default"}, |
| 203 | + }, |
| 204 | + "sliding_window": 512, |
| 205 | + "tie_word_embeddings": True, |
| 206 | + "top_k_experts": None, |
| 207 | + "use_bidirectional_attention": None, |
| 208 | + "use_cache": True, |
| 209 | + "use_double_wide_mlp": True, |
| 210 | + "vocab_size": 262144, |
| 211 | + "vocab_size_per_layer_input": 262144, |
| 212 | + }, |
| 213 | + "tie_word_embeddings": True, |
| 214 | + "transformers_version": "5.5.0.dev0", |
| 215 | + "video_token_id": 258884, |
| 216 | + "vision_config": { |
| 217 | + "attention_bias": False, |
| 218 | + "attention_dropout": 0.0, |
| 219 | + "default_output_length": 280, |
| 220 | + "dtype": "bfloat16", |
| 221 | + "global_head_dim": 64, |
| 222 | + "head_dim": 64, |
| 223 | + "hidden_activation": "gelu_pytorch_tanh", |
| 224 | + "hidden_size": 768, |
| 225 | + "intermediate_size": 3072, |
| 226 | + "max_position_embeddings": 131072, |
| 227 | + "model_type": "gemma4_vision", |
| 228 | + "num_attention_heads": 12, |
| 229 | + "num_hidden_layers": 16, |
| 230 | + "num_key_value_heads": 12, |
| 231 | + "patch_size": 16, |
| 232 | + "pooling_kernel_size": 3, |
| 233 | + "position_embedding_size": 10240, |
| 234 | + "rms_norm_eps": 1e-06, |
| 235 | + "rope_parameters": {"rope_theta": 100.0, "rope_type": "default"}, |
| 236 | + "standardize": False, |
| 237 | + "use_clipped_linears": True, |
| 238 | + }, |
| 239 | + "vision_soft_tokens_per_image": 280, |
| 240 | +} |
| 241 | + |
| 242 | + |
| 243 | +gemma4_e4b_dict = gemma4_e2b_dict.copy() |
| 244 | +gemma4_e4b_dict["text_config"] = gemma4_e2b_dict["text_config"].copy() |
| 245 | +gemma4_e4b_dict["text_config"].update( |
| 246 | + { |
| 247 | + "hidden_size": 2560, |
| 248 | + "intermediate_size": 10240, |
| 249 | + "layer_types": [ |
| 250 | + "sliding_attention", |
| 251 | + "sliding_attention", |
| 252 | + "sliding_attention", |
| 253 | + "sliding_attention", |
| 254 | + "sliding_attention", |
| 255 | + "full_attention", |
| 256 | + ] |
| 257 | + * 7, |
| 258 | + "num_hidden_layers": 42, |
| 259 | + "num_key_value_heads": 2, |
| 260 | + "num_kv_shared_layers": 18, |
| 261 | + "use_double_wide_mlp": False, |
| 262 | + } |
| 263 | +) |
| 264 | + |
| 265 | + |
147 | 266 | try: |
148 | 267 | # Will execute successfully if Transformers is updated with Gemma 4 support |
149 | 268 | gemma4_26b_config = transformers.Gemma4Config(**gemma4_26b_dict) |
150 | 269 | gemma4_31b_config = transformers.Gemma4Config(**gemma4_31b_dict) |
| 270 | + gemma4_e2b_config = transformers.Gemma4Config(**gemma4_e2b_dict) |
| 271 | + gemma4_e4b_config = transformers.Gemma4Config(**gemma4_e4b_dict) |
151 | 272 | except AttributeError: |
152 | 273 | # Graceful fallback to raw dict-based PTConfig if Gemma 4 natively is missing |
153 | 274 | gemma4_26b_config = PTConfig(**gemma4_26b_dict) # pytype: disable=wrong-arg-types |
154 | 275 | gemma4_31b_config = PTConfig(**gemma4_31b_dict) # pytype: disable=wrong-arg-types |
| 276 | + gemma4_e2b_config = PTConfig(**gemma4_e2b_dict) # pytype: disable=wrong-arg-types |
| 277 | + gemma4_e4b_config = PTConfig(**gemma4_e4b_dict) # pytype: disable=wrong-arg-types |
155 | 278 |
|
156 | 279 |
|
157 | 280 | gemma3_4b_config = transformers.Gemma3Config( |
@@ -1185,6 +1308,8 @@ def __init__(self, **kwargs): |
1185 | 1308 | "gemma3-27b": gemma3_27b_config, |
1186 | 1309 | "gemma4-26b": gemma4_26b_config, |
1187 | 1310 | "gemma4-31b": gemma4_31b_config, |
| 1311 | + "gemma4-e2b": gemma4_e2b_config, |
| 1312 | + "gemma4-e4b": gemma4_e4b_config, |
1188 | 1313 | "qwen2.5-1.5b": qwen25_1_5b_config, |
1189 | 1314 | "qwen2.5-7b": qwen25_7b_config, |
1190 | 1315 | "qwen2.5-14b": qwen25_14b_config, |
|
0 commit comments