Skip to content

Commit

Permalink
Extend inference engine dtype validation
Browse files Browse the repository at this point in the history
- to allow running inference tasks using bfloat16
- also generalize dtype checking
  • Loading branch information
nelyahu committed Sep 15, 2024
1 parent 170b46e commit ed35e07
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions deepspeed/inference/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def __init__(self, model, config):
if hasattr(self.module, "config"):
TransformerPolicy.hf_model_config = self.module.config

if config.dtype == torch.half and not get_accelerator().is_fp16_supported():
raise ValueError("Type fp16 is not supported.")
if config.dtype not in get_accelerator().is_fp16_supported():
raise ValueError(f"Data type {config} is not supported by {get_accelerator().device_name()} accelerator")

# todo: keep this self.injection_dict because we don't use to change config.injection_policy API
# todo: this will get changed when Molly's PR on auto injection dict is merged
Expand Down Expand Up @@ -324,7 +324,7 @@ def _validate_args(self, mpu, replace_with_kernel_inject):
if self._config.checkpoint is not None and not isinstance(self._config.checkpoint, (str, dict)):
raise ValueError(f"checkpoint must be None, str or dict, got {type(self._config.checkpoint)}")

supported_dtypes = [None, torch.half, torch.int8, torch.float]
supported_dtypes = [None, torch.half, torch.int8, torch.float, torch.bfloat16]
if self._config.dtype not in supported_dtypes:
raise ValueError(f"{self._config.dtype} not supported, valid dtype: {supported_dtypes}")

Expand Down

0 comments on commit ed35e07

Please sign in to comment.