2024-01-16 14:38:37 +08:00
|
|
|
# Copyright 2023 OpenSPG Authors
|
2024-01-06 12:12:12 +08:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
|
|
# in compliance with the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
# or implied.
|
|
|
|
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from nn4k.executor import NNExecutor, LLMExecutor
|
|
|
|
from nn4k.nnhub import SimpleNNHub
|
|
|
|
|
|
|
|
|
|
|
|
class StubExecutor(LLMExecutor):
|
|
|
|
def load_model(self, args=None, mode=None, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def warmup_inference(self, args=None, **kwargs):
|
|
|
|
pass
|
|
|
|
|
2024-03-08 13:54:15 +08:00
|
|
|
def inference(self, inputs, args=None, **kwargs):
|
2024-01-06 12:12:12 +08:00
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_config(cls, nn_config: dict) -> "StubExecutor":
|
|
|
|
"""
|
|
|
|
Create a StubExecutor instance from `nn_config`.
|
|
|
|
"""
|
|
|
|
executor = cls(nn_config)
|
|
|
|
return executor
|
|
|
|
|
|
|
|
|
|
|
|
class NotExecutor:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class StubHub(SimpleNNHub):
|
|
|
|
def get_model_executor(
|
|
|
|
self, name: str, version: str = None
|
|
|
|
) -> Optional[NNExecutor]:
|
2024-02-02 16:29:24 +08:00
|
|
|
if name == "executor_test_stub":
|
2024-01-06 12:12:12 +08:00
|
|
|
if version is None:
|
|
|
|
version = "default"
|
|
|
|
executor = StubExecutor(
|
|
|
|
{"nn_name": name, "nn_version": version}, test_stub_executor=True
|
|
|
|
)
|
|
|
|
return executor
|
|
|
|
return super().get_model_executor(name, version)
|