{"record":{"id":"8a2a8edfc1031828","repo":"apache/beam","slug":"a-param1-has-been-supplied-to-the-model-handler-but-the","errorCode":null,"errorMessage":"A {param1} has been supplied to the model handler, but the required {param2} is missing. Please provide the {param2} in order to successfully load the {param1}.","messagePattern":"A (.+?) has been supplied to the model handler, but the required (.+?) is missing\\. Please provide the (.+?) in order to successfully load the (.+?)\\.","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/inference/pytorch_inference.py","lineNumber":83,"sourceCode":"    # because a driver is missing or inaccessible.\n    torch.empty(1, device='cuda')\n    return True\n  except Exception:  # pylint: disable=broad-except\n    logging.warning(\"CUDA probe failed\", exc_info=True)\n    return False\n\n\ndef _validate_constructor_args(\n    state_dict_path, model_class, torch_script_model_path):\n  message = (\n      \"A {param1} has been supplied to the model \"\n      \"handler, but the required {param2} is missing. \"\n      \"Please provide the {param2} in order to \"\n      \"successfully load the {param1}.\")\n  # state_dict_path and model_class are coupled with each other\n  # raise RuntimeError if user forgets to pass any one of them.\n  if state_dict_path and not model_class:\n    raise RuntimeError(\n        message.format(param1=\"state_dict_path\", param2=\"model_class\"))\n\n  if not state_dict_path and model_class:\n    raise RuntimeError(\n        message.format(param1=\"model_class\", param2=\"state_dict_path\"))\n\n  if torch_script_model_path and state_dict_path:\n    raise RuntimeError(\n        \"Please specify either torch_script_model_path or \"\n        \"(state_dict_path, model_class) to successfully load the model.\")\n\n\ndef _load_model(\n    model_class: Optional[Callable[..., torch.nn.Module]],\n    state_dict_path: Optional[str],\n    device: torch.device,\n    model_params: Optional[dict[str, Any]],\n    torch_script_model_path: Optional[str],","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/inference/pytorch_inference.py#L65-L101","documentation":"PyTorchModelHandler couples state_dict_path with model_class: giving a state dict without the class leaves the handler unable to instantiate the architecture to load weights into, so it raises RuntimeError with the param1/param2 template (param1=state_dict_path, param2=model_class).","triggerScenarios":"PyTorchModelHandler(state_dict_path='model.pth') without model_class.","commonSituations":"Config supplies the weights path but not the class; class import removed during refactor; using a pipeline-style handler expectation.","solutions":["Add model_class, e.g. model_class=MyNet (a class, not an instance).","Ensure the class reference isn't None from a failed import/config lookup.","Or drop state_dict_path and load from a torch_script_model_path if you have a scripted model."],"exampleFix":"// before\nhandler = PyTorchModelHandler(state_dict_path='gs://bucket/model.pth')\n// after\nhandler = PyTorchModelHandler(state_dict_path='gs://bucket/model.pth', model_class=MyNet)","handlingStrategy":"validation","validationCode":"if state_dict_path and model_class is None:\n    raise ValueError('state_dict_path requires model_class')","typeGuard":"def state_dict_pair_ok(path, cls) -> bool:\n    return not (bool(path) != bool(cls))","tryCatchPattern":"try:\n    handler = PyTorchModelHandler(state_dict_path=p, model_class=cls)\nexcept RuntimeError as e:\n    if 'state_dict_path' in str(e) and 'model_class' in str(e):\n        logging.error('Provide model_class alongside state_dict_path')\n    raise","preventionTips":["Treat state_dict_path + model_class as an atomic pair in configs","Assert the class import succeeded before constructing the handler"],"tags":["python","apache-beam","pytorch","constructor-validation","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}