{"record":{"id":"a1d71dbb34c0a75e","repo":"apache/beam","slug":"device-specified-in-load-pipeline-args-device-parameter-for","errorCode":null,"errorMessage":"`device` specified in `load_pipeline_args`. `device` parameter for HuggingFacePipelineModelHandler will be ignored.","messagePattern":"`device` specified in `load_pipeline_args`\\. `device` parameter for HuggingFacePipelineModelHandler will be ignored\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/inference/huggingface_inference.py","lineNumber":694,"sourceCode":"    if (current_device and current_device != 'CPU' and current_device != 'GPU'):\n      raise ValueError(\n          f\"Invalid device value: {device}. Please specify \"\n          \"either CPU or GPU. Defaults to GPU if no value \"\n          \"is provided.\")\n    if 'device' not in self._load_pipeline_args:\n      if current_device == 'CPU':\n        self._load_pipeline_args['device'] = 'cpu'\n      else:\n        if is_gpu_available_torch():\n          self._load_pipeline_args['device'] = 'cuda:0'\n        else:\n          _LOGGER.warning(\n              \"HuggingFaceModelHandler specified a 'GPU' device, \"\n              \"but GPUs are not available. Switching to CPU.\")\n          self._load_pipeline_args['device'] = 'cpu'\n    else:\n      if current_device:\n        raise ValueError(\n            '`device` specified in `load_pipeline_args`. `device` '\n            'parameter for HuggingFacePipelineModelHandler will be ignored.')\n\n  def load_model(self):\n    \"\"\"Loads and initializes the pipeline for processing.\"\"\"\n    return pipeline(\n        task=self._task, model=self._model, **self._load_pipeline_args)\n\n  def run_inference(\n      self,\n      batch: Sequence[str],\n      pipeline: Pipeline,\n      inference_args: Optional[dict[str, Any]] = None\n  ) -> Iterable[PredictionResult]:\n    \"\"\"\n    Runs inferences on a batch of examples passed as a string resource.\n    These can either be string sentences, or string path to images or\n    audio files.","sourceCodeStart":676,"sourceCodeEnd":712,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/inference/huggingface_inference.py#L676-L712","documentation":"If 'device' is already present in load_pipeline_args, passing the handler's device parameter as well is a conflict: the handler raises ValueError rather than silently overriding the user's pipeline arg. This is a mutually-exclusive-options guard for the same setting supplied two ways.","triggerScenarios":"HuggingFacePipelineModelHandler(device='CPU', load_pipeline_args={'device': 'cuda:0'}) — device set in both places.","commonSituations":"Merging load_pipeline_args from config that already includes device while also passing the explicit device param; copy-pasted examples combining both.","solutions":["Remove the 'device' key from load_pipeline_args and use the device parameter only.","Or remove the device parameter and keep device inside load_pipeline_args.","Keep exactly one source of truth for device placement."],"exampleFix":"// before\nhandler = HuggingFacePipelineModelHandler(task='fill-mask', device='GPU', load_pipeline_args={'device': 'cuda:0'})\n// after\nhandler = HuggingFacePipelineModelHandler(task='fill-mask', load_pipeline_args={'device': 'cuda:0'})","handlingStrategy":"validation","validationCode":"if device is not None and 'device' in load_pipeline_args:\n    raise ValueError('Set device either via parameter or load_pipeline_args, not both')","typeGuard":"def no_device_conflict(device, load_pipeline_args) -> bool:\n    return not (device is not None and 'device' in (load_pipeline_args or {}))","tryCatchPattern":"try:\n    handler = HuggingFacePipelineModelHandler(task=task, device=device, load_pipeline_args=lp_args)\nexcept ValueError as e:\n    if 'load_pipeline_args' in str(e):\n        lp_args = {k: v for k, v in lp_args.items() if k != 'device'}\n        handler = HuggingFacePipelineModelHandler(task=task, device=device, load_pipeline_args=lp_args)\n    else:\n        raise","preventionTips":["Pick one place to specify device (parameter recommended) and document it","Sanitize load_pipeline_args loaded from external config to drop 'device'"],"tags":["python","apache-beam","machine-learning","huggingface","conflicting-options"],"backgroundTag":"conflicting-config-options","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"}