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

fix minicpm V 2.6 repeat output #11753

Merged
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
27 changes: 25 additions & 2 deletions python/llm/src/ipex_llm/transformers/models/minicpmv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@
#


import torch
from transformers.generation.logits_process import RepetitionPenaltyLogitsProcessor


# todo
def patched_repetition_penalty_call(self, input_ids: torch.LongTensor, scores: torch.FloatTensor):
score = torch.gather(scores, 1, input_ids)

# if score < 0 then repetition penalty has to be
# multiplied to reduce the token probabilities
score = torch.where(score < 0, score * self.penalty, score / self.penalty)

# ipex llm changes start: call scatter on CPU
device = scores.device
scores = scores.to('cpu')
input_ids = input_ids.to('cpu')
score = score.to('cpu')
scores.scatter_(1, input_ids, score)
scores = scores.to(device)
Comment on lines +31 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a gpu implementation later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

# ipex llm changes end

return scores


def minicpmv_generate_wrapper(origin_generate):
def generate(
self,
Expand All @@ -30,8 +54,7 @@ def generate(
decode_text=False,
**kwargs
):
if kwargs.get("repetition_penalty", None) is not None:
kwargs["repetition_penalty"] = 1
RepetitionPenaltyLogitsProcessor.__call__ = patched_repetition_penalty_call
return origin_generate(
self=self,
input_ids=input_ids,
Expand Down
Loading