{"record":{"id":"d6be95307d5d134d","repo":"Lightning-AI/pytorch-lightning","slug":"type-self-name-object-has-no-attribute-d6be95","errorCode":null,"errorMessage":"'{type(self).__name__}' object has no attribute '{name}'","messagePattern":"'(.+?)' object has no attribute '(.+?)'","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/load.py","lineNumber":176,"sourceCode":"            \"grad_fn\",\n            \"is_meta\",\n            \"layout\",\n            \"names\",\n            \"ndim\",\n            \"output_nr\",\n            \"requires_grad\",\n            \"retains_grad\",\n            \"size\",\n            \"shape\",\n            \"volatile\",\n        }:\n            return getattr(self.metatensor, name)\n\n        # materializing these is needed for quantization (see lit-gpt)\n        if name in {\"contiguous\", \"cuda\", \"half\", \"data\", \"to\"}:\n            return getattr(self._load_tensor(), name)\n\n        raise AttributeError(f\"'{type(self).__name__}' object has no attribute '{name}'\")\n\n    def __repr__(self) -> str:\n        return f\"{self.__class__.__name__}({repr(self.metatensor)})\"\n\n\n# Modified from https://github.com/lernapparat/torchhacks by Thomas Viehmann\nclass _LazyLoadingUnpickler(pickle.Unpickler):\n    def __init__(self, file: IO, file_reader: torch.PyTorchFileReader) -> None:\n        super().__init__(file)\n        self.file_reader = file_reader\n\n    @override\n    def find_class(self, module: str, name: str) -> Any:\n        if module == \"torch._utils\" and name == \"_rebuild_tensor_v2\":\n            return partial(_NotYetLoadedTensor.rebuild_tensor_v2, archiveinfo=self)\n        if module == \"torch._tensor\" and name == \"_rebuild_from_type_v2\":\n            return partial(_NotYetLoadedTensor.rebuild_from_type_v2, archiveinfo=self)\n        if module == \"torch._utils\" and name == \"_rebuild_parameter\":","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/load.py#L158-L194","documentation":"This AttributeError comes from `_UnloadedTensor` (Lightning's lazy checkpoint loading via `_lazy_load`), which wraps tensors that live on disk in a checkpoint instead of memory. It forwards most attribute access to the underlying meta tensor or materializes the tensor for a few special names (`contiguous`, `cuda`, `half`, `data`, `to`), but any other tensor attribute/method on an unloaded tensor cannot be served and raises.","triggerScenarios":"Calling arbitrary tensor methods/attributes (e.g. `.shape` is fine via metatensor, but e.g. `.float()`, `.view(...)`, `.t()`, `.numpy()`) directly on tensors obtained from a lazily-loaded checkpoint (`_lazy_load`, quantized/lazy checkpoint workflows like lit-gpt).","commonSituations":"Inspecting or manipulating weights right after lazy-loading a large/quantized checkpoint without materializing it; code written for regular tensors reused against lazily loaded state dicts.","solutions":["Materialize the tensor first via `.to(torch.float32)`, `.cuda`, `.contiguous()`, or `.data`, which are handled by the wrapper","Load the checkpoint fully (non-lazy `torch.load`) if you need arbitrary tensor operations","Restructure code to call `.to(...)`/`.data` before any other tensor method"],"exampleFix":"// before\nw = state[\"model\"][\"proj.weight\"]\nx = w.float()  # AttributeError on _UnloadedTensor\n\n// after\nw = state[\"model\"][\"proj.weight\"]\nw = w.to(torch.float32)  # materializes\nx = w.float()","handlingStrategy":"fallback","validationCode":"def materialize(t):\n    return t.to(t.metatensor.dtype) if hasattr(t, \"metatensor\") else t","typeGuard":"def is_unloaded_tensor(t) -> bool:\n    return hasattr(t, \"metatensor\") and hasattr(t, \"_load_tensor\")","tryCatchPattern":null,"preventionTips":["Materialize lazily loaded tensors with .to/.data/.contiguous before arbitrary ops","Keep heavy inspection code paths on fully loaded state dicts"],"tags":["lightning","lazy-loading","checkpoints"],"backgroundTag":"attribute-access-on-proxy-object","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}