{"record":{"id":"92ccefcd4a734459","repo":"huggingface/candle","slug":"none-of-hidden-act-and-hidden-activation-are-set","errorCode":null,"errorMessage":"none of hidden_act and hidden_activation are set","messagePattern":"none of hidden_act and hidden_activation are set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-transformers/src/models/gemma.rs","lineNumber":41,"sourceCode":"    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\nimpl Module for RmsNorm {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/gemma.rs#L23-L59","documentation":"Thrown when constructing Gemma activation if neither hidden_act nor hidden_activation is set in the config; at least one must be present to select the activation function.","triggerScenarios":"Loading a Gemma config.json missing both activation keys, or a struct constructed programmatically (e.g. Config { hidden_act: None, hidden_activation: None, .. }) without setting either.","commonSituations":"Hand-written or stripped config JSON; copy-pasted Config literal with activation fields left as None; a checkpoint variant whose config omits the key entirely.","solutions":["Add \"hidden_activation\": \"gelu_pytorch_tanh\" (or the checkpoint's actual activation) to config.json","Set hidden_act in the Config struct when constructing it in code","Check the original model card / config.json from the HuggingFace repo for the correct value"],"exampleFix":"// before\nlet cfg = Config { hidden_act: None, hidden_activation: None, .. };\n// after\nlet cfg = Config { hidden_act: None, hidden_activation: Some(Activation::GeluPytorchTanh), .. };","handlingStrategy":"validation","validationCode":"if cfg_json.get(\"hidden_act\").is_none() && cfg_json.get(\"hidden_activation\").is_none() {\n    return Err(\"config must set hidden_act or hidden_activation\");\n}","typeGuard":"fn has_activation(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(\"none of hidden_act\") {\n        anyhow!(\"add \\\"hidden_activation\\\" (e.g. gelu_pytorch_tanh) to config\")\n    } else { e.into() }\n});","preventionTips":["Copy config.json verbatim from the HuggingFace repo — don't strip keys","When constructing Config in code, always set one activation field","Validate config JSON against the original model card before loading"],"tags":["config","gemma","missing-field"],"backgroundTag":"missing-config-field","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}