Giter Site home page Giter Site logo

gpt4all-j's Introduction

Python bindings for the C++ port of GPT4All-J model.

Please migrate to ctransformers library which supports more models and has more features.

Installation

pip install gpt4all-j

Download the model from here.

Usage

from gpt4allj import Model

model = Model('/path/to/ggml-gpt4all-j.bin')

print(model.generate('AI is going to'))

Run in Google Colab

If you are getting illegal instruction error, try using instructions='avx' or instructions='basic':

model = Model('/path/to/ggml-gpt4all-j.bin', instructions='avx')

If it is running slow, try building the C++ library from source. Learn more

Parameters

model.generate(prompt,
               seed=-1,
               n_threads=-1,
               n_predict=200,
               top_k=40,
               top_p=0.9,
               temp=0.9,
               repeat_penalty=1.0,
               repeat_last_n=64,
               n_batch=8,
               reset=True,
               callback=None)

reset

If True, context will be reset. To keep the previous context, use reset=False.

model.generate('Write code to sort numbers in Python.')
model.generate('Rewrite the code in JavaScript.', reset=False)

callback

If a callback function is passed, it will be called once per each generated token. To stop generating more tokens, return False inside the callback function.

def callback(token):
    print(token)

model.generate('AI is going to', callback=callback)

LangChain

LangChain is a framework for developing applications powered by language models. A LangChain LLM object for the GPT4All-J model can be created using:

from gpt4allj.langchain import GPT4AllJ

llm = GPT4AllJ(model='/path/to/ggml-gpt4all-j.bin')

print(llm('AI is going to'))

If you are getting illegal instruction error, try using instructions='avx' or instructions='basic':

llm = GPT4AllJ(model='/path/to/ggml-gpt4all-j.bin', instructions='avx')

It can be used with other LangChain modules:

from langchain import PromptTemplate, LLMChain

template = """Question: {question}

Answer:"""

prompt = PromptTemplate(template=template, input_variables=['question'])

llm_chain = LLMChain(prompt=prompt, llm=llm)

print(llm_chain.run('What is AI?'))

Parameters

llm = GPT4AllJ(model='/path/to/ggml-gpt4all-j.bin',
               seed=-1,
               n_threads=-1,
               n_predict=200,
               top_k=40,
               top_p=0.9,
               temp=0.9,
               repeat_penalty=1.0,
               repeat_last_n=64,
               n_batch=8,
               reset=True)

C++ Library

To build the C++ library from source, please see gptj.cpp. Once you have built the shared libraries, you can use them as:

from gpt4allj import Model, load_library

lib = load_library('/path/to/libgptj.so', '/path/to/libggml.so')

model = Model('/path/to/ggml-gpt4all-j.bin', lib=lib)

License

MIT

gpt4all-j's People

Contributors

beratcmn avatar marella avatar thebloke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gpt4all-j's Issues

zsh: illegal hardware instruction

I'm using Mac with M1 chip. Any other tips? I already tried

from gpt4allj import Model

model = Model('./models/ggml-gpt4all-j.bin', instructions='avx')

print(model.generate('AI is going to'))```

error while trying to call gpt4allj.langchain

Hi I am trying to call "from gpt4allj.langchain import GPT4AllJ", but i get that error
'''ModuleNotFoundError: No module named 'langchain.callbacks.manager'''
I have istalled langchain + gpt4lallj + gpt4all
why i get that error. could any one help me

Don't print to screen by default

Hi

At the moment, all output from gpt4all-j is automatically printed to the screen. This makes the code quite 'noisy' when running from a script.

Ideally this information shouldn't be printed unless the user requests it.

Example:

tomj@Eddie ~/src $ python
Python 3.11.3 (main, Apr  7 2023, 19:25:52) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gpt4allj import Model
>>>
>>> model = Model('/Users/tomj/src/test-gpt4all/models/ggml-gpt4all-j-v1.2-jazzy.bin')
gptj_model_load: loading model from '/Users/tomj/src/test-gpt4all/models/ggml-gpt4all-j-v1.2-jazzy.bin' - please wait ...
gptj_model_load: n_vocab = 50400
gptj_model_load: n_ctx   = 2048
gptj_model_load: n_embd  = 4096
gptj_model_load: n_head  = 16
gptj_model_load: n_layer = 28
gptj_model_load: n_rot   = 64
gptj_model_load: f16     = 2
gptj_model_load: ggml ctx size = 5401.45 MB
gptj_model_load: memory_size =  1792.00 MB, n_mem = 57344
gptj_model_load: ................................... done
gptj_model_load: model size =  3609.38 MB / num tensors = 285
>>> output = model.generate('###Instruction: Write an essay about the American Civil War\n###Response:', n_threads=18, n_predict=500, top_k=40, top_p=0.9,temp=0.7)
gptj_generate: seed = 1681816305
gptj_generate: number of tokens in prompt = 17

###Instruction: Write an essay about the American Civil War
###Response: The American Civil War was a significant event in American history that lasted from 1861 to 1865. It was fought between the Union and Confederacy, with the Union ultimately emerging victorious. The war was fought over a number of issues, including slavery, states' rights, and the preservation of the Union. The war was brutal, with over 620,000 soldiers losing their lives, and the conflict resulted in the deaths of countless civilians. The war had a profound impact on American society, and it remains a significant event in the country's history.<|endoftext|

I did not print anything, but got a lot of automatically printed output from gptj

Thanks

"Not enough space in the context's memory pool"

Hi

When trying longer prompts, Python crashes with not enough space in the context's memory pool. Example:

tomj@Eddie ~/src $ python
Python 3.11.3 (main, Apr  7 2023, 19:25:52) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gpt4allj import Model
>>> model = Model('/Users/tomj/src/test-gpt4all/models/ggml-gpt4all-j-v1.2-jazzy.bin')
gptj_model_load: loading model from '/Users/tomj/src/test-gpt4all/models/ggml-gpt4all-j-v1.2-jazzy.bin' - please wait ...
gptj_model_load: n_vocab = 50400
gptj_model_load: n_ctx   = 2048
gptj_model_load: n_embd  = 4096
gptj_model_load: n_head  = 16
gptj_model_load: n_layer = 28
gptj_model_load: n_rot   = 64
gptj_model_load: f16     = 2
gptj_model_load: ggml ctx size = 5401.45 MB
gptj_model_load: memory_size =  1792.00 MB, n_mem = 57344
gptj_model_load: ................................... done
gptj_model_load: model size =  3609.38 MB / num tensors = 285
>>> prompt='''Below is an instruction that describes a task. Write a response that appropriately completes the request.
... ### Instruction:
... Write a story about llamas
... ### Response:'''
>>> print(model.generate(prompt))
gptj_generate: seed = 1681815129
gptj_generate: number of tokens in prompt = 34

Below is an instruction that describes a task. Write a response that appropriately completes the request.
### Instruction:
Write a story about llamas
### Response:ggml_new_tensor_impl: not enough space in the context's memory pool (needed 1382304912, available 612697122)
[1]    8718 segmentation fault  python

Ubuntu install

In case of use as feedback.

I just installed on a Ubuntu server with a t3.large instance type. (8 GiB memory).

I got the following error during installation:

  ERROR: Command errored out with exit status 1:
   command: /home/ubuntu/GPT4ALLJ/env/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-fv3hmz5f/gpt4all-j/setup.py'"'"'; __file__='"'"'/tmp/pip-install-fv3hmz5f/gpt4all-j/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-5dvn98y4
       cwd: /tmp/pip-install-fv3hmz5f/gpt4all-j/
  Complete output (6 lines):
  usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: setup.py --help [cmd1 cmd2 ...]
     or: setup.py --help-commands
     or: setup.py cmd --help
  
  error: invalid command 'bdist_wheel'
  ----------------------------------------
  ERROR: Failed building wheel for gpt4all-j

However, the install completed successfully and I was able to run the following simple program:

from gpt4allj import Model

model = Model('./models/ggml-gpt4all-j.bin', instructions='avx')

print(model.generate('What are the strengths and weaknesses of AWS versus Google Cloud?'))

Note that to run this program it takes 3 mins to get a reponse (and the response is then truncated, I assume because there is a hardcoded output length by default).

Few suggestions to add

Hi and thanks for your awesome backend.
I was just wondering if you can add those options to your generate method:
repeat_penalty
repeat_last_n

They are standard GPT parameters and your backend kinda miss that. They help penalize the model when it starts repeating stuff.

Need to recover the output word by word

Hi there,
Thank you for this promissing binding for gpt-J.

I am developing the GPT4All-ui that supports llamacpp for now and would like to support other backends such as gpt-j.

I can use your backend in my tool but I need the binding to be able to do the following:

1 - Allow me ro provide a callback function to the generate function to recover the output word by word as it comes.
2 - The callback function returns a continue boolean. If the boolean is False, it means that the user wants to stop the generation process. If the function returns nothing, you cas assulme that we want to continue.
3 - My tool has a continuous discussion system so I will send you every thing at once (the conditionning text + all previous discussion parts). So no need to add internal conditionning, just take all my text as prompt and give me the answer word by word.
4 - I also need a function that gives me the count of tokens from a text. I need this to adjust the window of words I send you so that it doesn't exceed the context size without loosing the conditionning part.

I think your binding can be a good thing to add to my tool as GPT-J has its own
Here is my tool if you want to check it out:
https://github.com/nomic-ai/gpt4all-ui
you can view my videos that explain how to install it, use it and modify the settings:
https://www.youtube.com/watch?v=6kKv6ESnwMk&list=PLuI3It1_o4U9u_0_SZTVYofUlYKQwIcl_&ab_channel=ParisNeo

The ui has advanced greatly from when I made this video. You can look at latest version in the github.

Thanks for making this binding.

Best regards

You must make a crash course or something like that.

Hi dear author, ı have trying to do what you are doing right now and it's difficult for me to find learning resources for this kind of stuff finally your library and you are perfect. Thank you for your effort and pslsss make course or suggest us a place for learning this kind of stuff. Thank you in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.