-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python Clean-Up Pass 2: Tests & Code Improvements #1293
Conversation
|
bc7f3fd
to
c46545b
Compare
This has become quite big even before refactoring. At the moment, it's basically all tests. I think I'll do just a few code improvements now. And I won't worry about everything else I wanted to do here. I'll open it up already in any case. From here it'll be some changes and squashing a bunch of commits. |
I think I'll leave it at this, just some squashing still to do. Maybe some very minor touch-ups, as well. |
- Mark decorators in test_gpt4all.py - Add note to the makefile - pytest marks need to be defined in a config file, here: pytest.ini - see: https://docs.pytest.org/en/7.4.x/how-to/mark.html
- Specify optional PYTEST_MODEL_PATH environment variable. - Format is like other PATH env vars, i.e. multiple folders allowed. - If set, these are the folder(s) in which models will be looked up for the tests.
- Tests are focused on the backend, i.e. the C API (through ctypes) - Add another pytest marker specifically for the backend: c_api_call
- Tests for the rest of the pyllmodel module which are mostly focused on the LLModel class.
- module gpt4all - module pyllmodel - edit gpt4all_python.md to match the _format_chat_prompt_template() change
…i#1293) - Make it more flexible so e.g. the heavy lifting could be handled differently in a subclass.
a5eb7da
to
29b02ac
Compare
it appears that if
|
with a directory specified some tests that check output fail on Mac because the Metal implementation does not get the same result:
|
Thanks for having a look.
Good catch, I failed to consider that. Although it already does the "reasonable default" thing by returning
Ah, interesting. I'd wager I don't have Metal support on CI? @acrastt was kind enough to help me run some tests on a Mac because I don't have one, but that was without Metal, too. I guess I'll just make the tests more general. Edit:
I have inference off most of the time here, so that slipped through. By the way, is there a way to make it truly deterministic across all architectures? |
By the way, looking at those pre-existing tests, I don't understand what Edit: I guess it's fine, in that it tests whether longer inputs are possible. Although not very useful anymore, |
this is what it's for - specifically I added it to test that memory management for long contexts in the backend have not broken |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outputs are not necessarily 100% consistent across backends or build configurations - tests should probably not check for exact output strings but if they do should force running on cpu (though even with Metal off the MacOS build may get different results as ggml on MacOS still has significant differences from the windows and linux builds)
test_inference_hparams
still fails on my machine for Paris
not appearing in the first 3 tokens
Alright, I hope that's that. If it's ok like this, I think I'll rebase onto main and merge those fixes into their respective commits. |
all tests now pass for me if I do set PYTEST_MODEL_PATH, but some still fail without it: https://gist.github.com/apage43/75247c0111363cde4dedd81b80217caa weird that this doesn't repro for you - if you're sure you've made sure the var is not set and it all passes it could be a MacOS specific thing, in which case I'm okay with calling that out in the py binding README and leaving it that way for now and I'll try to debug it myself later |
I'm not sure about it, I'll have to try again. I'm usually running all of these through VS Codium, which comes with If you don't set the Actually, this is strange: if model_path is None:
try:
os.makedirs(DEFAULT_MODEL_DIRECTORY, exist_ok=True)
except OSError as exc:
raise ValueError(
f"Failed to create model download directory at {DEFAULT_MODEL_DIRECTORY}: {exc}. "
"Please specify model_path."
)
model_path = DEFAULT_MODEL_DIRECTORY
else:
model_path = model_path.replace("\\", "\\\\")
if not os.path.exists(model_path):
> raise ValueError(f"Invalid model directory: {model_path}")
E ValueError: Invalid model directory: None How is it still Maybe I'll have to remove all my models and paths to find out what's going on here. Edit: Alright I see the problem. I guess I just failed to remove the env var here when I tried previously. There's a conversion from The idea is to eventually accept files/folders both as |
They are, though for me it is a symlink to the path the GUI puts them in:
|
Alright, so it looks like the version that finally brings the project near upstream llama.cpp again (i.e. 2.5.0 of chat GUI; GGUF support) is about to be ready. I guess the PR is outdated now (haven't followed everything closely), but the idea is still the same: if/when it gets accepted, refine things in a branch of the repo so there's access to CI, i.e. CI can run when pushing commits. How exactly that happens is up to you. |
This is outdated and to be closed? |
This was outdated a while ago because you guys didn't want to move it forward or merge it when it was ready. |
If you're still interested in updating this PR to GGUF and the latest bindings, I could run CI for you and review/merge it. apage43 hasn't been assigned to GPT4All for a while. |
Why not talk to me on Discord while I'm there? Here's the summary of what has been going on and the state this is in:
Now I get that you people have been busy, but it's simply at a point where someone would have needed to spend some time on it. That shouldn't have been too much to ask. I can't decide this for you.
So what I would have liked to see was the following:
You'll have to excuse me, but at this point in time, my motivation to contribute any more time to the project is at an all-time low. And regardless, the things I've outlined above have never been addressed and you guys basically refuse to talk to me about it. |
Describe your changes
PYTEST_MODEL_PATH
environment variable (tests only)gpt4all.gpt4all
module /GPT4All
classctypes
related) in thegpt4all.pyllmodel
modulegpt4all.pyllmodel
module intest_pyllmodel.py
(focused on theLLModel
class)pyllmodel
modulegpt4all
moduleLLModel
classGPT4All
to make it more flexible:There are no API breaking changes.
Pytest Markers
pytest.ini
):models.json
or the embeddings model)test_backend.py
, on tests which call the C API. While other Python tests can ultimately call the backend, too, the idea is that these can be run after backend changes.pytest -m "not inference and not online"
Specifying Model Path with
PYTEST_MODEL_PATH
Tests now look for an environment variable
PYTEST_MODEL_PATH
which can be used to specify model folders. Example Linux:More details in
tests/__init__.py
in the docstring.Issue ticket number and link
None
Checklist before requesting a review
Demo
None
Steps to Reproduce
mostly:
pytest gpt4all-bindings/python
😉Notes
Not sure about everything I'll include in this one, might split it up further.