huggingface/candle · error
compile with '--features flash-attn'
Error message
compile with '--features flash-attn'
What it means
granite.rs defines a `flash_attn` function whose fallback build (without the `flash-attn` cargo feature) panics with `unimplemented!`. When `CausalSelfAttention` forward selects the flash path because `config.use_flash_attn` is true, this stub is hit and the program aborts.
Source
Thrown at candle-transformers/src/models/granite.rs:212
span: tracing::Span,
span_rot: tracing::Span,
max_position_embeddings: usize,
}
#[cfg(feature = "flash-attn")]
fn flash_attn(
q: &Tensor,
k: &Tensor,
v: &Tensor,
softmax_scale: f32,
causal: bool,
) -> Result<Tensor> {
candle_flash_attn::flash_attn(q, k, v, softmax_scale, causal)
}
#[cfg(not(feature = "flash-attn"))]
fn flash_attn(_: &Tensor, _: &Tensor, _: &Tensor, _: f32, _: bool) -> Result<Tensor> {
unimplemented!("compile with '--features flash-attn'")
}
impl CausalSelfAttention {
fn apply_rotary_emb(&self, x: &Tensor, index_pos: usize, cache: &Cache) -> Result<Tensor> {
let _enter = self.span_rot.enter();
let (_b_sz, _, seq_len, _hidden_size) = x.dims4()?;
let cos = cache.cos.narrow(0, index_pos, seq_len)?;
let sin = cache.sin.narrow(0, index_pos, seq_len)?;
candle_nn::rotary_emb::rope(x, &cos, &sin)
}
fn forward(
&self,
x: &Tensor,
index_pos: usize,
block_idx: usize,
cache: &mut Cache,
) -> Result<Tensor> {View on GitHub (pinned to d5fee525bf)
Solutions
- Recompile with the feature: `cargo run --release --features candle-transformers/flash-attn` (CUDA required).
- Set `config.use_flash_attn = false` before creating the model.
- If you cannot enable CUDA, keep the default attention implementation and accept slower inference.
Example fix
// before cargo build --release // after cargo build --release --features candle-transformers/flash-attn
Defensive patterns
Strategy: validation
Validate before calling
#[cfg(not(feature = "flash-attn"))]
if config.use_flash_attn {
return Err(anyhow::anyhow!("granite: rebuild with --features candle-transformers/flash-attn or set use_flash_attn=false"));
} Type guard
fn flash_ok(cfg: &granite::Config) -> bool {
!cfg.use_flash_attn || cfg!(feature = "flash-attn")
} Try / catch
let config = if flash_ok(config) { config } else { config.with_flash_attn(false) }; Prevention
- Validate config flags against enabled cargo features at startup
- Keep CUDA-specific features behind explicit feature checks
- Search checkpoint config.json for flash-attention keys when porting models
- Run a one-token forward pass as a startup self-check
When it happens
Trigger: Running the Granite model with `use_flash_attn: true` in Config while compiled without `--features flash-attn`.
Common situations: Checkpoint config enables flash attention; default builds without the feature; attempting to use the feature on non-CUDA systems where candle-flash-attn cannot run.
Related errors
- compile with '--features flash-attn'
- compile with '--features flash-attn'
- compile with '--features flash-attn'
- compile with '--features flash-attn'
- compile with '--features flash-attn'
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/bcfc3dc43ab8863c.
Report an issue: GitHub.