Skip to content

Commit

Permalink
fix OVModelForCausalLM for auto device
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova committed Sep 20, 2023
1 parent 4b8ed24 commit 4985d1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion optimum/intel/openvino/modeling_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def update_pkv_precision(self, force_fp32=False):
pkv_precision = Type.f32
if not force_fp32:
device = self._device.upper()
pkv_precision = core.get_property(device, "INFERENCE_PRECISION_HINT")
if "INFERENCE_PRECISION_HINT" in core.get_property(device, "SUPPORTED_PROPERTIES"):
pkv_precision = core.get_property(device, "INFERENCE_PRECISION_HINT")
# ov_config["INFERENCE_PRECISION_HINT"] may override the prefer precision
if self.ov_config:
inference_precision_hint = self.ov_config.get("INFERENCE_PRECISION_HINT", "")
Expand Down
8 changes: 8 additions & 0 deletions tests/openvino/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,14 @@ def test_compare_with_and_without_past_key_values(self):
del model_without_pkv
gc.collect()

def test_auto_device_loading(self):
model_id = MODEL_NAMES["gpt2"]
model = OVModelForCausalLM.from_pretrained(model_id, export=True, use_cache=True, device="AUTO")
model.half()
self.assertEqual(model._device, "AUTO")
del model
gc.collect()


class OVModelForMaskedLMIntegrationTest(unittest.TestCase):
SUPPORTED_ARCHITECTURES = (
Expand Down

0 comments on commit 4985d1c

Please sign in to comment.