Skip to content

How to make it forget everything during for loop? #519

Description

@AlexB05

Sorry I am new to this.
Say I have a book full of independent articles, and I am trying to run alpaca in a loop, but for every run, I want it to forget everything and start new. (Basically the opposite of chat, make model remember zero previous context) To do this, based on my limited understanding, I need to set last_n_tokens_size to 0 (Is this even correct?)

llm = Llama(model_path="some_model.bin",n_ctx=1024,n_batch=1024, last_n_tokens_size=0, n_gpu_layers=2000000)
for article in book:
    output=evaluate(llm,article)

to make predictions.

Unfortunately the code above will cause an error:

  File "/***/lib/python3.10/site-packages/llama_cpp/llama.py", line 1328, in __call__
    return self.create_completion(
  File "/***/lib/python3.10/site-packages/llama_cpp/llama.py", line 1280, in create_completion
    completion: Completion = next(completion_or_chunks)  # type: ignore
  File "/***/lib/python3.10/site-packages/llama_cpp/llama.py", line 872, in _create_completion
    for token in self.generate(
  File "/***/lib/python3.10/site-packages/llama_cpp/llama.py", line 695, in generate
    token = self.sample(
  File "/***/lib/python3.10/site-packages/llama_cpp/llama.py", line 620, in sample
    last_n_tokens_data=(llama_cpp.llama_token * self.last_n_tokens_size)(
IndexError: invalid index

Interestingly, if I change last_n_tokens_size to 1, it will run smoothly.

My question is:

  1. Is last_n_tokens_size=0 even the correct way to make it forget everything before? If not, how?
  2. Is it ok to put llm = Llama(model=***) outside the for loop if I want each run not interfere each other's result, or do I need to put it inside the for loop?
  3. If anyone also making predictions that are independent for each run, could you share some examples?

I apologize if the questions are silly.
Thanks in advance!

Activity

  1. changed the title [-]How to make it forget everything?[/-] [+]How to make it forget everything during for loop?[/+] on Jul 24, 2023
  2. Repository owner locked and limited conversation to collaborators on Jul 30, 2023
  3. converted this issue into a discussion #544 on Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions