{"record":{"id":"5fbc4782b4876890","repo":"tracel-ai/burn","slug":"burn-device-flex-requested-but-the-flex-feature","errorCode":null,"errorMessage":"BURN_DEVICE=flex requested, but the 'flex' feature is not enabled.","messagePattern":"BURN_DEVICE=flex requested, but the 'flex' feature is not enabled\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/burn-dispatch/src/device.rs","lineNumber":278,"sourceCode":"                        return Self::Cube(CubeDevice::Cpu(Default::default()));\n                        panic!(\"BURN_DEVICE=cpu requested, but the 'cpu' feature is not enabled.\");\n                    }\n                    \"tch\" => {\n                        #[cfg(feature = \"tch\")]\n                        return Self::LibTorch(LibTorchDevice::default());\n                        panic!(\"BURN_DEVICE=tch requested, but the 'tch' feature is not enabled.\");\n                    }\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","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-dispatch/src/device.rs#L260-L296","documentation":"This panic fires when the BURN_DEVICE environment variable selects the 'flex' backend but the burn build was compiled without the 'flex' feature (and without default_backend matching). Burn dispatches to a backend at device-construction time based on compile-time cargo features; a runtime env var cannot enable a backend that was not compiled in. The library panics immediately rather than silently falling back, so the misconfiguration is surfaced at startup.","triggerScenarios":"Running any Burn program with BURN_DEVICE=flex set in the environment while the crate was built without `features = [\"flex\"]` (and without a default_backend feature) on crates/burn-dispatch/src/device.rs:278 during DispatchDevice::from_env/default parsing.","commonSituations":"Copying a run command or Dockerfile from a project that uses the flex backend into a project whose Cargo.toml lacks the feature; CI images built with a reduced feature set; toggling BURN_DEVICE between experiments without rebuilding with the matching features.","solutions":["Add the flex feature to the burn dependency in Cargo.toml, e.g. burn = { version = \"...\", features = [\"flex\"] }, and rebuild.","Alternatively enable a catch-all default_backend feature (burn = { features = [\"default_backend-flex\"] }) so BURN_DEVICE=flex resolves.","If flex is not intended, unset BURN_DEVICE or set it to a backend that is actually compiled in (e.g. ndarray, candle).","Verify compiled features with `cargo tree -e features -i burn` or check the burn features docs before setting the env var."],"exampleFix":"// before (Cargo.toml)\n[dependencies]\nburn = { version = \"0.18\", features = [\"ndarray\"] }\n// BURN_DEVICE=flex ./app  -> panics\n\n// after\n[dependencies]\nburn = { version = \"0.18\", features = [\"flex\"] }\n// BURN_DEVICE=flex ./app  -> DispatchDevice::Flex(FlexDevice)","handlingStrategy":"validation","validationCode":"// before constructing the device\nlet req = std::env::var(\"BURN_DEVICE\").unwrap_or_default();\nif req == \"flex\" && !cfg!(feature = \"flex\") && !cfg!(default_backend) {\n    panic!(\"Rebuild with burn feature 'flex' or unset BURN_DEVICE\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the BURN_DEVICE values supported by your binary documented next to the burn features list in Cargo.toml.","Assert the env var against compiled features in a #[test] or startup check.","Use default_backend-* features so env overrides always resolve."],"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"}