{"record":{"id":"b2cb1d31b8ef7e73","repo":"deepfakes/faceswap","slug":"the-state-file-state-file-does-not-exist-this","errorCode":null,"errorMessage":"The state file '{state_file}' does not exist. This model cannot be ported","messagePattern":"The state file '(.+?)' does not exist\\. This model cannot be ported","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"plugins/train/model/_base/update.py","lineNumber":109,"sourceCode":"            item[2] = int(item[2])\n        logger.debug(\"Unwrapped outputs: %s to: %s\", outputs, retval)\n        return retval\n\n    def _get_clip_config(self) -> dict[str, T.Any]:\n        \"\"\"Build a clip model from the configuration information stored in the legacy state file\n\n        Returns\n        -------\n        The new keras configuration for a Clip model\n\n        Raises\n        ------\n        FaceswapError\n            If the clip model cannot be built\n        \"\"\"\n        state_file = f\"{os.path.splitext(self._old_model_file)[0]}_state.json\"\n        if not os.path.isfile(state_file):\n            raise FaceswapError(\n                f\"The state file '{state_file}' does not exist. This model cannot be ported\")\n\n        with open(state_file, \"r\", encoding=\"utf-8\") as ifile:\n            config = json.load(ifile)\n\n        logger.debug(\"Loaded legacy config '%s': %s\", state_file, config)\n        net_name = config.get(\"config\", {}).get(\"enc_architecture\", \"\")\n        scaling = config.get(\"config\", {}).get(\"enc_scaling\", 0) / 100\n\n        # Import here to prevent circular imports\n        from plugins.train.model.phaze_a import _MODEL_MAPPING  # pylint:disable=C0415\n        vit_info = _MODEL_MAPPING.get(net_name)\n\n        if not scaling or not vit_info:\n            raise FaceswapError(\n                f\"Clip network could not be found in '{state_file}'. Discovered network is \"\n                f\"'{net_name}' with encoder scaling: {scaling}. This model cannot be ported\")\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/plugins/train/model/_base/update.py#L91-L127","documentation":"FaceswapError raised when porting a legacy Faceswap 2 model to Faceswap 3: the code derives a companion state file path (<model>_state.json next to the .h5) and that file does not exist. The state file holds the training configuration needed to rebuild the model architecture, so without it the port cannot proceed. Only the .h5 was found; the JSON sidecar is missing.","triggerScenarios":"Porting with an .h5 file whose sibling <basename>_state.json was deleted or never copied. os.path.isfile on f'{splitext(old_model_file)[0]}_state.json' returns False.","commonSituations":"User copies only the .h5 weights file out of a model folder, loses the state file in a partial backup, or renames the .h5 without renaming the state JSON.","solutions":["Restore the matching <model>_state.json into the same folder as the .h5 file","If the .h5 was renamed, rename the state JSON to share the same basename","If the state file is lost, the model cannot be ported; retrain or obtain the full original model folder"],"exampleFix":"# before\n/models/model.h5            # present\n/models/model_state.json     # missing -> error\n\n# after (shell)\ncp /backup/model_state.json /models/\n# basename of h5 and state json must match before the _state.json suffix","handlingStrategy":"validation","validationCode":"import os\nstate = f\"{os.path.splitext(model_h5)[0]}_state.json\"\nif not os.path.isfile(state):\n    raise SystemExit(f\"Missing {state}; porting requires the .h5 and its state json together\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always copy the whole model folder, never just the weights file","Keep the .h5 and _state.json basenames in sync when renaming"],"tags":["faceswap","migration","filesystem","state-file"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}