{"record":{"id":"dccde7beab62d2f2","repo":"huggingface/candle","slug":"compile-with-features-flash-attn-dccde7","errorCode":null,"errorMessage":"compile with '--features flash-attn'","messagePattern":"compile with '--features flash-attn'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-transformers/src/models/granitemoehybrid.rs","lineNumber":256,"sourceCode":"    span_rot: tracing::Span,\n    max_position_embeddings: usize,\n    attention_multiplier: f32,\n}\n\n#[cfg(feature = \"flash-attn\")]\nfn flash_attn(\n    q: &Tensor,\n    k: &Tensor,\n    v: &Tensor,\n    softmax_scale: f32,\n    causal: bool,\n) -> Result<Tensor> {\n    candle_flash_attn::flash_attn(q, k, v, softmax_scale, causal)\n}\n\n#[cfg(not(feature = \"flash-attn\"))]\nfn flash_attn(_: &Tensor, _: &Tensor, _: &Tensor, _: f32, _: bool) -> Result<Tensor> {\n    unimplemented!(\"compile with '--features flash-attn'\")\n}\n\nimpl CausalSelfAttention {\n    fn apply_rotary_emb(\n        &self,\n        x: &Tensor,\n        index_pos: usize,\n        cache: &GraniteMoeHybridCache,\n    ) -> Result<Tensor> {\n        let _enter = self.span_rot.enter();\n        let (_b_sz, _, seq_len, _hidden_size) = x.dims4()?;\n        let cos = cache.cos.narrow(0, index_pos, seq_len)?;\n        let sin = cache.sin.narrow(0, index_pos, seq_len)?;\n        candle_nn::rotary_emb::rope(x, &cos, &sin)\n    }\n\n    fn forward(\n        &self,","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/granitemoehybrid.rs#L238-L274","documentation":"granitemoehybrid.rs follows the shared candle pattern: a `flash_attn` helper replaced by an `unimplemented!` stub when the `flash-attn` feature is off. Requesting flash attention in the model config at runtime therefore panics instead of computing attention.","triggerScenarios":"Running the Granite MoE Hybrid model with `use_flash_attn: true` in Config while the crate is built without the `flash-attn` cargo feature.","commonSituations":"Config from a checkpoint enables flash attention; users on CPU/macOS or Windows (no CUDA support in candle-flash-attn) hit the stub; forgetting the feature flag in cargo build/run commands.","solutions":["Rebuild with `--features candle-transformers/flash-attn` on a CUDA machine.","Set `config.use_flash_attn = false` to use the standard attention path.","Check your platform: on non-CUDA targets the flash-attn feature cannot be enabled, so always disable it in config."],"exampleFix":"// before\nconfig.use_flash_attn = true;\ncargo run --release\n// after\nconfig.use_flash_attn = false;\ncargo run --release","handlingStrategy":"validation","validationCode":"if config.use_flash_attn && !cfg!(feature = \"flash-attn\") {\n    config.use_flash_attn = false;\n    log::warn!(\"flash-attn feature missing; disabled at runtime\");\n}","typeGuard":"fn flash_attn_usable(cfg: &granitemoehybrid::Config) -> bool {\n    !cfg.use_flash_attn || cfg!(feature = \"flash-attn\")\n}","tryCatchPattern":"assert!(flash_attn_usable(&config), \"enable --features candle-transformers/flash-attn or disable use_flash_attn\");","preventionTips":["Enforce feature-flag/config-flag consistency in a shared constructor","Record required cargo features in README/model docs","Avoid enabling flash attention on macOS/CPU builds","Use cfg!(feature = ...) checks instead of assuming feature availability"],"tags":["rust","candle","feature-flag","flash-attention","panic"],"backgroundTag":"missing-cargo-feature","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}