{"record":{"id":"a769aeb8ae40ca5a","repo":"tracel-ai/burn","slug":"failed-to-get-data-for-tensor","errorCode":null,"errorMessage":"Failed to get data for tensor '{}': {:?}","messagePattern":"Failed to get data for tensor '(.+?)': (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/burn-store/src/safetensors/store.rs","lineNumber":620,"sourceCode":"impl safetensors::View for PackTensorView {\n    fn dtype(&self) -> safetensors::Dtype {\n        // Convert from burn dtype to safetensors dtype\n        dtype_to_safetensors(self.0.dtype).unwrap_or(safetensors::Dtype::F32)\n    }\n\n    fn shape(&self) -> &[usize] {\n        &self.0.shape\n    }\n\n    fn data(&self) -> alloc::borrow::Cow<'_, [u8]> {\n        // Only materialize data when actually needed for serialization\n        // `View::data` has no error channel, so this is the one place a materialization\n        // failure cannot be returned. Name the tensor at least, since the writer's own\n        // annotation is not reached from here.\n        let bytes = self\n            .0\n            .to_bytes()\n            .unwrap_or_else(|e| panic!(\"Failed to get data for tensor '{}': {:?}\", self.0.name, e));\n        alloc::borrow::Cow::Owned(bytes.deref().to_vec())\n    }\n\n    fn data_len(&self) -> usize {\n        // Known from the descriptor, without drawing the bytes\n        self.0.byte_len()\n    }\n}\n\nimpl ModuleStore for SafetensorsStore {\n    type Error = SafetensorsStoreError;\n\n    fn collect_from<M: ModuleSnapshot>(&mut self, module: &M) -> Result<(), Self::Error> {\n        // Invalidate cache since we're writing new data\n        match self {\n            #[cfg(feature = \"std\")]\n            Self::File(p) => p.tensors_cache = None,\n            Self::Memory(p) => p.tensors_cache = None,","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-store/src/safetensors/store.rs#L602-L638","documentation":"In burn-store's safetensors writer, `View::data` must return the tensor's bytes but has no error channel, so a failure while materializing tensor data (`to_bytes()`) cannot be propagated and instead panics, naming the tensor. This typically wraps an underlying store error (device read failure, unsupported dtype/layout, IO problem) that the safetensors export path cannot report gracefully.","triggerScenarios":"Exporting a module/tensor to safetensors (ModuleSnapshot / record saving via SafetensorsStore) when `to_bytes()` on the underlying tensor view fails — e.g. the tensor data lives on a device that cannot be read, or the backend returns an error while gathering data.","commonSituations":"Saving a model whose tensors reside on a GPU that is unavailable/disconnected; exporting a lazily-computed or remote (burn-remote) tensor whose fetch fails; dtype/shape combinations unsupported by the safetensors exporter.","solutions":["Ensure all tensors are on an accessible device and synchronized before export (e.g. move to CPU / call sync).","Catch the underlying cause from the panic message (tensor name + inner error) and fix the reported backend/IO issue.","If exporting from a remote backend, read tensors locally first, then save with SafetensorsStore.","Check the dtype is supported by safetensors and convert unsupported dtypes before export."],"exampleFix":"// before\nmodel.save(SafetensorsStore::from_file(\"model.safetensors\"))?; // panics if GPU tensor unreadable\n// after\nlet model = model.to_device(&Default::default()); // move to CPU first\nmodel.verify()?; // ensure data is materialized\nmodel.save(SafetensorsStore::from_file(\"model.safetensors\"))?;","handlingStrategy":"validation","validationCode":"// verify data is materialized and readable before export\nmodel.verify()?;\nfor param in model.parameters() {\n    assert!(param.is_ready(), \"tensor not ready for export\");\n}","typeGuard":null,"tryCatchPattern":"// panic escapes View::data; guard the save call\nlet result = std::panic::catch_unwind(AssertUnwindSafe(||\n    model.save(SafetensorsStore::from_file(\"model.safetensors\"))\n));","preventionTips":["Move tensors to an accessible device (CPU) before saving","Call sync()/verify() on the model before export","Avoid exporting tensors from remote/lazy backends directly"],"tags":["rust","panic","safetensors","serialization"],"backgroundTag":"tensor-materialization-failed","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"}