[Breaking] Migrate GPT4All to use PyGPT4All (#3934)

Seems the pyllamacpp package is no longer the supported bindings from
gpt4all. Tested that this works locally.

Given that the older models weren't very performant, I think it's better
to migrate now without trying to include a lot of try / except blocks

---------

Co-authored-by: Nissan Pow <npow@users.noreply.github.com>
Co-authored-by: Nissan Pow <pownissa@amazon.com>
This commit is contained in:
Zander Chase 2023-05-01 20:42:45 -07:00 committed by GitHub
parent f0a4bbb8e2
commit c4cb55a0c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 178 additions and 187 deletions

View File

@ -27,7 +27,7 @@
}
],
"source": [
"%pip install pyllamacpp > /dev/null"
"%pip install pygpt4all > /dev/null"
]
},
{
@ -64,7 +64,7 @@
"source": [
"### Specify Model\n",
"\n",
"To run locally, download a compatible ggml-formatted model. For more info, visit https://github.com/nomic-ai/pyllamacpp\n",
"To run locally, download a compatible ggml-formatted model. For more info, visit https://github.com/nomic-ai/pygpt4all\n",
"\n",
"For full installation instructions go [here](https://gpt4all.io/index.html).\n",
"\n",
@ -79,7 +79,7 @@
"metadata": {},
"outputs": [],
"source": [
"local_path = './models/gpt4all-lora-quantized-ggml.bin' # replace with your desired local file path"
"local_path = './models/ggml-gpt4all-l13b-snoozy.bin' # replace with your desired local file path"
]
},
{
@ -102,8 +102,8 @@
"\n",
"# Path(local_path).parent.mkdir(parents=True, exist_ok=True)\n",
"\n",
"# # Example model. Check https://github.com/nomic-ai/pyllamacpp for the latest models.\n",
"# url = 'https://the-eye.eu/public/AI/models/nomic-ai/gpt4all/gpt4all-lora-quantized-ggml.bin'\n",
"# # Example model. Check https://github.com/nomic-ai/pygpt4all for the latest models.\n",
"# url = 'http://gpt4all.io/models/ggml-gpt4all-l13b-snoozy.bin'\n",
"\n",
"# # send a GET request to the URL to download the file. Stream since it's large\n",
"# response = requests.get(url, stream=True)\n",
@ -165,7 +165,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.2"
}
},
"nbformat": 4,

View File

@ -12,7 +12,7 @@ from langchain.llms.utils import enforce_stop_tokens
class GPT4All(LLM):
r"""Wrapper around GPT4All language models.
To use, you should have the ``pyllamacpp`` python package installed, the
To use, you should have the ``pygpt4all`` python package installed, the
pre-trained model file, and the model's config information.
Example:
@ -126,19 +126,19 @@ class GPT4All(LLM):
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that the python package exists in the environment."""
try:
from pyllamacpp.model import Model as GPT4AllModel
from pygpt4all.models.gpt4all import GPT4All as GPT4AllModel
llama_keys = cls._llama_param_names()
model_kwargs = {k: v for k, v in values.items() if k in llama_keys}
values["client"] = GPT4AllModel(
ggml_model=values["model"],
model_path=values["model"],
**model_kwargs,
)
except ImportError:
raise ValueError(
"Could not import pyllamacpp python package. "
"Please install it with `pip install pyllamacpp`."
"Could not import pygpt4all python package. "
"Please install it with `pip install pygpt4all`."
)
return values

View File

@ -7,21 +7,12 @@ from langchain.llms import GPT4All
def _download_model() -> str:
"""Download model.
From https://the-eye.eu/public/AI/models/nomic-ai/gpt4all/gpt4all-lora-quantized.bin,
convert to new ggml format and return model path."""
model_url = "https://the-eye.eu/public/AI/models/nomic-ai/gpt4all/gpt4all-lora-quantized.bin"
tokenizer_url = "https://huggingface.co/decapoda-research/llama-7b-hf/resolve/main/tokenizer.model"
conversion_script = "https://github.com/nomic-ai/pyllamacpp/blob/main/pyllamacpp/scripts/convert_gpt4all.py"
"""Download model."""
model_url = "http://gpt4all.io/models/ggml-gpt4all-l13b-snoozy.bin"
local_filename = model_url.split("/")[-1]
if not os.path.exists("convert_gpt4all.py"):
urlretrieve(conversion_script, "convert_gpt4all.py")
if not os.path.exists("tokenizer.model"):
urlretrieve(tokenizer_url, "tokenizer.model")
if not os.path.exists(local_filename):
urlretrieve(model_url, local_filename)
os.system(f"python convert_gpt4all.py.py . tokenizer.model")
return local_filename