From 3be037bf8b2b1682cd9457c83318c42f53fc13f0 Mon Sep 17 00:00:00 2001 From: wangjian Date: Thu, 8 Aug 2024 20:45:41 +0800 Subject: [PATCH 1/4] add lazyllm before group --- README.CN.md | 4 ++-- README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.CN.md b/README.CN.md index 8942563c..6aca225d 100644 --- a/README.CN.md +++ b/README.CN.md @@ -269,9 +269,9 @@ def test(input): def test_cmd(input): return f'echo input is {input}' -# >>> demo.test()(1) +# >>> lazyllm.demo.test()(1) # 'input is 1' -# >>> demo.test_cmd(launcher=launchers.slurm)(2) +# >>> lazyllm.demo.test_cmd(launcher=launchers.slurm)(2) # Command: srun -p pat_rd -N 1 --job-name=xf488db3 -n1 bash -c 'echo input is 2' ``` diff --git a/README.md b/README.md index 57dbd723..34533877 100644 --- a/README.md +++ b/README.md @@ -276,9 +276,9 @@ def test(input): def test_cmd(input): return f'echo input is {input}' -# >>> demo.test()(1) +# >>> lazyllm.demo.test()(1) # 'input is 1' -# >>> demo.test_cmd(launcher=launchers.slurm)(2) +# >>> lazyllm.demo.test_cmd(launcher=launchers.slurm)(2) # Command: srun -p pat_rd -N 1 --job-name=xf488db3 -n1 bash -c 'echo input is 2' ``` From 7bcf7c19641196af576d151832365dd097f724d0 Mon Sep 17 00:00:00 2001 From: wangjian Date: Wed, 4 Sep 2024 19:11:08 +0800 Subject: [PATCH 2/4] modify trainable function call unit test process --- .../standard_test/test_trainable_fc.py | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/tests/advanced_tests/standard_test/test_trainable_fc.py b/tests/advanced_tests/standard_test/test_trainable_fc.py index e95ee9db..7873073f 100644 --- a/tests/advanced_tests/standard_test/test_trainable_fc.py +++ b/tests/advanced_tests/standard_test/test_trainable_fc.py @@ -119,92 +119,90 @@ def LLMWorker(input: str): @pytest.fixture() def exe_trainable_single_function_call(request): params = request.param if hasattr(request, 'param') else {} - model = params.get('model', None) tools = params.get("tools", []) query = params.get("query", "") + llm = request.cls.llm if not query or not tools: raise ValueError(f"query: {query} and {tools} cannot be empty.") - llm = lazyllm.TrainableModule(model).deploy_method(deploy.vllm).start() - print(f"\nStarting test 【{model}】 function calling") + print(f"\nStarting test 【{llm}】 function calling") fc = FunctionCall(llm, tools) ret = fc(query) yield ret - print(f"\n【{model}】 function calling test done.") + print(f"\n【{llm}】 function calling test done.") @pytest.fixture() def exe_trainable_parallel_function_call(request): params = request.param if hasattr(request, 'param') else {} - model = params.get('model', None) tools = params.get("tools", []) query = params.get("query", "") + llm = request.cls.llm if not query or not tools: raise ValueError(f"query: {query} and tools: {tools} cannot be empty.") - llm = lazyllm.TrainableModule(model).deploy_method(deploy.vllm).start() agent = FunctionCallAgent(llm, tools) - print(f"\nStarting test 【{model}】parallel function calling") + print(f"\nStarting test 【{llm}】parallel function calling") ret = agent(query) yield ret - print(f"\n【{model}】parallel function calling test done.") + print(f"\n【{llm}】parallel function calling test done.") @pytest.fixture() def exe_trainable_advance_agent(request): params = request.param if hasattr(request, 'param') else {} - model = params.get('model', None) tools = params.get('tools', []) query = params.get('query', '') Agent = params.get('Agent', None) + llm = request.cls.llm if not query or not tools: raise ValueError(f"query: {query} and tools: {tools} cannot be empty.") if Agent is None: raise ValueError(f"Agent: {Agent} must be a valid value.") - llm = lazyllm.TrainableModule(model).deploy_method(deploy.vllm).start() agent = Agent(llm, tools) - print(f"\nStarting test 【{model}】 {Agent}.") + print(f"\nStarting test 【{llm}】 {Agent}.") ret = agent(query) yield ret - print(f"\n【{model}】 {Agent} test done.") + print(f"\n【{llm}】 {Agent} test done.") tools = ["get_current_weather", "get_n_day_weather_forecast"] squery1 = "What's the weather like today in celsius in Tokyo." squery2 = "What will the weather be like in celsius in Paris tomorrow?" mquery1 = "What's the weather like today in celsius in Tokyo and Paris." mquery2 = "What will the weather be like in fahrenheit in san francisco and beijing tomorrow?" -vModels = ['glm-4-9b-chat', 'qwen2-7b-instruct'] -agentQuery = "What is 20+(2*4)? Calculate step by step." -rewooquery = "What is the name of the cognac house that makes the main ingredient in The Hennchata?" +agentQuery = "计算 20*(45+23)*4, Calculate step by step." +rewooquery = "截止到当前美国历届总统就职时年龄最大的是谁" class TestTrainableFunctionCall(object): - @pytest.fixture(autouse=True) - def run_around_tests(self): - yield + @classmethod + def setup_class(cls): + models = ["internlm2-chat-20b", "glm-4-9b-chat", "qwen2-7b-instruct", "qwen2-72b-instruct-awq"] + model = random.choice(models) + cls.llm = lazyllm.TrainableModule(model).deploy_method(deploy.vllm).start() + + @classmethod + def teardown_class(cls): cleanup() @pytest.mark.parametrize("exe_trainable_single_function_call", - [{"model": random.choice(vModels), "tools": tools, "query": squery1}, - {"model": random.choice(vModels), "tools": tools, "query": squery2}], + [{"tools": tools, "query": squery1}, + {"tools": tools, "query": squery2}], indirect=True) def test_trainable_single_function_call(self, exe_trainable_single_function_call): ret = exe_trainable_single_function_call assert isinstance(ret, list) @pytest.mark.parametrize("exe_trainable_parallel_function_call", - [{"model": random.choice(vModels), 'tools': tools, 'query': mquery1}, - {"model": random.choice(vModels), 'tools': tools, 'query': mquery2}], + [{'tools': tools, 'query': mquery1}, + {'tools': tools, 'query': mquery2}], indirect=True) def test_trainable_parallel_function_call(self, exe_trainable_parallel_function_call): ret = exe_trainable_parallel_function_call assert isinstance(ret, str) @pytest.mark.parametrize("exe_trainable_advance_agent", - [{"model": random.choice(['internlm2-chat-20b', 'Qwen1.5-14B-Chat']), - 'tools': ['multiply_tool', 'add_tool'], 'query': agentQuery, "Agent": ReactAgent}, - {"model": random.choice(['internlm2-chat-20b', 'Qwen1.5-14B-Chat']), - 'tools': ['multiply_tool', 'add_tool'], 'query': agentQuery, "Agent": PlanAndSolveAgent}, - {"model": random.choice(['GLM-4-9B-Chat', 'Qwen2-72B-Instruct-AWQ']), - 'tools': ['WikipediaWorker', 'LLMWorker'], 'query': rewooquery, "Agent": ReWOOAgent}], + [{'tools': ['multiply_tool', 'add_tool'], 'query': agentQuery, "Agent": ReactAgent}, + {'tools': ['multiply_tool', 'add_tool'], 'query': agentQuery, "Agent": PlanAndSolveAgent}, + {'tools': ['WikipediaWorker', 'LLMWorker'], 'query': rewooquery, "Agent": ReWOOAgent}], indirect=True) def test_trainable_advance_agent(self, exe_trainable_advance_agent): ret = exe_trainable_advance_agent From e5bf29fc4d5fa3ab8729c67dcde102796a2d13ac Mon Sep 17 00:00:00 2001 From: wangjian Date: Thu, 5 Sep 2024 10:38:50 +0800 Subject: [PATCH 3/4] optimizing Trainable model usage in unittests --- .../standard_test/test_intent_classifier.py | 10 ++++++++-- .../standard_test/test_llm_parser.py | 20 +++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/advanced_tests/standard_test/test_intent_classifier.py b/tests/advanced_tests/standard_test/test_intent_classifier.py index 80373ab0..adcd4f0b 100644 --- a/tests/advanced_tests/standard_test/test_intent_classifier.py +++ b/tests/advanced_tests/standard_test/test_intent_classifier.py @@ -1,10 +1,16 @@ from lazyllm.tools import IntentClassifier import lazyllm +from lazyllm.launcher import cleanup class TestIntentClassifier(object): - def setup_method(self): - self._llm = lazyllm.TrainableModule('internlm2-chat-7b') + @classmethod + def setup_class(cls): + cls._llm = lazyllm.TrainableModule('internlm2-chat-7b') + + @classmethod + def teardown_class(cls): + cleanup() def test_intent_classifier(self): intent_list = ["Chat", "Financial Knowledge Q&A", "Employee Information Query", "Weather Query"] diff --git a/tests/advanced_tests/standard_test/test_llm_parser.py b/tests/advanced_tests/standard_test/test_llm_parser.py index cadd9e12..c1ee4f6a 100644 --- a/tests/advanced_tests/standard_test/test_llm_parser.py +++ b/tests/advanced_tests/standard_test/test_llm_parser.py @@ -1,21 +1,25 @@ import unittest from unittest.mock import MagicMock from lazyllm import LLMParser, TrainableModule +from lazyllm.launcher import cleanup class TestLLMParser(unittest.TestCase): - def setUp(self): - self.llm = TrainableModule("internlm2-chat-7b") - self.llm.start() - - self.mock_node = MagicMock() - self.mock_node.get_text.return_value = ( + @classmethod + def setup_class(cls): + cls.llm = TrainableModule("internlm2-chat-7b").start() + cls.mock_node = MagicMock() + cls.mock_node.get_text.return_value = ( "Hello, I am an AI robot developed by SenseTime, named LazyLLM. " "My mission is to assist you in building the most powerful large-scale model applications with minimal cost." ) - self.summary_parser = LLMParser(self.llm, language="en", task_type="summary") - self.keywords_parser = LLMParser(self.llm, language="en", task_type="keywords") + cls.summary_parser = LLMParser(cls.llm, language="en", task_type="summary") + cls.keywords_parser = LLMParser(cls.llm, language="en", task_type="keywords") + + @classmethod + def teardown_class(cls): + cleanup() def test_summary_transform(self): result = self.summary_parser.transform(self.mock_node) From 7bcd9d012f9c715fe5a138d3e1e28dec22b3469a Mon Sep 17 00:00:00 2001 From: wangjian Date: Thu, 5 Sep 2024 13:40:07 +0800 Subject: [PATCH 4/4] modify rewoo agent query --- tests/advanced_tests/standard_test/test_trainable_fc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/advanced_tests/standard_test/test_trainable_fc.py b/tests/advanced_tests/standard_test/test_trainable_fc.py index 7873073f..97e6f0d7 100644 --- a/tests/advanced_tests/standard_test/test_trainable_fc.py +++ b/tests/advanced_tests/standard_test/test_trainable_fc.py @@ -170,7 +170,7 @@ def exe_trainable_advance_agent(request): mquery1 = "What's the weather like today in celsius in Tokyo and Paris." mquery2 = "What will the weather be like in fahrenheit in san francisco and beijing tomorrow?" agentQuery = "计算 20*(45+23)*4, Calculate step by step." -rewooquery = "截止到当前美国历届总统就职时年龄最大的是谁" +rewooquery = "美国历届总统就职时年龄最大的是谁" class TestTrainableFunctionCall(object): @classmethod