Skip to content

Instantly share code, notes, and snippets.

@psychemedia
Last active December 21, 2023 17:30
Show Gist options
  • Star 30 You must be signed in to star a gist
  • Fork 20 You must be signed in to fork a gist
  • Save psychemedia/51f45fbfe160f78605bdd0c1b404e499 to your computer and use it in GitHub Desktop.
Save psychemedia/51f45fbfe160f78605bdd0c1b404e499 to your computer and use it in GitHub Desktop.
Example of running GPT4all local LLM via langchain in a Jupyter notebook (Python)
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cg-sachink
Copy link

But this is not working

@rain1024
Copy link

rain1024 commented Apr 7, 2023

I'm having trouble with the following code:

download llama.cpp 7B model
#%pip install pyllama
#!python3.10 -m llama.download --model_size 7B --folder llama/

I install pyllama with the following command successfully

$ pip install pyllama
$ pip freeze | grep pyllama
pyllama==0.0.9
pyllamacpp==1.0.6

However when I run

$ python -m llama.download --model_size 7B --folder llama/

I received an error message:

No module named llama.download

Has anyone else encountered same issue?

Update 1:

When I clone repository pyllama and run from pyllama, I can download the llama folder

@monabiyan
Copy link

from langchain.embeddings import LlamaCppEmbeddings does not work.

@psychemedia
Copy link
Author

psychemedia commented Apr 11, 2023 via email

@JeffreyShran
Copy link

@psychemedia - Any ideas on where to seek out performance gain opportunities?

The final run on#129 is a killer. I was expecting VectorstoreIndexCreator to be something that helped improve performance but it still takes a long time.

@psychemedia
Copy link
Author

@JeffreyShran For performance, I'd probably use a different way of semantically indexing items; the above demo was trying to keep things bounded by reusing the same model for everything.

@MakkiNeutron
Copy link

ValueError: Requested tokens exceed context window of 512 using gpt4All with langchain llamacpp

@JeffreyShran
Copy link

JeffreyShran commented Apr 17, 2023

@JeffreyShran For performance, I'd probably use a different way of semantically indexing items; the above demo was trying to keep things bounded by reusing the same model for everything.

Thanks @psychemedia, my longer term goal is to load in a git repo by switching the loader with the official git one with the hope that I could ask questions about my private projects.

RE: the error reported by @MakkiNeutron. I tried to load in a semi-small Python script as a text file as a preliminary test and also hit this error. Some digging showed that llama.cpp can be modified to increase the token amount. However I feel like this is a wrong step and in fact we should try to do a) as you suggested to my earlier question, use a different index approach and/or b) further split the text into smaller batches than the 500 in your code.

I'm keen but very much a noob in this space and so any insights that you might be able to share would be useful and appreciated, particularly on my expected use-case. Do you feel that I am taking the smartest route or should I use a different approach within langchain or some other tool?

@jrobles98
Copy link

@JeffreyShran Humm I just arrived here but talking about increasing the token amount that Llama can handle is something blurry still since it was trained from the beggining with that amount and technically you should need to recreate the whole training of Llama but increasing the input size. In other words, is a inherent property of the model that is unmutable from the beggining.
Good news is that the input training that Llama was trained on (therefore the maximum possible) is 2048 tokens!

Here you can see that limit on the HF docs looking at the max_position_embeddings parameter

BTW here is a similar thread if you want to take a sneak peak

Nevertheless there are ways to let Llama have more "memory scope", here are some converstional approaches, the last section is the most interesting one for any purpose.

Hope you found it helpfull✌🏼

@JeffreyShran
Copy link

@JeffreyShran Humm I just arrived here but talking about increasing the token amount that Llama can handle is something blurry still since it was trained from the beggining with that amount and technically you should need to recreate the whole training of Llama but increasing the input size. In other words, is a inherent property of the model that is unmutable from the beggining. Good news is that the input training that Llama was trained on (therefore the maximum possible) is 2048 tokens!

Here you can see that limit on the HF docs looking at the max_position_embeddings parameter

BTW here is a similar thread if you want to take a sneak peak

Nevertheless there are ways to let Llama have more "memory scope", here are some converstional approaches, the last section is the most interesting one for any purpose.

Hope you found it helpfull✌🏼

Thanks, that is helpful. However it appears that these settings are already maxed out at default to 2048.

The file I tested with had only a few lines in it, so I think the problem might lie elsewhere.

@jrobles98
Copy link

Thanks, that is helpful. However it appears that these settings are already maxed out at default to 2048.

The file I tested with had only a few lines in it, so I think the problem might lie elsewhere.

Yes, Indeed. I was hoping to find that limit on GPT4All but only found that the standard model used 1024 input tokens. So maybe... the quantized lora version uses a limit of 512 tokens for some reason, although it doens't make that much sense since quantized and lora versions only looses precision rather than dimensionality.

Anyway I think the best way to improve this regard is to try to use other models that we know can handle already 2048 token input. I suggest Vicuna, that was born mainly with this purpose of maxing out input/output.

If somebody can test this it would be so great.

@JeffreyShran
Copy link

JeffreyShran commented Apr 18, 2023

I'm actually using ggml-vicuna-7b-4bit.bin. This is the one I'm having the most trouble with. :)

@mtthw-meyer
Copy link

This would be much easier to follow with the working code in one place instead of only scattered fragments.

@stellarkllc
Copy link

Is it possible to use GPT4All as llm with sql_agent or pandas_agent instead of OpenAI?

@zeke-john
Copy link

I've installed all the packages and still get this: zsh: command not found: pyllamacpp-convert-gpt4all

@lingjiekong
Copy link

I've installed all the packages and still get this: zsh: command not found: pyllamacpp-convert-gpt4all

Try a older version pyllamacpp pip install pyllamacpp==1.0.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment