Skip to content

Commit

Permalink
Prevent llama.cpp from being monkey patched more than once (closes #6201
Browse files Browse the repository at this point in the history
)
  • Loading branch information
oobabooga committed Jul 5, 2024
1 parent a210e61 commit aa653e3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/llama_cpp_python_hijack.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ def eval_with_progress(self, tokens: Sequence[int]):


def monkey_patch_llama_cpp_python(lib):
if getattr(lib.Llama, '_is_patched', False):
# If the patch is already applied, do nothing
return

def my_generate(self, *args, **kwargs):

if shared.args.streaming_llm:
new_sequence = args[0]
past_sequence = self._input_ids
Expand All @@ -116,3 +118,6 @@ def my_generate(self, *args, **kwargs):
lib.Llama.eval = eval_with_progress
lib.Llama.original_generate = lib.Llama.generate
lib.Llama.generate = my_generate

# Set the flag to indicate that the patch has been applied
lib.Llama._is_patched = True

0 comments on commit aa653e3

Please sign in to comment.