damccorm commented on code in PR #29223:
URL: https://github.com/apache/beam/pull/29223#discussion_r1378826347
##########
sdks/python/apache_beam/ml/inference/huggingface_inference.py:
##########
@@ -638,8 +640,30 @@ def __init__(
if max_batch_size is not None:
self._batching_kwargs['max_batch_size'] = max_batch_size
self._large_model = large_model
+
+ # Check if the device is specified twice. If true then the device parameter
+ # of model handler is overridden.
+ self._deduplicate_device_value(device)
_validate_constructor_args_hf_pipeline(self._task, self._model)
+ def _deduplicate_device_value(self, device: str):
+ if 'device' not in self._load_pipeline_args:
+ if device == 'CPU':
+ self._load_pipeline_args['device'] = 'cpu'
+ else:
+ if is_gpu_available_torch():
+ self._load_pipeline_args['device'] = 'cuda:1'
+ else:
+ _LOGGER.warning(
+ "HuggingFaceModelHandler specified a 'GPU' device, "
+ "but GPUs are not available. Switching to CPU.")
+ self._load_pipeline_args['device'] = 'cpu'
+ else:
+ if device:
Review Comment:
Since `device` has a default value, this will always trigger. I think we
should change `device`'s default value to `device: Optional[str] = None`
##########
sdks/python/apache_beam/ml/inference/huggingface_inference.py:
##########
@@ -638,8 +640,30 @@ def __init__(
if max_batch_size is not None:
self._batching_kwargs['max_batch_size'] = max_batch_size
self._large_model = large_model
+
+ # Check if the device is specified twice. If true then the device parameter
+ # of model handler is overridden.
+ self._deduplicate_device_value(device)
_validate_constructor_args_hf_pipeline(self._task, self._model)
+ def _deduplicate_device_value(self, device: str):
Review Comment:
Would be good to throw if device != CPU or GPU here as well. Also would be
good to convert to uppercase if device is not None
##########
sdks/python/apache_beam/ml/inference/huggingface_inference.py:
##########
@@ -606,6 +603,11 @@ def __init__(
task="text-generation", model="meta-llama/Llama-2-7b-hf",
load_pipeline_args={'model_kwargs':{'quantization_map':config}})
+ device (str): the device on which you wish to run the pipeline. Defaults
Review Comment:
```suggestion
device (str): the device (CPU or GPU) on which you wish to run the
pipeline. Defaults
```
Note: applying this will break the format checker, so you should still
probably do it locally
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]