mirror of
https://github.com/OpenSPG/openspg.git
synced 2025-09-25 16:30:21 +00:00
init nn4k module
(cherry picked from commit ec6c8e6f5e561aae04f49ef8340db203cb8e50e8)
This commit is contained in:
parent
995dfab7f6
commit
425285ad79
0
python/NN4K/__init__.py
Normal file
0
python/NN4K/__init__.py
Normal file
0
python/NN4K/executor/__init__.py
Normal file
0
python/NN4K/executor/__init__.py
Normal file
54
python/NN4K/executor/base.py
Normal file
54
python/NN4K/executor/base.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class ModelExecutor(ABC):
|
||||||
|
"""
|
||||||
|
对应xflow AntLLM
|
||||||
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_config(cls,
|
||||||
|
args='sys',
|
||||||
|
**kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
backend_model,
|
||||||
|
backend_tokenizer,
|
||||||
|
init_args,
|
||||||
|
**kwargs):
|
||||||
|
self.backend_model = backend_model
|
||||||
|
self.backend_tokenizer = backend_tokenizer
|
||||||
|
self.init_args = init_args
|
||||||
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
|
||||||
|
class LLMExecutor(ModelExecutor):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def sft_train(self, args=None, callbacks=None, **kwargs):
|
||||||
|
raise NotImplementedError("")
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def rl_tuning(self, args=None, callbacks=None, **kwargs):
|
||||||
|
raise NotImplementedError("")
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def batch_inference(self, args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def inference(self, input, inference_args, **kwargs):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
|
class HfLLMExecutor(ModelExecutor):
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DeepKEExecutor(ModelExecutor):
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
0
python/NN4K/executor/deepke/__init__.py
Normal file
0
python/NN4K/executor/deepke/__init__.py
Normal file
0
python/NN4K/executor/hugging_face/__init__.py
Normal file
0
python/NN4K/executor/hugging_face/__init__.py
Normal file
0
python/NN4K/invoker/__init__.py
Normal file
0
python/NN4K/invoker/__init__.py
Normal file
50
python/NN4K/invoker/base.py
Normal file
50
python/NN4K/invoker/base.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
# Copyright (c) Antfin, Inc. All rights reserved.
|
||||||
|
import sys
|
||||||
|
from abc import ABC
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ModelInvoker(ABC):
|
||||||
|
"""
|
||||||
|
对应 xflow ModelHubEntry
|
||||||
|
"""
|
||||||
|
|
||||||
|
def submit_sft(self, submit_mode='k8s'):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def submit_rl_tuning(self, submit_mode='k8s'):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def deploy(cls, args, deploy_mode='k8s'):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def inference(self, input, **kwargs):
|
||||||
|
"""
|
||||||
|
这个是从已有的服务中获取inference
|
||||||
|
Args:
|
||||||
|
args:
|
||||||
|
**kwargs:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_config(cls, args='sys'):
|
||||||
|
return cls()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class OpenAI(ModelInvoker):
|
||||||
|
|
||||||
|
def __init__(self, token):
|
||||||
|
self.token = token
|
||||||
|
pass
|
||||||
|
|
||||||
|
def inference(self, input, **kwargs):
|
||||||
|
import requests
|
||||||
|
requests.post(url="https://api.openai.com", params={"input": input, "token": self.token})
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user