tracel-ai/burn · error

unsupported dispatch device: {__other:?}

Error message

unsupported dispatch device: {__other:?}

What it means

Generated by expand_creation as the inner fallback arm: when the macro unwraps DispatchDevice::Autodiff and its inner device matches no known backend (and is not a nested Autodiff), it panics with the unsupported device. This is a catch-all for an inner device the macro generated arms for — meaning a backend feature is not compiled in or the enum gained an unknown variant.

Source

Thrown at crates/burn-backend-extension/src/dispatch.rs:345

    body: &syn::Block,
) -> TokenStream {
    let direct_arms = BACKENDS
        .iter()
        .map(|backend| creation_arm(backend, output, body, false));
    let autodiff_arms = BACKENDS
        .iter()
        .map(|backend| creation_arm(backend, output, body, true));
    quote! {
        match #device {
            #(#direct_arms)*
            #[cfg(feature = "autodiff")]
            crate::DispatchDevice::Autodiff(__device) => match __device.inner.as_ref() {
                #(#autodiff_arms)*
                crate::DispatchDevice::Autodiff(_) => {
                    panic!("Autodiff should not wrap an autodiff device.")
                }
                #[allow(unreachable_patterns)]
                __other => panic!("unsupported dispatch device: {__other:?}"),
            },
            #[allow(unreachable_patterns)]
            __other => panic!("unsupported dispatch device: {__other:?}"),
        }
    }
}

fn creation_arm(
    backend: &crate::BackendSpec,
    output: &OperationOutput,
    body: &syn::Block,
    autodiff_device: bool,
) -> TokenStream {
    let ident = syn::Ident::new(backend.name, proc_macro2::Span::call_site());
    let cfg: TokenStream = backend.cfg.parse().expect("valid backend cfg");
    if !autodiff_device {
        let wrapped = routing::wrap_output(
            output,

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Enable the cargo feature for the inner backend (e.g. the backend-specific feature in burn-backend-extension) so the corresponding cfg-gated arm is generated
  2. Inspect the printed device in the panic to identify which backend variant is missing
  3. Align feature flags across all crates in the workspace so every consumer compiles with the same backends
  4. Update to matching versions of the dispatch crates if a new device variant exists

Example fix

// before (Cargo.toml)
[features]
default = ["autodiff"]
// after
[features]
default = ["autodiff", "backend-cpu"]  # ensure the inner backend feature is on
Defensive patterns

Strategy: validation

Validate before calling

fn supports_inner(device: &DispatchDevice) -> bool {
    match device {
        DispatchDevice::Autodiff(inner) => !matches!(
            inner.inner.as_ref(),
            DispatchDevice::Cpu(_) if !cfg!(feature = "backend-cpu")
        ) && !matches!(inner.inner.as_ref(), DispatchDevice::Autodiff(_)),
        _ => true,
    }
}

Type guard

fn is_autodiff_device(d: &DispatchDevice) -> Option<&AutodiffDevice> {
    match d { DispatchDevice::Autodiff(inner) => Some(inner), _ => None }
}

Try / catch

let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| op(&device)));
match result {
    Ok(v) => v,
    Err(_) => eprintln!("dispatch device unsupported; check backend features"),
}

Prevention

When it happens

Trigger: Creating a tensor/operation with an Autodiff device whose inner device belongs to a backend whose cfg feature flag is disabled at compile time, or an otherwise unknown inner DispatchDevice variant.

Common situations: Enabling feature = "autodiff" but not the backend feature the inner device targets; mixing crates compiled with different backend feature sets; version mismatch after a new DispatchDevice variant was added.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/cc945a35b6868301. Report an issue: GitHub.