From 1de1eb49492945f836cdaa7b39feeeefb57fc5ac Mon Sep 17 00:00:00 2001 From: maofagui Date: Wed, 10 Jan 2024 18:44:40 +0800 Subject: [PATCH 1/2] [feat]Add align-executor/invoker API. --- python/nn4k/nn4k/executor/base.py | 30 ++++++++++++++++++--- python/nn4k/nn4k/invoker/base.py | 43 +++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/python/nn4k/nn4k/executor/base.py b/python/nn4k/nn4k/executor/base.py index 4d5279b5b..0127bb7a2 100644 --- a/python/nn4k/nn4k/executor/base.py +++ b/python/nn4k/nn4k/executor/base.py @@ -152,10 +152,34 @@ def execute_sft(self, args=None, callbacks=None, **kwargs): """ raise NotImplementedError(f"{self.__class__.__name__} does not support SFT.") - def execute_rl_tuning(self, args=None, callbacks=None, **kwargs): + +class AlignExecutor(LLMExecutor): + """An executor for X-Alignment""" + + @classmethod + def from_config(cls, nn_config: Union[str, dict]) -> "NNExecutor": + return super().from_config(nn_config) + + def execute_rm(self, args=None, callbacks=None, **kwargs): """ - The entry point of SFT execution in a certain pod. + Execute reward model(rm) training. + """ + raise NotImplementedError( + f"{self.__class__.__name__} does not support execute_rm yet." + ) + + def execute_dpo(self, args=None, callbacks=None, **kwargs): + """ + Execute DPO training. + """ + raise NotImplementedError( + f"{self.__class__.__name__} does not support execute_dpo yet." + ) + + def execute_ppo(self, args=None, callbacks=None, **kwargs): + """ + Execute PPO training. """ raise NotImplementedError( - f"{self.__class__.__name__} does not support RL-Tuning." + f"{self.__class__.__name__} does not support execute_ppo yet." ) diff --git a/python/nn4k/nn4k/invoker/base.py b/python/nn4k/nn4k/invoker/base.py index 4cd08d9b7..8db15232a 100644 --- a/python/nn4k/nn4k/invoker/base.py +++ b/python/nn4k/nn4k/invoker/base.py @@ -138,14 +138,6 @@ def submit_sft(self, submit_mode: SubmitMode = SubmitMode.K8s): """ raise NotImplementedError(f"{self.__class__.__name__} does not support SFT.") - def submit_rl_tuning(self, submit_mode: SubmitMode = SubmitMode.K8s): - """ - Submit remote RL-Tuning execution. - """ - raise NotImplementedError( - f"{self.__class__.__name__} does not support RL-Tuning." - ) - def local_inference(self, data, **kwargs): """ Implement local inference for local invoker. @@ -184,3 +176,38 @@ def from_config(cls, nn_config: dict) -> "LLMInvoker": """ invoker = cls(nn_config) return invoker + + +class AlignInvoker(NNInvoker): + """A invoker for X-Alignment tuning""" + @classmethod + def from_config(cls, nn_config: Union[str, dict]) -> "NNInvoker": + """ + Create an instance from `nn_config`. + """ + invoker = cls(nn_config) + return invoker + + def submit_rm(self, submit_mode: SubmitMode = SubmitMode.K8s): + """ + Submit remote tuning execution for reward model(rm). + """ + raise NotImplementedError( + f"{self.__class__.__name__} does not support submit_rm yet." + ) + + def submit_dpo(self, submit_mode: SubmitMode = SubmitMode.K8s): + """ + Submit remote execution for DPO. + """ + raise NotImplementedError( + f"{self.__class__.__name__} does not support submit_dpo yet." + ) + + def submit_ppo(self, submit_mode: SubmitMode = SubmitMode.K8s): + """ + Submit remote execution for PPO. + """ + raise NotImplementedError( + f"{self.__class__.__name__} does not support submit_ppo yet." + ) From 4e9eacd1fb38dd50dbbbfc5c9bcb66974ef5ea42 Mon Sep 17 00:00:00 2001 From: maofagui Date: Tue, 3 Jun 2025 20:07:31 +0800 Subject: [PATCH 2/2] test --- README_cn.md | 2 ++ python/nn4k/nn4k/invoker/base.py | 1 + 2 files changed, 3 insertions(+) diff --git a/README_cn.md b/README_cn.md index e82091f55..912c3084a 100644 --- a/README_cn.md +++ b/README_cn.md @@ -58,6 +58,8 @@ OpenSPG核心能力模型包括: # Cite +None + # License [Apache License 2.0](LICENSE) diff --git a/python/nn4k/nn4k/invoker/base.py b/python/nn4k/nn4k/invoker/base.py index 8db15232a..cf7ba9008 100644 --- a/python/nn4k/nn4k/invoker/base.py +++ b/python/nn4k/nn4k/invoker/base.py @@ -17,6 +17,7 @@ class SubmitMode(Enum): + Local = "local" K8s = "k8s" Docker = "docker"