Skip to content

gguf-py : avoid requiring PySide6 for packaged scripts #13036

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

compilade
Copy link
Collaborator

@compilade compilade commented Apr 20, 2025

I'm using Nix devShells for my development, most often with nix develop .#default-extra.

Problem

I wanted to use gguf-dump with some model using the wrapper which that devShell puts in the $PATH, and was greeted with

$ gguf-dump --help
Traceback (most recent call last):
  File "/nix/store/l06dc60pbanrbm5ksvf0wh3n2q9blw4z-python3.12-gguf-0.0.0/bin/.gguf-dump-wrapped", line 6, in <module>
    from gguf.scripts import gguf_dump_entrypoint
  File "/nix/store/l06dc60pbanrbm5ksvf0wh3n2q9blw4z-python3.12-gguf-0.0.0/lib/python3.12/site-packages/gguf/scripts/__init__.py", line 9, in <module>
    from .gguf_editor_gui import main as gguf_editor_gui_entrypoint
  File "/nix/store/l06dc60pbanrbm5ksvf0wh3n2q9blw4z-python3.12-gguf-0.0.0/lib/python3.12/site-packages/gguf/scripts/gguf_editor_gui.py", line 15, in <module>
    from PySide6.QtWidgets import (
ModuleNotFoundError: No module named 'PySide6'

That should not be a fatal error, since gguf-dump doesn't require that module.

This is a problem likely introduced in #12930.

Note that this problem also happens when using pip install gguf in a venv.

Changes

  • Remove gguf-py/gguf/scripts/__init__.py and directly refer to the main functions of the scripts as their entrypoint in pyproject.toml (as suggested in gguf-py : avoid requiring PySide6 for packaged scripts #13036 (comment))
  • Add pyside6 to the python dependencies included in *-extra devShells
    • Its transitive dependencies are quite big, though (300 MB compressed). Hopefully that is fine with others who use the *-extra devShells
  • Update flake.lock
    • Because the version which is used by gguf_editor_gui is ^6.9, and 6.9.0 is relatively recent (and not in the previous version of nixpkgs in flake.lock)

Make sure to read the contributing guidelines before submitting a PR

- nix : add pyside6 as a python dependency to include it in *-extra shells
Flake lock file updates:

• Updated input 'flake-parts':
    'github:hercules-ci/flake-parts/506278e768c2a08bec68eb62932193e341f55c90?narHash=sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS%2Bb4tfNFCwE%3D' (2024-11-01)
  → 'github:hercules-ci/flake-parts/c621e8422220273271f52058f618c94e405bb0f5?narHash=sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY%3D' (2025-04-01)
• Updated input 'flake-parts/nixpkgs-lib':
    'https://github.com/NixOS/nixpkgs/archive/cc2f28000298e1269cea6612cd06ec9979dd5d7f.tar.gz?narHash=sha256-lXvH/vOfb4aGYyvFmZK/HlsNsr/0CVWlwYvo2rxJk3s%3D' (2024-11-01)
  → 'github:nix-community/nixpkgs.lib/e4822aea2a6d1cdd36653c134cacfd64c97ff4fa?narHash=sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc%3D' (2025-03-30)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/23e89b7da85c3640bbc2173fe04f4bd114342367?narHash=sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w%3D' (2024-11-19)
  → 'github:NixOS/nixpkgs/b024ced1aac25639f8ca8fdfc2f8c4fbd66c48ef?narHash=sha256-fusHbZCyv126cyArUwwKrLdCkgVAIaa/fQJYFlCEqiU%3D' (2025-04-17)
@compilade compilade added nix Issues specific to consuming flake.nix, or generally concerned with ❄ Nix-based llama.cpp deployment bugfix fixes an issue or bug python python script changes labels Apr 20, 2025
@compilade compilade requested a review from CISC April 20, 2025 20:39
@github-actions github-actions bot added the devops improvements to build systems and github actions label Apr 20, 2025
@CISC
Copy link
Collaborator

CISC commented Apr 21, 2025

$ gguf-dump --help
Traceback (most recent call last):
  File "/nix/store/l06dc60pbanrbm5ksvf0wh3n2q9blw4z-python3.12-gguf-0.0.0/bin/.gguf-dump-wrapped", line 6, in <module>
    from gguf.scripts import gguf_dump_entrypoint
  File "/nix/store/l06dc60pbanrbm5ksvf0wh3n2q9blw4z-python3.12-gguf-0.0.0/lib/python3.12/site-packages/gguf/scripts/__init__.py", line 9, in <module>
    from .gguf_editor_gui import main as gguf_editor_gui_entrypoint
  File "/nix/store/l06dc60pbanrbm5ksvf0wh3n2q9blw4z-python3.12-gguf-0.0.0/lib/python3.12/site-packages/gguf/scripts/gguf_editor_gui.py", line 15, in <module>
    from PySide6.QtWidgets import (
ModuleNotFoundError: No module named 'PySide6'

Interesting, so this is clearly a problem with the way the entrypoints are all made from the same __init__.py, which perhaps is not ideal anyway? Is there a better/simpler way to define them?

* Add `pyside6` to the python dependencies included in `*-extra` devShells
  * Its transitive dependencies are quite big, though (300 MB compressed). Hopefully that is fine with others who use the `*-extra` devShells

Hmmm, yeah, let's hope so.

@CISC
Copy link
Collaborator

CISC commented Apr 21, 2025

Interesting, so this is clearly a problem with the way the entrypoints are all made from the same __init__.py, which perhaps is not ideal anyway? Is there a better/simpler way to define them?

So, to answer my own question, I just tried emptying __init__.py, and defining the script entrypoints as the following instead:

[tool.poetry.scripts]
gguf-convert-endian = "gguf.scripts.gguf_convert_endian:main"
gguf-dump = "gguf.scripts.gguf_dump:main"
gguf-set-metadata = "gguf.scripts.gguf_set_metadata:main"
gguf-new-metadata = "gguf.scripts.gguf_new_metadata:main"
gguf-editor-gui = "gguf.scripts.gguf_editor_gui:main"

Built and installed the package and problem seems to be solved, know why it wasn't done like this to begin with?

@CISC
Copy link
Collaborator

CISC commented Apr 21, 2025

@compilade Looking at the commit history I think it sort of just evolved into this without any serious consideration as to why, I think clearing __init__.py and pointing directly to the scripts' main function is the solution.

Let me know if you need me to tag the release later.

…eded

Implicit namespaces are supported since Python 3.3 (https://peps.python.org/pep-0420/),
and the entrypoints in pyproject.toml can directly refer to the main functions.
@compilade
Copy link
Collaborator Author

@CISC I went ahead and changed gguf-py/pyproject.toml as you suggest and removed gguf-py/gguf/scripts/__init__.py because it's not really needed since implicit namespaces added in https://peps.python.org/pep-0420/ (in Python 3.3).

I've tested the scripts after building, and they work fine even when PySide6 is not installed (apart from the gguf-editor-gui script, of course, which requires it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix fixes an issue or bug devops improvements to build systems and github actions nix Issues specific to consuming flake.nix, or generally concerned with ❄ Nix-based llama.cpp deployment python python script changes
Projects
None yet
2 participants