apache/beam · error · RuntimeError

A {param1} has been supplied to the model handler, but the r

Error message

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}.

What it means

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).

Source

Thrown at sdks/python/apache_beam/ml/inference/pytorch_inference.py:83

    # because a driver is missing or inaccessible.
    torch.empty(1, device='cuda')
    return True
  except Exception:  # pylint: disable=broad-except
    logging.warning("CUDA probe failed", exc_info=True)
    return False


def _validate_constructor_args(
    state_dict_path, model_class, torch_script_model_path):
  message = (
      "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}.")
  # state_dict_path and model_class are coupled with each other
  # raise RuntimeError if user forgets to pass any one of them.
  if state_dict_path and not model_class:
    raise RuntimeError(
        message.format(param1="state_dict_path", param2="model_class"))

  if not state_dict_path and model_class:
    raise RuntimeError(
        message.format(param1="model_class", param2="state_dict_path"))

  if torch_script_model_path and state_dict_path:
    raise RuntimeError(
        "Please specify either torch_script_model_path or "
        "(state_dict_path, model_class) to successfully load the model.")


def _load_model(
    model_class: Optional[Callable[..., torch.nn.Module]],
    state_dict_path: Optional[str],
    device: torch.device,
    model_params: Optional[dict[str, Any]],
    torch_script_model_path: Optional[str],

View on GitHub (pinned to 12126d8942)

Solutions

  1. Add model_class, e.g. model_class=MyNet (a class, not an instance).
  2. Ensure the class reference isn't None from a failed import/config lookup.
  3. Or drop state_dict_path and load from a torch_script_model_path if you have a scripted model.

Example fix

// before
handler = PyTorchModelHandler(state_dict_path='gs://bucket/model.pth')
// after
handler = PyTorchModelHandler(state_dict_path='gs://bucket/model.pth', model_class=MyNet)
Defensive patterns

Strategy: validation

Validate before calling

if state_dict_path and model_class is None:
    raise ValueError('state_dict_path requires model_class')

Type guard

def state_dict_pair_ok(path, cls) -> bool:
    return not (bool(path) != bool(cls))

Try / catch

try:
    handler = PyTorchModelHandler(state_dict_path=p, model_class=cls)
except RuntimeError as e:
    if 'state_dict_path' in str(e) and 'model_class' in str(e):
        logging.error('Provide model_class alongside state_dict_path')
    raise

Prevention

When it happens

Trigger: PyTorchModelHandler(state_dict_path='model.pth') without model_class.

Common situations: Config supplies the weights path but not the class; class import removed during refactor; using a pipeline-style handler expectation.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/8a2a8edfc1031828. Report an issue: GitHub.