{"record":{"id":"ba607c047fadf31c","repo":"apache/beam","slug":"please-provide-either-task-or-model-to-the","errorCode":null,"errorMessage":"Please provide either task or model to the HuggingFacePipelineModelHandler. If the model already defines the task, no need to specify the task.","messagePattern":"Please provide either task or model to the HuggingFacePipelineModelHandler\\. If the model already defines the task, no need to specify the task\\.","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/inference/huggingface_inference.py","lineNumber":161,"sourceCode":"\n\ndef get_device_torch(device):\n  if device == \"GPU\" and is_gpu_available_torch():\n    return torch.device(\"cuda\")\n  return torch.device(\"cpu\")\n\n\ndef is_gpu_available_tensorflow(device):\n  gpu_devices = tf.config.list_physical_devices(device)\n  if len(gpu_devices) == 0:\n    no_gpu_available_warning()\n    return False\n  return True\n\n\ndef _validate_constructor_args_hf_pipeline(task, model):\n  if not task and not model:\n    raise RuntimeError(\n        'Please provide either task or model to the '\n        'HuggingFacePipelineModelHandler. If the model already defines the '\n        'task, no need to specify the task.')\n\n\ndef _run_inference_torch_keyed_tensor(\n    batch: Sequence[dict[str, torch.Tensor]],\n    model: AutoModel,\n    device,\n    inference_args: dict[str, Any],\n    model_id: Optional[str] = None) -> Iterable[PredictionResult]:\n  device = get_device_torch(device)\n  key_to_tensor_list = defaultdict(list)\n  # torch.no_grad() mitigates GPU memory issues\n  # https://github.com/apache/beam/issues/22811\n  with torch.no_grad():\n    for example in batch:\n      for key, tensor in example.items():","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/inference/huggingface_inference.py#L143-L179","documentation":"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.","triggerScenarios":"HuggingFacePipelineModelHandler() with both task=None and model=None.","commonSituations":"Empty/default constructor args; config keys for task/model both unset; typo'd parameter names so both arrive as None.","solutions":["Pass a task like task='text-classification'.","Or pass a model id/path that defines its task: model='distilbert-base-uncased-finetuned-sst-2-english'.","Pass both to be explicit about the pipeline type."],"exampleFix":"// before\nhandler = HuggingFacePipelineModelHandler(load_pipeline_args={'device': 0})\n// after\nhandler = HuggingFacePipelineModelHandler(task='sentiment-analysis', model='distilbert-base-uncased-finetuned-sst-2-english')","handlingStrategy":"validation","validationCode":"if not task and not model:\n    raise ValueError('HuggingFacePipelineModelHandler requires task or model')","typeGuard":"def pipeline_args_ok(task, model) -> bool:\n    return bool(task) or bool(model)","tryCatchPattern":"try:\n    handler = HuggingFacePipelineModelHandler(task=task, model=model)\nexcept RuntimeError as e:\n    logging.error('Need task or model: %s', e)\n    raise","preventionTips":["Always pass a model id; it usually defines its own task","Check config keys for typos so task/model are not silently None"],"tags":["python","apache-beam","machine-learning","huggingface","constructor-validation"],"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"}