{"record":{"id":"0a24eff2db1b2df7","repo":"deepfakes/faceswap","slug":"clip-network-could-not-be-found-in-state-file","errorCode":null,"errorMessage":"Clip network could not be found in '{state_file}'. Discovered network is '{net_name}' with encoder scaling: {scaling}. This model cannot be ported","messagePattern":"Clip network could not be found in '(.+?)'\\. Discovered network is '(.+?)' with encoder scaling: (.+?)\\. This model cannot be ported","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"plugins/train/model/_base/update.py","lineNumber":124,"sourceCode":"        \"\"\"\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\n        input_size = int(max(vit_info.min_size, ((vit_info.default_size * scaling) // 16) * 16))\n        vit_model = ViT(T.cast(TypeModelsViT, vit_info.keras_name), input_size=input_size)()\n\n        retval = vit_model.get_config()\n        del vit_model\n        logger.debug(\"Got new config for '%s' at input size: %s: %s\", net_name, input_size, retval)\n        return retval\n\n    def _convert_lambda_config(self, layer: dict[str, T.Any]):\n        \"\"\"Keras 2 TFLambdaOps are not compatible with Keras 3. Scalar operations can be\n        relatively easily substituted with a :class:`~lib.model.layers.ScalarOp` layer\n\n        Parameters\n        ----------\n        layer","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/plugins/train/model/_base/update.py#L106-L142","documentation":"FaceswapError raised while porting a legacy Phaze-A 'Clip' (ViT) model: the enc_architecture found in the legacy state file is not in _MODEL_MAPPING, or enc_scaling is 0/falsy after dividing by 100. Both are required to compute the new ViT input size and rebuild the network. The message reports the discovered net name and scaling for diagnosis.","triggerScenarios":"Porting a Phaze-A model whose state file has enc_architecture not present in plugins.train.model.phaze_a._MODEL_MAPPING, or enc_scaling = 0. Condition: not scaling or not vit_info.","commonSituations":"Porting a model trained on an older/newer Faceswap whose architecture list differs, an edited or corrupted state file, or a hand-modified enc_scaling of 0.","solutions":["Open the state JSON and check config.enc_architecture spelling against the architectures in phaze_a.py's _MODEL_MAPPING","Ensure config.enc_scaling is a non-zero positive integer (percentage)","If the architecture genuinely no longer exists in your Faceswap version, port the model with the version it was trained on"],"exampleFix":"# before (in <model>_state.json)\n\"config\": {\"enc_architecture\": \"clip_vit_b32x\", \"enc_scaling\": 0}\n\n# after\n\"config\": {\"enc_architecture\": \"clip_vit_b32\", \"enc_scaling\": 100}","handlingStrategy":"validation","validationCode":"import json\nwith open(state_file, encoding=\"utf-8\") as fh:\n    cfg = json.load(fh).get(\"config\", {})\nnet, scaling = cfg.get(\"enc_architecture\", \"\"), cfg.get(\"enc_scaling\", 0)\nfrom plugins.train.model.phaze_a import _MODEL_MAPPING\nif not scaling or net not in _MODEL_MAPPING:\n    raise SystemExit(f\"Cannot port: arch={net!r} scaling={scaling}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Port models with the same Faceswap version line they were trained on","Do not hand-edit enc_architecture/enc_scaling in state files"],"tags":["faceswap","phaze-a","migration","config"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}