def get_metrics(self) -> List[Dict[str, Any]]: """Get list of possible metrics.""" framework = self.config.get("framework", None) if framework is None: raise ClientErrorException("Framework not set.") if framework == "pytorch": check_module("ignite") else: check_module(framework) help_dict = load_help_lpot_params("metrics") key_in_framework_metrics = "onnxrt_qlinearops" if framework == "onnxrt" else framework metrics_class = framework_metrics.get(key_in_framework_metrics) raw_metric_list = list( metrics_class().metrics.keys()) if metrics_class else [] raw_metric_list += ["custom"] metrics_updated = _update_metric_parameters(raw_metric_list) for metric, value in metrics_updated.copy().items(): if isinstance(value, dict): for key in value.copy().keys(): help_msg_key = f"__help__{key}" metrics_updated[metric][help_msg_key] = help_dict.get( metric, {}, ).get(help_msg_key, "") metrics_updated[f"__help__{metric}"] = help_dict.get( f"__help__{metric}", "", ) return self._parse_help_in_dict(metrics_updated)
def get_strategies() -> List[Dict[str, Any]]: """Get list of supported strategies.""" check_module("lpot") from lpot.strategy import STRATEGIES help_dict = load_help_lpot_params("strategies") strategies = [] for strategy in STRATEGIES.keys(): help_msg = help_dict.get(f"__help__{strategy}", "") strategies.append({"name": strategy, "help": help_msg}) return strategies
def get_objectives() -> List[dict]: """Get list of supported objectives.""" check_module("lpot") from lpot.objective import OBJECTIVES help_dict = load_help_lpot_params("objectives") objectives = [] for objective in OBJECTIVES.keys(): help_msg = help_dict.get(f"__help__{objective}", "") objectives.append({"name": objective, "help": help_msg}) return objectives
def get_boundary_nodes(data: Dict[str, Any]) -> None: """Get configuration.""" from lpot.ux.utils.utils import find_boundary_nodes request_id = str(data.get("id", "")) model_path = data.get("model_path", None) if not (request_id and model_path): message = "Missing model path or request id." mq.post_error( "boundary_nodes_finish", {"message": message, "code": 404, "id": request_id}, ) return try: mq.post_success( "boundary_nodes_start", {"message": "started", "id": request_id}, ) model_repository = ModelRepository() try: model = model_repository.get_model(model_path) except NotFoundException: supported_frameworks = model_repository.get_frameworks() raise ClientErrorException( f"Framework for specified model is not yet supported. " f"Supported frameworks are: {', '.join(supported_frameworks)}.", ) framework = model.get_framework_name() try: check_module(framework) except ClientErrorException: raise ClientErrorException( f"Detected {framework} model. " f"Could not find installed {framework} module. " f"Please install {framework}.", ) framework_version = get_module_version(framework) response_data = find_boundary_nodes(model_path) response_data["id"] = request_id response_data["framework"] = framework response_data["framework_version"] = framework_version except ClientErrorException as err: mq.post_error( "boundary_nodes_finish", {"message": str(err), "code": 404, "id": request_id}, ) return log.debug(f"Parsed data is {json.dumps(response_data)}") mq.post_success("boundary_nodes_finish", response_data)
def guard_requirements_installed(self) -> None: """Ensure all requirements are installed.""" super().guard_requirements_installed() tensorflow_version = get_module_version("tensorflow") if not tensorflow_version.startswith("1."): raise ClientErrorException( "TensorFlow slim models work only with TensorFlow 1.x. " f"Currently installed version is {tensorflow_version}. " "Please install TensorFlow 1.x to tune selected model.", ) check_module("tf_slim")
def test_check_non_existing_module(self) -> None: """Test checking non existing module.""" with self.assertRaises(ClientErrorException): check_module("non_existing_module")
def test_check_module(self) -> None: """Test checking existing module.""" check_module("os")
def guard_requirements_installed(self) -> None: """Ensure all requirements are installed.""" check_module("onnx") check_module("onnxruntime")
def guard_requirements_installed(self) -> None: """Ensure all requirements are installed.""" check_module("tensorflow")