|
| 1 | +# ------------------------------------------------------------------------- |
| 2 | +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | +# -------------------------------------------------------------------------- |
| 5 | + |
| 6 | +import logging |
| 7 | +from typing import Any, Callable, Optional, Union |
| 8 | + |
| 9 | +from olive.constants import Framework, ModelFileFormat |
| 10 | +from olive.hardware.accelerator import Device |
| 11 | +from olive.model.config import IoConfig |
| 12 | +from olive.model.config.registry import model_handler_registry |
| 13 | +from olive.model.handler.base import OliveModelHandler |
| 14 | + |
| 15 | +logger = logging.getLogger(__name__) |
| 16 | + |
| 17 | + |
| 18 | +@model_handler_registry("QairtPreparedModel") |
| 19 | +class QairtPreparedModelHandler(OliveModelHandler): |
| 20 | + json_config_keys: tuple[str, ...] = ("io_config", "model_file_format") |
| 21 | + |
| 22 | + def __init__( |
| 23 | + self, |
| 24 | + model_path: str, |
| 25 | + model_attributes: Optional[dict[str, Any]] = None, |
| 26 | + io_config: Union[dict[str, Any], IoConfig, str, Callable] = None, |
| 27 | + model_file_format: ModelFileFormat = ModelFileFormat.QAIRT_PREPARED, |
| 28 | + ): |
| 29 | + super().__init__( |
| 30 | + framework=Framework.QAIRT, |
| 31 | + model_file_format=model_file_format, |
| 32 | + model_path=model_path, |
| 33 | + model_attributes=model_attributes, |
| 34 | + io_config=io_config, |
| 35 | + ) |
| 36 | + |
| 37 | + @property |
| 38 | + def size_on_disk(self) -> int: |
| 39 | + """Compute size of the model on disk.""" |
| 40 | + return 0 |
| 41 | + |
| 42 | + def load_model(self, rank: int = None, cache_model: bool = True): |
| 43 | + raise NotImplementedError("QairtPreparedModelHandler does not support load_model") |
| 44 | + |
| 45 | + def prepare_session( |
| 46 | + self, |
| 47 | + inference_settings: Union[dict[str, Any], None] = None, |
| 48 | + device: Device = Device.CPU, |
| 49 | + execution_providers: Union[str, list[str]] = None, |
| 50 | + rank: Union[int, None] = None, |
| 51 | + ): |
| 52 | + raise NotImplementedError("QairtPreparedModelHandler does not support prepare_session") |
| 53 | + |
| 54 | + def run_session( |
| 55 | + self, |
| 56 | + session: Any = None, |
| 57 | + inputs: Union[dict[str, Any], list[Any], tuple[Any, ...]] = None, |
| 58 | + **kwargs: dict[str, Any], |
| 59 | + ) -> Any: |
| 60 | + raise NotImplementedError("QairtPreparedModelHandler does not support prepare_session") |
| 61 | + |
| 62 | + |
| 63 | +@model_handler_registry("QairtModel") |
| 64 | +class QairtModelHandler(OliveModelHandler): |
| 65 | + json_config_keys: tuple[str, ...] = ("io_config", "model_file_format") |
| 66 | + |
| 67 | + def __init__( |
| 68 | + self, |
| 69 | + model_path: str, |
| 70 | + model_attributes: Optional[dict[str, Any]] = None, |
| 71 | + io_config: Union[dict[str, Any], IoConfig, str, Callable] = None, |
| 72 | + model_file_format: ModelFileFormat = ModelFileFormat.QAIRT, |
| 73 | + ): |
| 74 | + super().__init__( |
| 75 | + framework=Framework.QAIRT, |
| 76 | + model_file_format=model_file_format, |
| 77 | + model_path=model_path, |
| 78 | + model_attributes=model_attributes, |
| 79 | + io_config=io_config, |
| 80 | + ) |
| 81 | + |
| 82 | + @property |
| 83 | + def size_on_disk(self) -> int: |
| 84 | + """Compute size of the model on disk.""" |
| 85 | + return 0 |
| 86 | + |
| 87 | + def load_model(self, rank: int = None, cache_model: bool = True): |
| 88 | + raise NotImplementedError("QairtModelHandler does not support load_model") |
| 89 | + |
| 90 | + def prepare_session( |
| 91 | + self, |
| 92 | + inference_settings: Union[dict[str, Any], None] = None, |
| 93 | + device: Device = Device.CPU, |
| 94 | + execution_providers: Union[str, list[str]] = None, |
| 95 | + rank: Union[int, None] = None, |
| 96 | + ): |
| 97 | + raise NotImplementedError("QairtModelHandler does not support prepare_session") |
| 98 | + |
| 99 | + def run_session( |
| 100 | + self, |
| 101 | + session: Any = None, |
| 102 | + inputs: Union[dict[str, Any], list[Any], tuple[Any, ...]] = None, |
| 103 | + **kwargs: dict[str, Any], |
| 104 | + ) -> Any: |
| 105 | + raise NotImplementedError("QairtModelHandler does not support prepare_session") |
0 commit comments