{"record":{"id":"6bd72ed0fa4bb5e8","repo":"huggingface/candle","slug":"compile-with-features-flash-attn-6bd72e","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/lfm2.rs","lineNumber":225,"sourceCode":"    let on_true = Tensor::new(on_true, on_false.device())?.broadcast_as(shape.dims())?;\n    let m = mask.where_cond(&on_true, on_false)?;\n    Ok(m)\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/// MLP layer with SwiGLU activation.\n#[derive(Debug, Clone)]\nstruct Mlp {\n    gate_proj: Linear,\n    up_proj: Linear,\n    down_proj: Linear,\n    span: tracing::Span,\n}\n\nimpl Mlp {\n    fn new(cfg: &Config, vb: VarBuilder) -> Result<Self> {\n        let hidden_size = cfg.hidden_size;\n        let intermediate_size = cfg.intermediate_size;\n        // LFM2 uses w1 (gate), w3 (up), w2 (down) naming convention\n        let gate_proj = linear(hidden_size, intermediate_size, vb.pp(\"w1\"))?;\n        let up_proj = linear(hidden_size, intermediate_size, vb.pp(\"w3\"))?;","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/lfm2.rs#L207-L243","documentation":"lfm2.rs defines the standard candle `flash_attn` helper whose non-feature stub panics with `unimplemented!`. When the LFM2 model config requests flash attention but the crate lacks the `flash-attn` feature, attention forward reaches the stub and panics.","triggerScenarios":"Running the LFM2 model with `use_flash_attn: true` in Config while the build does not include the `flash-attn` cargo feature.","commonSituations":"Checkpoint config enables flash attention; builds on CPU/macOS where the CUDA-only backend is unavailable; forgetting `--features` on cargo run/test.","solutions":["Rebuild with `cargo build --release --features candle-transformers/flash-attn` on CUDA.","Set `config.use_flash_attn = false` in code or patch the loaded config.","Use the default attention implementation on unsupported platforms."],"exampleFix":"// before\n// built without feature, config.use_flash_attn = true\n// after\ncargo run --release --features candle-transformers/flash-attn","handlingStrategy":"validation","validationCode":"if config.use_flash_attn && !cfg!(feature = \"flash-attn\") {\n    return Err(anyhow::anyhow!(\"lfm2: flash-attn requires --features candle-transformers/flash-attn (CUDA)\"));\n}","typeGuard":"fn flash_attn_enabled_safely(cfg: &lfm2::Config) -> bool {\n    cfg.use_flash_attn && cfg!(feature = \"flash-attn\")\n}","tryCatchPattern":"if !flash_attn_enabled_safely(&config) {\n    config.use_flash_attn = false; // fallback path\n}","preventionTips":["Check feature availability before enabling flash in configs","Keep model configs and cargo features versioned together","Test inference entry points without the feature to catch stub panics early","Use panic hooks or catch_unwind around first forward pass in services"],"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"}