(sd)
| 240 | return sd |
| 241 | |
| 242 | def gemma3_norm_corrections(sd): |
| 243 | # Reverse change from Gemma3Model modify_tensors in llama.cpp convert script |
| 244 | norm_patterns = [ |
| 245 | "input_layernorm.weight", |
| 246 | "post_attention_layernorm.weight", |
| 247 | "pre_feedforward_layernorm.weight", |
| 248 | "post_feedforward_layernorm.weight", |
| 249 | "self_attn.q_norm.weight", |
| 250 | "self_attn.k_norm.weight", |
| 251 | "model.norm.weight" |
| 252 | ] |
| 253 | corrected = 0 |
| 254 | for key in list(sd.keys()): |
| 255 | if any(p in key for p in norm_patterns): |
| 256 | if is_quantized(sd[key]): |
| 257 | sd[key] = dequantize_tensor(sd[key], dtype=torch.float32) - 1.0 |
| 258 | else: |
| 259 | sd[key] = sd[key].float() - 1.0 |
| 260 | corrected += 1 |
| 261 | #logging.info(f"Gemma3: Applied -1 norm correction to {corrected} tensors") |
| 262 | return sd |
| 263 | |
| 264 | def strip_quant_suffix(name): |
| 265 | pattern = r"[-_]?(?:ud-)?i?q[0-9]_[a-z0-9_\-]{1,8}$" |
no test coverage detected