{"record":{"id":"aa752d030ccdb576","repo":"huggingface/candle","slug":"both-hidden-act-and-hidden-activation-are-set","errorCode":null,"errorMessage":"both hidden_act and hidden_activation are set","messagePattern":"both hidden_act and hidden_activation are set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-transformers/src/models/gemma.rs","lineNumber":40,"sourceCode":"    pub hidden_activation: Option<Activation>,\n    pub hidden_size: usize,\n    pub intermediate_size: usize,\n    pub num_attention_heads: usize,\n    pub num_hidden_layers: usize,\n    pub num_key_value_heads: usize,\n    pub rms_norm_eps: f64,\n    pub rope_theta: f64,\n    pub vocab_size: usize,\n\n    #[serde(default = \"default_max_position_embeddings\")]\n    pub max_position_embeddings: usize,\n}\n\nimpl Config {\n    fn hidden_act(&self) -> Result<Activation> {\n        match (self.hidden_act, self.hidden_activation) {\n            (None, Some(act)) | (Some(act), None) => Ok(act),\n            (Some(_), Some(_)) => candle::bail!(\"both hidden_act and hidden_activation are set\"),\n            (None, None) => candle::bail!(\"none of hidden_act and hidden_activation are set\"),\n        }\n    }\n}\n\n#[derive(Debug, Clone)]\nstruct RmsNorm {\n    weight: Tensor,\n    eps: f64,\n}\n\nimpl RmsNorm {\n    fn new(dim: usize, eps: f64, vb: VarBuilder) -> Result<Self> {\n        let weight = vb.get(dim, \"weight\")?;\n        Ok(Self { weight, eps })\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/gemma.rs#L22-L58","documentation":"Gemma Config can specify the activation two ways: legacy hidden_act and newer hidden_activation. Config::hidden_act() rejects configs where both are set, because it cannot tell which one the checkpoint author intended. This is an eager config-validation error raised when building the model.","triggerScenarios":"Deserializing a Gemma config.json that contains both \"hidden_act\" and \"hidden_activation\" keys — typically a config from a newer transformers version fed to code that also fills the legacy field with a default.","commonSituations":"Mixing config versions (HuggingFace transformers renamed hidden_act to hidden_activation in newer Gemma revisions); hand-edited config.json; a serde default populating hidden_act when it should be None.","solutions":["Remove one of the two keys from the config JSON (keep hidden_activation for newer checkpoints)","Ensure hidden_act is Option and defaults to None rather than being filled unconditionally","Pin to a candle version matching the checkpoint's config format"],"exampleFix":"// before (config.json)\n{\"hidden_act\": \"gelu\", \"hidden_activation\": \"gelu_pytorch_tanh\", ...}\n// after\n{\"hidden_activation\": \"gelu_pytorch_tanh\", ...}","handlingStrategy":"validation","validationCode":"let both_set = cfg_json.get(\"hidden_act\").is_some() && cfg_json.get(\"hidden_activation\").is_some();\nif both_set { return Err(\"config sets both hidden_act and hidden_activation\"); }","typeGuard":"fn activation_is_unambiguous(c: &gemma::Config) -> bool {\n    c.hidden_act.is_some() ^ c.hidden_activation.is_some()\n}","tryCatchPattern":"let model = gemma::Model::new(&vb, cfg).map_err(|e| {\n    if e.to_string().contains(\"both hidden_act\") {\n        anyhow!(\"strip one activation key from config.json (prefer hidden_activation)\")\n    } else { e.into() }\n});","preventionTips":["Match candle's Config serde layout to your transformers version","Never set both activation keys in config.json","When hand-writing Gemma configs, use hidden_activation for newer checkpoints"],"tags":["config","gemma","model-loading"],"backgroundTag":"ambiguous-model-config","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}