Skip to content

Conversation

booxter
Copy link
Contributor

@booxter booxter commented Apr 17, 2024

Which issue is resolved by this Pull Request:
Resolves #814

Description of your changes:

Mocks were not effective for in-function local import symbols.

This patch moves the imports to the module scope, which fixes the suite for python3.9.

Since mlx is not present on Linux, we have to catch ImportError and fall back to Nones for mac-specific imports (which can then be mocked out in unit tests as needed).

Mocks were not effective for in-function local import symbols.

This patch moves the imports to the module scope, which fixes the suite
for python3.9.

Since mlx is not present on Linux, we have to catch ImportError and fall
back to Nones for mac-specific imports (which can then be mocked out in
unit tests as needed).

Closes #814
Signed-off-by: Ihar Hrachyshka <ihrachys@redhat.com>
@tiran
Copy link
Contributor

tiran commented Apr 17, 2024

I would prefer to keep the imports local. It speeds up start-up time of the CLI.

Please take a look at tests/test_lab_train.py:mock_mlx(). I added the function a while ago to solve a similar issue. Does the approach work for the other tests?

@booxter
Copy link
Contributor Author

booxter commented Apr 17, 2024

@tiran I will take a look at mock_mlx.

Do you have numbers on start-up slowdown? I don't have access to Mac to try it out, so I wonder how impactful this is...

@tiran
Copy link
Contributor

tiran commented Apr 17, 2024

I'm Linux-only, too.

I know that llama_cpp and torch imports made huge impact. My PR #674 speeded up ilab --help from 4.8s to 0.18s. I don't know how long mlx takes to import, though.

booxter pushed a commit to booxter/instructlab that referenced this pull request Apr 19, 2024
Test code was writing {} in the file but this results in an empty dict()
produced by json.load, which would later fail with KeyError('user') in
make_data.

The reason why this doesn't show up in the test runs is because
make_data is mocked out. This test bug was noticed while working on
another fix for the test suite where mocks were not effective [1].

While the test suite was not failing (because of mocks), it's still
better to inject data that conforms to loader expectations.

[1] instructlab#890

Signed-off-by: Ihar Hrachyshka <ihrachys@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unit tests fail with python < 3.11
3 participants