{"record":{"id":"395a287591d28ee7","repo":"tracel-ai/burn","slug":"burn-device-ndarray-requested-but-the-ndarray-f","errorCode":null,"errorMessage":"BURN_DEVICE=ndarray requested, but the 'ndarray' feature is not enabled.","messagePattern":"BURN_DEVICE=ndarray requested, but the 'ndarray' feature is not enabled\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/burn-dispatch/src/device.rs","lineNumber":285,"sourceCode":"                    }\n                    \"remote\" => {\n                        #[cfg(feature = \"remote\")]\n                        return Self::Remote(RemoteDevice::default());\n                        panic!(\n                            \"BURN_DEVICE=remote requested, but the 'remote' feature is not enabled.\"\n                        );\n                    }\n                    \"flex\" => {\n                        #[cfg(any(feature = \"flex\", default_backend))]\n                        return Self::Flex(FlexDevice);\n                        panic!(\n                            \"BURN_DEVICE=flex requested, but the 'flex' feature is not enabled.\"\n                        );\n                    }\n                    \"ndarray\" => {\n                        #[cfg(feature = \"ndarray\")]\n                        return Self::NdArray(NdArrayDevice::default());\n                        panic!(\n                            \"BURN_DEVICE=ndarray requested, but the 'ndarray' feature is not enabled.\"\n                        );\n                    }\n                    _ => panic!(\"Unknown BURN_DEVICE override: '{}'.\", device_str),\n                }\n            }\n        }\n\n        // Spelled out per feature rather than left to `CubeDevice::default()`: that answers for\n        // the runtimes *cubecl* compiled in, and cargo unifies features across a build, so a\n        // workspace that also builds `burn-cuda` would hand this crate a CUDA default even when\n        // it was built with only `wgpu`. The order is the one a caller who did not choose would\n        // want — a discrete accelerator, then the portable path, then the CPU.\n        #[cfg(feature = \"cuda\")]\n        return Self::Cube(CubeDevice::Cuda(Default::default()));\n\n        #[cfg(feature = \"metal\")]\n        return Self::Cube(CubeDevice::Wgpu(Default::default()));","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-dispatch/src/device.rs#L267-L303","documentation":"This panic fires when BURN_DEVICE=ndarray is requested but the burn build was compiled without the 'ndarray' feature. Backend selection via BURN_DEVICE is a runtime override over backends enabled at compile time; if the ndarray backend was not compiled in, the dispatcher cannot construct an NdArrayDevice and panics instead of silently substituting another backend.","triggerScenarios":"Setting BURN_DEVICE=ndarray in the environment while the binary was built without `features = [\"ndarray\"]` in the burn dependency; the panic originates from the \"ndarray\" match arm in device.rs backend parsing.","commonSituations":"Running tests or scripts that assume the lightweight ndarray backend (common in CI for speed) against a build configured for GPU-only features; inheriting BURN_DEVICE from a shared shell profile or Kubernetes manifest while the binary has different features.","solutions":["Enable the feature: burn = { version = \"...\", features = [\"ndarray\"] } in Cargo.toml, then rebuild.","Or enable the unified default_backend-ndarray feature so the env override resolves through the default backend path.","If ndarray was never intended, unset BURN_DEVICE or set it to an enabled backend (cubecl/candle/flex as compiled).","Document required BURN_DEVICE values alongside the feature list so env and build stay in sync."],"exampleFix":"// before\n[dependencies]\nburn = { version = \"0.18\", features = [\"candle\"] }\n// BURN_DEVICE=ndarray ./app -> panics\n\n// after\n[dependencies]\nburn = { version = \"0.18\", features = [\"candle\", \"ndarray\"] }\n// BURN_DEVICE=ndarray ./app -> NdArrayDevice::default()","handlingStrategy":"validation","validationCode":"let req = std::env::var(\"BURN_DEVICE\").unwrap_or_default();\nif req == \"ndarray\" && !cfg!(feature = \"ndarray\") {\n    panic!(\"Rebuild with burn feature 'ndarray' or unset BURN_DEVICE\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the backend in CI both via features and via BURN_DEVICE so they cannot drift.","Add a startup feature check before device construction.","Avoid sharing shell profiles that export BURN_DEVICE across differently-built binaries."],"tags":["rust","feature-flag","environment-variable","configuration","burn"],"backgroundTag":"backend-feature-not-enabled","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}