File tree Expand file tree Collapse file tree 2 files changed +13
-13
lines changed
swift/llm/infer/infer_engine Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,11 @@ async def _run_async_iter():
7272 else :
7373 queue .put (None )
7474
75- loop = asyncio .new_event_loop ()
75+ try :
76+ loop = asyncio .get_event_loop ()
77+ except RuntimeError :
78+ loop = asyncio .new_event_loop ()
79+ asyncio .set_event_loop (loop )
7680 thread = Thread (target = lambda : loop .run_until_complete (_run_async_iter ()))
7781 thread .start ()
7882 pre_output = None
@@ -81,7 +85,6 @@ async def _run_async_iter():
8185 if output is None or isinstance (output , Exception ):
8286 prog_bar .update ()
8387 self ._update_metrics (pre_output , metrics )
84- loop .close ()
8588 return
8689 pre_output = output
8790 yield output
Original file line number Diff line number Diff line change @@ -90,18 +90,15 @@ def _load_generation_config(self) -> None:
9090 generation_config_path = os .path .join (self .model_dir , 'generation_config.json' )
9191 if os .path .isfile (generation_config_path ):
9292 generation_config = GenerationConfig .from_pretrained (self .model_dir )
93- kwargs = generation_config .to_dict ()
94- top_k = kwargs .get ('top_k' )
95- if top_k == 0 :
96- kwargs ['top_k' ] = - 1
97-
98- parameters = inspect .signature (SamplingParams ).parameters
99- for k , v in kwargs .copy ().items ():
100- if k not in parameters or v is None :
101- kwargs .pop (k )
102- self .generation_config = kwargs
10393 else :
104- self .generation_config = {}
94+ generation_config = GenerationConfig ()
95+ kwargs = generation_config .to_dict ()
96+ top_k = kwargs .get ('top_k' )
97+ if top_k == 0 :
98+ kwargs ['top_k' ] = - 1
99+
100+ parameters = inspect .signature (SamplingParams ).parameters
101+ self .generation_config = {k : v for k , v in kwargs .items () if k in parameters and v is not None }
105102
106103 def _prepare_generation_config (self , request_config : RequestConfig ) -> Dict [str , Any ]:
107104 kwargs = {'max_new_tokens' : request_config .max_tokens }
You can’t perform that action at this time.
0 commit comments