{"record":{"id":"0fbe35148e694a0f","repo":"Lightning-AI/pytorch-lightning","slug":"expected-fabric-save-filter-for-key-k-r-t","errorCode":null,"errorMessage":"Expected `fabric.save(filter=...)` for key {k!r} to be a callable, given {v!r}","messagePattern":"Expected `fabric\\.save\\(filter=\\.\\.\\.\\)` for key (.+?) to be a callable, given (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/fabric.py","lineNumber":865,"sourceCode":"            fabric.save(\"checkpoint.pth\", state)\n\n            # With filter\n            def param_filter(name, param):\n                return \"bias\" not in name  # Save only non-bias parameters\n\n            fabric.save(\"checkpoint.pth\", state, filter={\"model\": param_filter})\n\n        \"\"\"\n        if filter is not None:\n            if not isinstance(filter, dict):\n                raise TypeError(f\"Filter should be a dictionary, given {filter!r}\")\n            if not set(filter).issubset(state):\n                raise ValueError(\n                    f\"The filter keys {filter.keys() - state} are not present in the state keys {set(state)}.\"\n                )\n            for k, v in filter.items():\n                if not callable(v):\n                    raise TypeError(f\"Expected `fabric.save(filter=...)` for key {k!r} to be a callable, given {v!r}\")\n        self._strategy.save_checkpoint(path=path, state=_unwrap_objects(state), filter=filter)\n        self.barrier()\n\n    def load(\n        self,\n        path: Union[str, Path],\n        state: Optional[dict[str, Union[nn.Module, Optimizer, Any]]] = None,\n        strict: bool = True,\n        *,\n        weights_only: Optional[bool] = None,\n    ) -> dict[str, Any]:\n        \"\"\"Load a checkpoint from a file and restore the state of objects (modules, optimizers, etc.).\n\n        How and which processes load gets determined by the `strategy`.\n        This method must be called on all processes!\n\n        Args:\n            path: A path to where the file is located.","sourceCodeStart":847,"sourceCodeEnd":883,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/fabric.py#L847-L883","documentation":"Each value in the fabric.save(filter={...}) dict must be callable — it is applied as a predicate to the tensors/objects under that state key. Passing a non-callable (bool, string, list of names) fails the `callable(v)` check with TypeError naming the offending key and value.","triggerScenarios":"filter={'model': True}, filter={'model': ['weight']}, or filter={'model': 'lambda ...'} (stringified lambda).","commonSituations":"Trying to use filter as an include-list of parameter names; JSON-round-tripped configs turning functions into strings.","solutions":["Provide a function: filter={'model': lambda k, v: k in ('weight', 'bias')}","For simple key selection, build the state dict to only contain what you want to save and omit filter entirely"],"exampleFix":"# before\nfabric.save('ckpt.pth', state, filter={'model': True})\n# after\nfabric.save('ckpt.pth', state, filter={'model': lambda k, v: True})","handlingStrategy":"type-guard","validationCode":"assert all(callable(v) for v in filter.values()), 'filter values must be callables'","typeGuard":"def valid_filter_values(f):\n    return all(callable(v) for v in f.values())","tryCatchPattern":null,"preventionTips":["Never put lists/bools in filter; use lambda k, v: k in {...} for key selection"],"tags":["lightning","fabric","checkpointing","type-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}