apache/beam · error · RuntimeError

Please provide either task or model to the HuggingFacePipeli

Error message

Please provide either task or model to the HuggingFacePipelineModelHandler. If the model already defines the task, no need to specify the task.

What it means

HuggingFacePipelineModelHandler requires at least one of 'task' (e.g. 'sentiment-analysis') or 'model' (a model id/path) to build a transformers pipeline. Without a task, transformers cannot infer the pipeline type; without a model there is nothing to load.

Source

Thrown at sdks/python/apache_beam/ml/inference/huggingface_inference.py:161


def get_device_torch(device):
  if device == "GPU" and is_gpu_available_torch():
    return torch.device("cuda")
  return torch.device("cpu")


def is_gpu_available_tensorflow(device):
  gpu_devices = tf.config.list_physical_devices(device)
  if len(gpu_devices) == 0:
    no_gpu_available_warning()
    return False
  return True


def _validate_constructor_args_hf_pipeline(task, model):
  if not task and not model:
    raise RuntimeError(
        'Please provide either task or model to the '
        'HuggingFacePipelineModelHandler. If the model already defines the '
        'task, no need to specify the task.')


def _run_inference_torch_keyed_tensor(
    batch: Sequence[dict[str, torch.Tensor]],
    model: AutoModel,
    device,
    inference_args: dict[str, Any],
    model_id: Optional[str] = None) -> Iterable[PredictionResult]:
  device = get_device_torch(device)
  key_to_tensor_list = defaultdict(list)
  # torch.no_grad() mitigates GPU memory issues
  # https://github.com/apache/beam/issues/22811
  with torch.no_grad():
    for example in batch:
      for key, tensor in example.items():

View on GitHub (pinned to 12126d8942)

Solutions

  1. Pass a task like task='text-classification'.
  2. Or pass a model id/path that defines its task: model='distilbert-base-uncased-finetuned-sst-2-english'.
  3. Pass both to be explicit about the pipeline type.

Example fix

// before
handler = HuggingFacePipelineModelHandler(load_pipeline_args={'device': 0})
// after
handler = HuggingFacePipelineModelHandler(task='sentiment-analysis', model='distilbert-base-uncased-finetuned-sst-2-english')
Defensive patterns

Strategy: validation

Validate before calling

if not task and not model:
    raise ValueError('HuggingFacePipelineModelHandler requires task or model')

Type guard

def pipeline_args_ok(task, model) -> bool:
    return bool(task) or bool(model)

Try / catch

try:
    handler = HuggingFacePipelineModelHandler(task=task, model=model)
except RuntimeError as e:
    logging.error('Need task or model: %s', e)
    raise

Prevention

When it happens

Trigger: HuggingFacePipelineModelHandler() with both task=None and model=None.

Common situations: Empty/default constructor args; config keys for task/model both unset; typo'd parameter names so both arrive as None.

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/ba607c047fadf31c. Report an issue: GitHub.