{"record":{"id":"a9a94fcbb2066aba","repo":"Lightning-AI/pytorch-lightning","slug":"you-set-load-from-checkpoint-strict-strict","errorCode":null,"errorMessage":"You set `.load_from_checkpoint(..., strict={strict!r})` which is in conflict with `{cls.__name__}.strict_loading={obj.strict_loading!r}. Please set the same value for both of them.","messagePattern":"You set `\\.load_from_checkpoint\\(\\.\\.\\., strict=(.+?)\\)` which is in conflict with `(.+?)\\.strict_loading=(.+?)\\. Please set the same value for both of them\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/core/saving.py","lineNumber":187,"sourceCode":"                \" add the path to `lightning.pytorch.core.saving._ALLOWED_INSTANTIATORS` before loading.\"\n            )\n        module_path, name = instantiator_path.rsplit(\".\", 1)\n        instantiator = getattr(__import__(module_path, fromlist=[name]), name)\n\n    if not cls_spec.varkw:\n        # filter kwargs according to class init unless it allows any argument via kwargs\n        _cls_kwargs = {k: v for k, v in _cls_kwargs.items() if k in cls_init_args_name}\n\n    obj = instantiator(cls, _cls_kwargs) if instantiator else cls(**_cls_kwargs)\n\n    if isinstance(obj, pl.LightningDataModule):\n        if obj.__class__.__qualname__ in checkpoint:\n            obj.load_state_dict(checkpoint[obj.__class__.__qualname__])\n        return obj\n\n    if isinstance(obj, pl.LightningModule):\n        if obj._strict_loading is not None and strict is not None and strict != obj.strict_loading:\n            raise ValueError(\n                f\"You set `.load_from_checkpoint(..., strict={strict!r})` which is in conflict with\"\n                f\" `{cls.__name__}.strict_loading={obj.strict_loading!r}. Please set the same value for both of them.\"\n            )\n        strict = obj.strict_loading if strict is None else strict\n\n        if is_overridden(\"configure_model\", obj):\n            obj.configure_model()\n\n        # give model a chance to load something\n        obj.on_load_checkpoint(checkpoint)\n\n    # load the state_dict on the model automatically\n    keys = obj.load_state_dict(checkpoint[\"state_dict\"], strict=strict)  # type: ignore[arg-type]\n\n    if not strict:\n        if keys.missing_keys:\n            rank_zero_warn(\n                f\"Found keys that are in the model state dict but not in the checkpoint: {keys.missing_keys}\"","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/core/saving.py#L169-L205","documentation":"Raised when the strict argument passed to load_from_checkpoint conflicts with the strict_loading attribute set on the LightningModule (__init__ strict_loading=...). Lightning requires both values to agree (or one to be None) to avoid ambiguity about whether load_state_dict is strict.","triggerScenarios":"Defining class MyModel(pl.LightningModule) with strict_loading=False and then calling MyModel.load_from_checkpoint(ckpt, strict=True), or any combination where both are non-None and differ.","commonSituations":"A module author pins strict_loading for all users; a user of the class passes the familiar strict= kwarg from older Lightning versions with a different value, causing the conflict.","solutions":["Pass the same value: either omit strict in load_from_checkpoint (module default wins) or match it","Or change the module's strict_loading constructor arg to match the desired call-site value"],"exampleFix":"// before\nmodel = MyModel.load_from_checkpoint(ckpt, strict=True)  # module has strict_loading=False\n// after\nmodel = MyModel.load_from_checkpoint(ckpt)  # uses module's strict_loading","handlingStrategy":"validation","validationCode":"strict = None  # simplest: let the module's strict_loading decide\n# or explicitly reconcile:\n# strict = model_kw_strict if model_kw_strict == cls_strict_loading else None","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one mechanism: either set strict_loading in the module OR pass strict at call sites, not both","Omit strict in load_from_checkpoint when the module defines strict_loading"],"tags":["lightning","checkpoint","strict-loading","config-conflict"],"backgroundTag":"conflicting-configuration-values","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}