Skip to content

Commit 4127b99

Browse files
authored
Fix null pointer dereferences error. (#11125)
* delete unused function on tgi_server * update * update * fix style
1 parent 50ee004 commit 4127b99

File tree

4 files changed

+26
-78
lines changed

4 files changed

+26
-78
lines changed

python/llm/dev/print_glib_requirement.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ def _check_version(filename, flag="GLIBC"):
2929
if flag == "GLIBCXX":
3030
subfile = _check_glibcxx_version(filename)
3131
max_version = None
32-
for version_string in subfile.split():
33-
try:
34-
version = Version(version_string.split("_")[1])
35-
if max_version is None or version > max_version:
36-
max_version = version
37-
except Exception:
38-
pass
32+
if subfile:
33+
for version_string in subfile.split():
34+
try:
35+
version = Version(version_string.split("_")[1])
36+
if max_version is None or version > max_version:
37+
max_version = version
38+
except Exception:
39+
pass
3940
return max_version
4041

4142

python/llm/portable-zip/chat.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def greedy_generate(model, tokenizer, input_ids, past_key_values, max_gen_len, s
113113

114114
if pred_token_idx == tokenizer.eos_token_id:
115115
break
116-
print(" ".join(generated_text[pos:]).strip('\n<'), flush=True)
116+
if generated_text:
117+
print(" ".join(generated_text[pos:]).strip('\n<'), flush=True)
117118
return past_key_values
118119

119120
@torch.no_grad()

python/llm/src/ipex_llm/serving/fastchat/tgi_api_server.py

-59
Original file line numberDiff line numberDiff line change
@@ -607,65 +607,6 @@ async def chat_completion_stream_generator(
607607
yield f"data: {json.dumps(chunk.model_dump(exclude_unset=True), ensure_ascii=False)}\n\n"
608608
yield "data: [DONE]\n\n"
609609

610-
async def generate_completion_stream_generator(
611-
request: CompletionRequest, n: int, worker_addr: str
612-
):
613-
model_name = request.model
614-
id = f"cmpl-{shortuuid.random()}"
615-
finish_stream_events = []
616-
for text in request.prompt:
617-
for i in range(n):
618-
previous_text = ""
619-
gen_params = await get_gen_params(
620-
request.model,
621-
worker_addr,
622-
text,
623-
temperature=request.temperature,
624-
top_p=request.top_p,
625-
top_k=request.top_k,
626-
presence_penalty=request.presence_penalty,
627-
frequency_penalty=request.frequency_penalty,
628-
max_tokens=request.max_tokens,
629-
logprobs=request.logprobs,
630-
echo=request.echo,
631-
stop=request.stop,
632-
)
633-
async for content in generate_completion_stream(gen_params, worker_addr):
634-
if content["error_code"] != 0:
635-
yield f"data: {json.dumps(chunk.model_dump(exclude_unset=True), ensure_ascii=False)}\n\n"
636-
yield "data: [DONE]\n\n"
637-
return
638-
decoded_unicode = content["text"].replace("\ufffd", "")
639-
delta_text = decoded_unicode[len(previous_text) :]
640-
previous_text = (
641-
decoded_unicode
642-
if len(decoded_unicode) > len(previous_text)
643-
else previous_text
644-
)
645-
# todo: index is not apparent
646-
choice_data = CompletionResponseStreamChoice(
647-
index=i,
648-
text=delta_text,
649-
logprobs=create_openai_logprobs(content.get("logprobs", None)),
650-
finish_reason=content.get("finish_reason", None),
651-
)
652-
chunk = CompletionStreamResponse(
653-
id=id,
654-
object="text_completion",
655-
choices=[choice_data],
656-
model=model_name,
657-
)
658-
if len(delta_text) == 0:
659-
if content.get("finish_reason", None) is not None:
660-
finish_stream_events.append(chunk)
661-
continue
662-
yield f"data: {json.dumps(chunk.model_dump(exclude_unset=True), ensure_ascii=False)}\n\n"
663-
# There is not "content" field in the last delta message, so exclude_none to exclude field "content".
664-
for finish_chunk in finish_stream_events:
665-
yield f"data: {json.dumps(chunk.model_dump(exclude_unset=True), ensure_ascii=False)}\n\n"
666-
yield "data: [DONE]\n\n"
667-
668-
669610
async def generate_completion_stream(payload: Dict[str, Any], worker_addr: str):
670611
controller_address = app_settings.controller_address
671612
async with httpx.AsyncClient() as client:

python/llm/src/ipex_llm/transformers/convert.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -487,20 +487,25 @@ def replace_with_low_bit_linear_for_module(model, qtype, module_name=None,
487487
FP16Linear, BF16Linear
488488
has_been_replaced = False
489489

490+
splits = []
490491
if "." in module_name:
491492
splits = module_name.split(".")
492-
parent_module = getattr(model, splits[0])
493-
494-
if "lm_head" not in module_name:
495-
for split in splits[1:-2]:
496-
new_module = getattr(parent_module, split)
497-
parent_module = new_module
498-
module = getattr(parent_module, splits[-2])
499-
module_name = splits[-2]
493+
if not splits:
494+
invalidInputError(False,
495+
"Please provide a valid module_name with hierarchical structure")
500496
else:
501-
module = parent_module
502-
parent_module = model
503-
module_name = splits[0]
497+
parent_module = getattr(model, splits[0])
498+
499+
if "lm_head" not in module_name:
500+
for split in splits[1:-2]:
501+
new_module = getattr(parent_module, split)
502+
parent_module = new_module
503+
module = getattr(parent_module, splits[-2])
504+
module_name = splits[-2]
505+
else:
506+
module = parent_module
507+
parent_module = model
508+
module_name = splits[0]
504509

505510
if current_key_name is None:
506511
current_key_name = []

0 commit comments

Comments
 (0)