tracel-ai/burn · error

unsupported dispatch backend

Error message

unsupported dispatch backend

What it means

Generated by the dispatch macro's generated match: when the tensor kind's backend does not correspond to any registered backend arm (the autodiff route's fallback), the code panics with 'unsupported dispatch backend'. It means the runtime backend kind found in the DispatchTensor has no matching arm in the macro-expanded match.

Source

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

) -> TokenStream {
    let float_inputs = float_input_presence(operation, source);
    let backends = dispatch_backends();
    let source_is_non_float = source.is_some_and(|source| {
        matches!(
            source.kind,
            InputKind::Tensor { kind, .. } if kind != TensorKind::Float
        )
    });
    let paths = routing::RoutingPaths::dispatch();
    let selected =
        source.map(|_| syn::Ident::new("__burn_selected", proc_macro2::Span::call_site()));
    let autodiff_match = (!source_is_non_float).then(|| routing::AutodiffKindMatch {
        cfg_attr: Some(quote!(#[cfg(feature = "autodiff")])),
        inner_kind,
        nested_autodiff: Some(quote! {
            panic!("Autodiff should not wrap an autodiff tensor.")
        }),
        fallback: quote!(panic!("unsupported dispatch backend")),
    });
    let arms = routing::backend_kind_arms(
        &paths,
        &backends,
        selected.as_ref(),
        autodiff_match,
        |_, backend, autodiff| {
            backend_route_body(backend, operation, &float_inputs, autodiff, source)
        },
    );
    let direct_arms = arms.concrete;
    let autodiff_route = if source_is_non_float {
        quote! {
            #[cfg(feature = "autodiff")]
            crate::DispatchTensorKind::Autodiff(_) => {
                panic!("only float tensors may use an autodiff primitive")
            }
        }

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Register the backend you use in the dispatch macro's backend list
  2. Enable the cargo feature that activates the matching backend arm so the tensor matches a concrete arm
  3. Unwrap/convert the tensor to a registered backend before dispatching
  4. Update burn-backend-extension version if a backend arm was added upstream

Example fix

// before
expand_backend_dispatch! { backends: [Wgpu] }
// tensor uses burn_tch::Tch — panic
// after
expand_backend_dispatch! { backends: [Wgpu, Tch] }
Defensive patterns

Strategy: validation

Validate before calling

// Before dispatch, confirm the tensor's backend is registered
// compile-time: list every backend you use in the macro invocation
expand_backend_dispatch! { backends: [Wgpu, Tch] }

Prevention

When it happens

Trigger: Calling a macro-generated dispatch function with a tensor whose backend was not listed in the macro invocation's backend list; feature-flag mismatches (autodiff enabled but no concrete backend arm compiled in) so the fallback arm executes.

Common situations: Adding a new backend to the project but forgetting to register it in the dispatch macro call; building with a feature set where the expected backend arm is cfg'd out; mixing tensors from two different compiled backends at runtime.

Related errors


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