apache/beam · error · ValueError

`device` specified in `load_pipeline_args`. `device` paramet

Error message

`device` specified in `load_pipeline_args`. `device` parameter for HuggingFacePipelineModelHandler will be ignored.

What it means

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.

Source

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

    if (current_device and current_device != 'CPU' and current_device != 'GPU'):
      raise ValueError(
          f"Invalid device value: {device}. Please specify "
          "either CPU or GPU. Defaults to GPU if no value "
          "is provided.")
    if 'device' not in self._load_pipeline_args:
      if current_device == 'CPU':
        self._load_pipeline_args['device'] = 'cpu'
      else:
        if is_gpu_available_torch():
          self._load_pipeline_args['device'] = 'cuda:0'
        else:
          _LOGGER.warning(
              "HuggingFaceModelHandler specified a 'GPU' device, "
              "but GPUs are not available. Switching to CPU.")
          self._load_pipeline_args['device'] = 'cpu'
    else:
      if current_device:
        raise ValueError(
            '`device` specified in `load_pipeline_args`. `device` '
            'parameter for HuggingFacePipelineModelHandler will be ignored.')

  def load_model(self):
    """Loads and initializes the pipeline for processing."""
    return pipeline(
        task=self._task, model=self._model, **self._load_pipeline_args)

  def run_inference(
      self,
      batch: Sequence[str],
      pipeline: Pipeline,
      inference_args: Optional[dict[str, Any]] = None
  ) -> Iterable[PredictionResult]:
    """
    Runs inferences on a batch of examples passed as a string resource.
    These can either be string sentences, or string path to images or
    audio files.

View on GitHub (pinned to 12126d8942)

Solutions

  1. Remove the 'device' key from load_pipeline_args and use the device parameter only.
  2. Or remove the device parameter and keep device inside load_pipeline_args.
  3. Keep exactly one source of truth for device placement.

Example fix

// before
handler = HuggingFacePipelineModelHandler(task='fill-mask', device='GPU', load_pipeline_args={'device': 'cuda:0'})
// after
handler = HuggingFacePipelineModelHandler(task='fill-mask', load_pipeline_args={'device': 'cuda:0'})
Defensive patterns

Strategy: validation

Validate before calling

if device is not None and 'device' in load_pipeline_args:
    raise ValueError('Set device either via parameter or load_pipeline_args, not both')

Type guard

def no_device_conflict(device, load_pipeline_args) -> bool:
    return not (device is not None and 'device' in (load_pipeline_args or {}))

Try / catch

try:
    handler = HuggingFacePipelineModelHandler(task=task, device=device, load_pipeline_args=lp_args)
except ValueError as e:
    if 'load_pipeline_args' in str(e):
        lp_args = {k: v for k, v in lp_args.items() if k != 'device'}
        handler = HuggingFacePipelineModelHandler(task=task, device=device, load_pipeline_args=lp_args)
    else:
        raise

Prevention

When it happens

Trigger: HuggingFacePipelineModelHandler(device='CPU', load_pipeline_args={'device': 'cuda:0'}) — device set in both places.

Common situations: Merging load_pipeline_args from config that already includes device while also passing the explicit device param; copy-pasted examples combining both.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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