4
4
from jsonschema import validate
5
5
6
6
from lmdeploy import pipeline
7
- from lmdeploy .messages import GenerationConfig , TurbomindEngineConfig
7
+ from lmdeploy .messages import GenerationConfig , PytorchEngineConfig , TurbomindEngineConfig
8
8
9
+ MODEL_IDS = [
10
+ 'Qwen/Qwen3-0.6B' ,
11
+ 'OpenGVLab/InternVL3_5-1B' ,
12
+ ]
9
13
10
- @pytest .fixture (scope = 'module' )
11
- def tiny_model_id ():
12
- return 'internlm/internlm2_5-1_8b'
14
+ BACKEND_FACTORIES = [
15
+ ('tm' , lambda : TurbomindEngineConfig (max_batch_size = 2 , session_len = 1024 )),
16
+ ('pt' , lambda : PytorchEngineConfig (max_batch_size = 1 , session_len = 1024 )),
17
+ ]
13
18
14
-
15
- @pytest .fixture (scope = 'module' )
16
- def tmp_workspace (tmp_path_factory ):
17
- return tmp_path_factory .mktemp ('tm_workspace' )
18
-
19
-
20
- guide = {
19
+ GUIDE_SCHEMA = {
21
20
'type' : 'object' ,
22
21
'properties' : {
23
22
'name' : {
@@ -29,7 +28,8 @@ def tmp_workspace(tmp_path_factory):
29
28
'type' : 'string' ,
30
29
'maxLength' : 10
31
30
},
32
- 'minItems' : 3
31
+ 'minItems' : 3 ,
32
+ 'maxItems' : 10 ,
33
33
},
34
34
'work history' : {
35
35
'type' : 'array' ,
@@ -41,20 +41,39 @@ def tmp_workspace(tmp_path_factory):
41
41
},
42
42
'duration' : {
43
43
'type' : 'string'
44
- }
44
+ },
45
45
},
46
- 'required' : ['company' ]
47
- }
48
- }
46
+ 'required' : ['company' ],
47
+ },
48
+ },
49
49
},
50
- 'required' : ['name' , 'skills' , 'work history' ]
50
+ 'required' : ['name' , 'skills' , 'work history' ],
51
51
}
52
52
53
53
54
- def test_tm_guided_pipeline (tiny_model_id ):
55
- pipe = pipeline (tiny_model_id ,
56
- backend_config = TurbomindEngineConfig (max_batch_size = 1 , session_len = 1024 ),
57
- log_level = 'INFO' )
58
- gen_config = GenerationConfig (response_format = dict (type = 'json_schema' , json_schema = dict (name = 'test' , schema = guide )))
59
- response = pipe (['Make a self introduction please.' ], gen_config = gen_config )
60
- validate (instance = json .loads (response [0 ].text ), schema = guide )
54
+ @pytest .mark .parametrize ('model_id' , MODEL_IDS )
55
+ @pytest .mark .parametrize ('backend_name,backend_factory' , BACKEND_FACTORIES )
56
+ @pytest .mark .parametrize ('enable_guide' , [True , False ])
57
+ def test_guided_matrix (model_id , backend_name , backend_factory , enable_guide ):
58
+ pipe = pipeline (
59
+ model_id ,
60
+ backend_config = backend_factory (),
61
+ log_level = 'INFO' ,
62
+ )
63
+
64
+ try :
65
+ if enable_guide :
66
+ gen_config = GenerationConfig (response_format = dict (
67
+ type = 'json_schema' ,
68
+ json_schema = dict (name = 'test' , schema = GUIDE_SCHEMA ),
69
+ ), )
70
+ else :
71
+ gen_config = GenerationConfig ()
72
+
73
+ response = pipe (['Make a self introduction please.' ] * 3 , gen_config = gen_config )
74
+ assert response and response [0 ].text
75
+
76
+ if enable_guide :
77
+ validate (instance = json .loads (response [0 ].text ), schema = GUIDE_SCHEMA )
78
+ finally :
79
+ pipe .close ()
0 commit comments