Skip to content

Commit 3e6898a

Browse files
committed
重构 Qwen2LM 输出处理逻辑,以改进token处理逻辑
1 parent f08872a commit 3e6898a

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

cosyvoice/llm/llm.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,22 +496,24 @@ def inference_wrapper(self, lm_input, sampling, min_len, max_len, uuid):
496496
self.vllm_output_queue[uuid] = queue.Queue()
497497
out_tokens = []
498498
while True:
499+
top_ids = None
499500
with self.lock:
500501
if self.vllm_output_queue[uuid].empty() is True:
501502
request_outputs: List[RequestOutput] = self.vllm.step()
502503
for request_output in request_outputs:
503-
top_ids = list(request_output.outputs[0].token_ids)[-1]
504-
self.vllm_output_queue[request_output.request_id].put(top_ids)
505-
if self.vllm_output_queue[uuid].empty() is False:
506-
top_ids = self.vllm_output_queue[uuid].get()
504+
self.vllm_output_queue[request_output.request_id].put(list(request_output.outputs[0].token_ids)[-1])
505+
if self.vllm_output_queue[uuid].empty() is False:
506+
top_ids = self.vllm_output_queue[uuid].get()
507+
if top_ids is not None:
507508
if top_ids in self.stop_token_ids:
508509
break
509510
# in stream mode, yield token one by one
510511
yield top_ids
511512
out_tokens.append(top_ids)
512513
if len(out_tokens) == max_len:
513514
break
514-
time.sleep(0.001)
515+
else:
516+
time.sleep(0.001)
515517
with self.lock:
516518
self.vllm_output_queue.pop(uuid)
517519
else:

cosyvoice/vllm/cosyvoice2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# See the License for the specific language governing permissions and
2424
# limitations under the License.
2525
"""Inference-only Qwen2 model compatible with HuggingFace weights."""
26-
from typing import Optional
26+
from typing import Optional, Union, Iterable
2727
from packaging.version import parse as vparse
2828
import vllm
2929

0 commit comments

Comments
 (0)