{"record":{"id":"1cae34644d894c1a","repo":"huggingface/candle","slug":"compile-with-features-flash-attn-1cae34","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/mistral.rs","lineNumber":199,"sourceCode":"        let rhs = xs.apply(&self.up_proj)?;\n        (lhs * rhs)?.apply(&self.down_proj)\n    }\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\n#[derive(Debug, Clone)]\nstruct Attention {\n    q_proj: Linear,\n    k_proj: Linear,\n    v_proj: Linear,\n    o_proj: Linear,\n    num_heads: usize,\n    num_kv_heads: usize,\n    num_kv_groups: usize,\n    head_dim: usize,\n    rotary_emb: Arc<RotaryEmbedding>,\n    kv_cache: Option<(Tensor, Tensor)>,\n    use_flash_attn: bool,\n}\n\nimpl Attention {","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/mistral.rs#L181-L217","documentation":"mistral.rs uses the shared candle pattern: a `flash_attn` helper that becomes an `unimplemented!` stub without the `flash-attn` cargo feature. Requesting flash attention in the Mistral model config at runtime hits the stub and panics.","triggerScenarios":"Running a Mistral model with `use_flash_attn: true` in Config (often from the checkpoint's config.json) while built without `--features flash-attn`.","commonSituations":"Default builds without features; non-CUDA environments; users copying mistral examples that enable flash attention without matching cargo flags.","solutions":["Enable the feature on CUDA: `cargo run --release --features candle-transformers/flash-attn`.","Set `config.use_flash_attn = false` before constructing the model.","Ensure build scripts/CI consistently pass the feature flag wherever flash attention is expected."],"exampleFix":"// before\nconfig.use_flash_attn = true;\ncargo run --release\n// after\ncargo run --release --features candle-transformers/flash-attn","handlingStrategy":"validation","validationCode":"if config.use_flash_attn && !cfg!(feature = \"flash-attn\") {\n    eprintln!(\"mistral: flash-attn unavailable; using standard attention\");\n    config.use_flash_attn = false;\n}","typeGuard":"fn flash_safe(cfg: &mistral::Config) -> bool {\n    !cfg.use_flash_attn || cfg!(feature = \"flash-attn\")\n}","tryCatchPattern":"let config = sanitize(config); // where sanitize disables flash unless cfg!(feature = \"flash-attn\")","preventionTips":["Mistral checkpoint configs often set flash-attn; strip it unless supported","Run example commands with the same feature flags documented in the README","Guard with cfg!(feature = \"flash-attn\") at config-load time","Keep a single helper crate/module for flash-attn availability checks"],"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"}