Skip to content

gpt4all-bindings: init at version 3.2.1 #340717

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 2 commits into
base: master
Choose a base branch
from

Conversation

litchipi
Copy link
Contributor

@litchipi litchipi commented Sep 9, 2024

Description of changes

Packaging request: #306217

Python library for the Gpt4all project

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@litchipi litchipi requested a review from natsukium as a code owner September 9, 2024 08:40
@github-actions github-actions bot added the 6.topic: python Python is a high-level, general-purpose programming language. label Sep 9, 2024
@litchipi
Copy link
Contributor Author

litchipi commented Sep 9, 2024

I am creating the PR as it's my first Python package in nixpkgs, so it may require a lot of fixups.
However the functional tests aren't totally over yet, I'm still validating that it really works (and not just the import gpt4all part)
Please be intransigent with this PR so I don't merge 💩 in the python modules

@litchipi
Copy link
Contributor Author

litchipi commented Sep 9, 2024

@polygon @drupol Feel free to also add yourself as maintainers of the package if you feel like it ! 😄

@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Sep 9, 2024
cuda ? false,
}:
let
basepkg = if cuda then gpt4all-cuda else gpt4all;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
basepkg = if cuda then gpt4all-cuda else gpt4all;

Instead, enable cuda through config.cudaSupport.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the condition inside the top-level/python-packages.nix file as if I get the gpt4all package through the derivation arguments, it clashes with the python library I'm trying to build.

setuptools,
wheel,
python,
cuda ? false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cuda ? false,

};
in
buildPythonPackage {
pname = "gpt4all-bindings";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pname = "gpt4all-bindings";
pname = "gpt4all";

Attribute names in python-packages.nix as well as pnames should match the library's name on PyPI, but be normalized according to PEP 0503. This means that characters should be converted to lowercase and . and _ should be replaced by a single - (foo-bar-baz instead of Foo__Bar.baz).

https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/python.section.md#contributing-guidelines-contributing-guidelines

pname = "gpt4all-bindings";
inherit (basepkg) src version;
sourceRoot = "${basepkg.src.name}/gpt4all-bindings/python";
pyproject = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pyproject = false;
pyproject = true;

A typical python package with setup.py.

https://github.com/nomic-ai/gpt4all/tree/main/gpt4all-bindings/python

sourceRoot = "${basepkg.src.name}/gpt4all-bindings/python";
pyproject = false;

patches = [ ./setup_fixup.patch ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setup.py adds some code inside it to copy library files inside a folder.
For this, it uses shutil.copy2 which fails if the destination file already exists, which it does for some of them
I modified the patch to only avoid this specific case.

Comment on lines 48 to 51
build-system = [
setuptools
wheel
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
build-system = [
setuptools
wheel
];
build-system = [ setuptools ];

Comment on lines 60 to 68
buildPhase = ''
python3 setup.py build
'';

installPhase = ''
mkdir -p $out/${python.sitePackages}/
cp -r gpt4all $out/${python.sitePackages}/gpt4all
'';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
buildPhase = ''
python3 setup.py build
'';
installPhase = ''
mkdir -p $out/${python.sitePackages}/
cp -r gpt4all $out/${python.sitePackages}/gpt4all
'';

'';

pythonImportsCheck = [ "gpt4all" ];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I enabled tests, and after removing those needing network connection to download a large LLM and do inference, it left me with 0 tests left to execute.
So I just let them disabled, and added a comment on why

pythonImportsCheck = [ "gpt4all" ];

meta = with lib; {
description = "GPT4All: Run Local LLMs on Any Device. Python bindings";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = "GPT4All: Run Local LLMs on Any Device. Python bindings";
description = "Run Local LLMs on Any Device";

https://nixos.org/manual/nixpkgs/unstable/#var-meta-description

@@ -5294,6 +5294,8 @@ self: super: with self; {

gpt-2-simple = callPackage ../development/python-modules/gpt-2-simple { };

gpt4all-bindings = callPackage ../development/python-modules/gpt4all-bindings { };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gpt4all-bindings = callPackage ../development/python-modules/gpt4all-bindings { };
gpt4all = callPackage ../development/python-modules/gpt4all { };

Signed-off-by: Litchi Pi <litchi.pi@proton.me>
@litchipi
Copy link
Contributor Author

Addressed the comments, rebased and squashed into a clean commit

@ofborg ofborg bot removed 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Sep 13, 2024
@litchipi
Copy link
Contributor Author

@natsukium Any more comments on this PR I should address ? :-)

Signed-off-by: Litchi Pi <litchi.pi@proton.me>
@litchipi
Copy link
Contributor Author

ping

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 2, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: python Python is a high-level, general-purpose programming language. 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants