This article was originally published on runaihome.com
Missing Gemma4 Metadata in Ollama Model Creation
When running ollama create --experimental on a Gemma4ForCausalLM safetensors F16 model, the conversion process writes 0 or blank values for all gemma4.* metadata fields in the resulting model. This occurs because the experimental import path fails to parse the hidden_size, num_attention_heads, num_hidden_layers, and vocab_size parameters from the safetensors config.json. Without these values, the model initializes with invalid tensor dimensions, causing immediate EOS token generation and zero useful output. Quantized imports (int4/int8) bypass this issue because the quantization tooling includes hardcoded Gemma4 defaults.
Fix 1: Explicit Modelfile with Manual Metadata
Create a Modelfile that explicitly sets all required Gemma4 parameters:
bash
cat > Modelfile << 'EOF'
FROM ./path/to/gemma4-safetensors
PARAMETER gemma4.hidden_size 3072
PARAMETER gemma4.num_attention_heads 16
PARAMETER gemma4.num_hidden_layers 28
PARAMETER gemma4.vocab_size 256128
PARAMETER gemma4.head_dim 256
PARAMETER gemma4.query_key_layer_norm True
PARAMETER gemma4.final_rms_norm True
PARAMETER gemma4.logits_soft_cap 50.
Top comments (0)