Skip to content

Commit

Permalink
Fix magicoder model tokenizer issue and remove codegen streaming redu…
Browse files Browse the repository at this point in the history
…ndant end format (#1086)

* Fix magicoder tokenizer issue and streaming redundant end format

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
  • Loading branch information
lvliang-intel committed Dec 27, 2023
1 parent 4b5eb3f commit 2758d49
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ def load_model(
logging.error(f"Exception: {e}")
raise ValueError(f"load_model: an unexpected error occurred, {e}")

if re.search("llama", model.config.architectures[0], re.IGNORECASE):
if re.search("llama", model.config.architectures[0], re.IGNORECASE) and \
not re.search("magicoder", model_name, re.IGNORECASE):
# unwind broken decapoda-research config
model.generation_config.pad_token_id = 0
model.generation_config.bos_token_id = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,31 +250,13 @@ async def chat_completion_endpoint(request: ChatCompletionRequest):
if attr == "stream":
continue
setattr(gen_config, attr, value)
buffered_texts = ""
if request.stream:
generator, _ = chatbot.predict_stream(query=request.prompt, config=gen_config)
if not isinstance(generator, types.GeneratorType):
generator = (generator,)
def stream_generator():
nonlocal buffered_texts
for output in generator:
if isinstance(output, str):
chunks = output.split()
for chunk in chunks:
ret = {
"text": chunk,
"error_code": 0,
}
buffered_texts += chunk + ' '
yield json.dumps(ret).encode() + b"\0"
else:
ret = {
"text": output,
"error_code": 0,
}
buffered_texts += output + ' '
yield json.dumps(ret).encode() + b"\0"
yield f"data: [DONE]\n\n"
yield output + "\0"
return StreamingResponse(stream_generator(), media_type="text/event-stream")
else:
response = chatbot.predict(query=request.prompt, config=gen_config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ async def chat_completion_endpoint(request: ChatCompletionRequest):
def stream_generator():
for output in generator:
yield output + "\0"
yield f"data: [DONE]\n\n"
return StreamingResponse(stream_generator(), media_type="text/event-stream")
else:
response = chatbot.predict(query=request.prompt, config=gen_config)
Expand Down

0 comments on commit 2758d49

Please sign in to comment.