Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLM: Add length check for IPEX-CPU speculative decoding #10529

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions python/llm/src/ipex_llm/transformers/speculative.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ def generate(
**kwargs,
):
if hasattr(self, "draft_model"):
from ipex_llm.llm.transformers.convert import get_enable_ipex
_enable_ipex = get_enable_ipex()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add CPU device check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_enable_ipex is CPU only. Others LGTM

Copy link
Contributor

@qiyuangong qiyuangong Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jason-dai
Any comment on this PR

if _enable_ipex and inputs.size(1) < 256:
logger.warning(
"IPEX_CPU optimized models have issues for speculative decoding with short prompts"
"(length < 256). Using normal generate() method instead."
)
for var in ['max_step_draft', 'th_stop_draft', 'hf_adjust',
'auto_th_stop_draft', 'auto_parameters', 'min_step_draft',
'th_batch_num']:
value = kwargs.pop(var, None)
del self.draft_model
return original_generate(self,
inputs=inputs,
generation_config=generation_config,
logits_processor=logits_processor,
stopping_criteria=stopping_criteria,
prefix_allowed_tokens_fn=prefix_allowed_tokens_fn,
synced_gpus=synced_gpus,
assistant_model=assistant_model,
streamer=streamer,
**kwargs)
# do speculative decoding
# TODO: maybe add other way to double check
new_speculative_kwargs = {}
Expand Down
Loading