python3Packages.unsloth: 2026.3.8 -> 2026.4.1 (#506250)

This commit is contained in:
Gaétan Lepage
2026-04-06 23:02:53 +00:00
committed by GitHub
5 changed files with 126 additions and 64 deletions
@@ -5,35 +5,33 @@
# build-system
setuptools,
setuptools-scm,
# dependencies
accelerate,
datasets,
packaging,
rich,
transformers,
}:
buildPythonPackage rec {
buildPythonPackage (finalAttrs: {
pname = "trl";
version = "0.27.0";
version = "0.24.0";
pyproject = true;
src = fetchFromGitHub {
owner = "huggingface";
repo = "trl";
tag = "v${version}";
hash = "sha256-NEvIWrirHqcLJpyA894NgNFPn/Svg+ND/xDMIRHW8d0=";
tag = "v${finalAttrs.version}";
hash = "sha256-t0wOuEKlcZzFlQeS4PYHykFsz+43hYc0gJ9u4emr8HI=";
};
build-system = [
setuptools
setuptools-scm
];
build-system = [ setuptools ];
dependencies = [
accelerate
datasets
packaging
rich
transformers
];
@@ -46,8 +44,8 @@ buildPythonPackage rec {
meta = {
description = "Train transformer language models with reinforcement learning";
homepage = "https://github.com/huggingface/trl";
changelog = "https://github.com/huggingface/trl/releases/tag/${src.tag}";
changelog = "https://github.com/huggingface/trl/releases/tag/${finalAttrs.src.tag}";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ hoh ];
};
}
})
@@ -9,71 +9,72 @@
# dependencies
docstring-parser,
rich,
shtab,
typeguard,
typing-extensions,
# tests
attrs,
flax,
jax,
ml-collections,
msgspec,
omegaconf,
pydantic,
pytestCheckHook,
torch,
shtab,
universal-pathlib,
}:
buildPythonPackage (finalAttrs: {
pname = "tyro";
version = "1.0.10";
version = "1.0.12";
pyproject = true;
src = fetchFromGitHub {
owner = "brentyi";
repo = "tyro";
tag = "v${finalAttrs.version}";
hash = "sha256-k8f0eSeBBCROSsf7WooapDIFoy1G4Guxpbb7eNbj6ps=";
hash = "sha256-e4LIJzZ7lIkvhqbOz/EGHgPo9ri1HNiMp0j+I1S0/J4=";
};
build-system = [ hatchling ];
dependencies = [
docstring-parser
rich
shtab
typeguard
typing-extensions
];
# Upstream's neural-network integration tests are optional and skipped when
# flax/torch are unavailable, so keep the lightweight dev extras only.
nativeCheckInputs = [
attrs
flax
jax
ml-collections
msgspec
omegaconf
pydantic
pytestCheckHook
torch
shtab
universal-pathlib
];
disabledTests = lib.optionals (pythonAtLeast "3.13") [
# Bash path completion relies on the programmable-completion builtin `compgen`,
# which is unavailable in the stdenv build shell.
"test_bash_path_completion_marker"
disabledTests =
lib.optionals (pythonAtLeast "3.13") [
# The bash path-completion functional test still returns no file
# completions in the Nix build environment.
"test_bash_path_completion_marker"
]
++ lib.optionals (pythonAtLeast "3.14") [
# Upstream checks that the literal substring `bc` never appears in the
# help text, but under Nix the `python -m pytest` runner path can include
# that substring in the store hash used for `sys.argv[0]`.
"test_suppress_subcommand"
];
# In Nix builds, the long `python -m pytest` argv[0] path gets line-wrapped in
# argparse error output, splitting `class-b` and `)` so this literal-match fails.
"test_similar_arguments_subcommands_multiple_contains_match"
# Same wrapped-output literal-match issue as above for the cascading-args variant.
"test_similar_arguments_subcommands_multiple_contains_match_cascading"
];
# Keep argparse help output on a single line where possible so the
# literal-output tests do not fail due to terminal line wrapping.
preCheck = ''
export COLUMNS=200
export LINES=200
'';
pythonImportsCheck = [ "tyro" ];
@@ -11,30 +11,42 @@
accelerate,
cut-cross-entropy,
datasets,
filelock,
hf-transfer,
huggingface-hub,
msgspec,
numpy,
packaging,
peft,
pillow,
protobuf,
psutil,
regex,
sentencepiece,
torch,
torchao,
triton,
tqdm,
transformers,
trl,
tyro,
typing-extensions,
# tests
cudaPackages,
python,
}:
buildPythonPackage (finalAttrs: {
pname = "unsloth-zoo";
version = "2026.3.4";
version = "2026.4.2";
pyproject = true;
# no tags on GitHub
src = fetchPypi {
pname = "unsloth_zoo";
inherit (finalAttrs) version;
hash = "sha256-24w8UV5cLG5XWrU73xfmg+Jk32zl+QSPdqXLzMtmP1E=";
hash = "sha256-l0OTaZjPrNnrxVYIfZcf6pYr1tJS9EGj+iguU6S+D28=";
};
postPatch = ''
@@ -47,14 +59,11 @@ buildPythonPackage (finalAttrs: {
"setuptools-scm"
'';
# pyproject.toml requires an obsolete version of protobuf,
# but it is not used.
# Upstream issue: https://github.com/unslothai/unsloth-zoo/pull/68
# Upstream constrains datasets/torch more tightly than the versions
# currently shipped in nixpkgs, but the package still builds and works with
# the newer dependency set here.
pythonRelaxDeps = [
"datasets"
"protobuf"
"transformers"
"trl"
"torch"
];
@@ -72,29 +81,59 @@ buildPythonPackage (finalAttrs: {
accelerate
cut-cross-entropy
datasets
filelock
hf-transfer
huggingface-hub
msgspec
numpy
packaging
peft
pillow
protobuf
psutil
regex
sentencepiece
torch
torchao
triton
tqdm
transformers
trl
tyro
typing-extensions
];
# No tests
doCheck = false;
pythonImportsCheck = [ "unsloth_zoo" ];
# Importing touches torch.cuda at module import time and queries GPU memory.
dontUsePythonImportsCheck = true;
# Cover the import path on GPU-enabled runners instead of pure builders.
passthru.gpuCheck =
(cudaPackages.writeGpuTestPython.override { python3Packages = python.pkgs; }
{
libraries = ps: [ ps.unsloth-zoo ];
}
''
import torch
assert torch.cuda.is_available(), "CUDA is not available"
assert torch.ones(1, device="cuda").is_cuda
import unsloth_zoo # noqa: F401
from unsloth_zoo.device_type import DEVICE_COUNT, DEVICE_TYPE
assert DEVICE_TYPE == "cuda", DEVICE_TYPE
assert DEVICE_COUNT > 0, DEVICE_COUNT
print(f"Unsloth Zoo detected {DEVICE_COUNT} CUDA device(s)")
''
).gpuCheck;
meta = {
description = "Utils for Unsloth";
homepage = "https://github.com/unslothai/unsloth_zoo";
license = lib.licenses.mit;
license = lib.licenses.lgpl3Plus;
maintainers = with lib.maintainers; [ hoh ];
};
})
@@ -21,17 +21,3 @@ index 8c4404c..dc1666f 100644
try:
print("🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.")
except:
diff --git a/unsloth_zoo/device_type.py b/unsloth_zoo/device_type.py
index 11136fb..8f8dafc 100644
--- a/unsloth_zoo/device_type.py
+++ b/unsloth_zoo/device_type.py
@@ -209,6 +209,9 @@ def get_device_type():
return "cuda"
elif hasattr(torch, "xpu") and torch.xpu.is_available():
return "xpu"
+ else:
+ # Allow import during tests
+ return None
# Check torch.accelerator
if hasattr(torch, "accelerator"):
if not torch.accelerator.is_available():
@@ -11,6 +11,7 @@
bitsandbytes,
numpy,
packaging,
psutil,
torch,
unsloth-zoo,
xformers,
@@ -53,16 +54,40 @@ in
buildPythonPackage (finalAttrs: {
pname = "unsloth";
version = "2026.3.8";
version = "2026.4.1";
pyproject = true;
# Tags on the GitHub repo don't match
src = fetchPypi {
pname = "unsloth";
inherit (finalAttrs) version;
hash = "sha256-2HXsaYhsMxNEm6ctKDZDrA9MY/fUKhAo0EPYC5RwBNc=";
hash = "sha256-RGpVxrcFzKbHxV7o0/OYaADo/Pqxx/c+FaxcV05gHGU=";
};
postPatch = ''
substituteInPlace pyproject.toml \
--replace-fail 'requires = ["setuptools==80.9.0", "setuptools-scm==9.2.0"]' \
'requires = ["setuptools", "setuptools-scm"]'
# Upstream's datasets guard says only 4.4.0 and 4.4.1 recurse, but the
# current check blocks the whole 4.4.0 .. 4.5.0 range. Narrow it to the
# versions the upstream comment actually calls out.
substituteInPlace unsloth/import_fixes.py \
--replace-fail 'if (datasets_version <= Version("4.5.0")) and (' \
'if (datasets_version <= Version("4.4.1")) and ('
# Strip AGPL-licensed CLI, Studio, and grouped-GEMM sources from the
# Apache-licensed Python package.
rm -rf \
unsloth_cli \
studio \
unsloth/kernels/moe \
COPYING
# Drop the entry point after removing the CLI package above.
sed -i '/^\[project\.scripts\]/,/^$/d' pyproject.toml
'';
build-system = [
setuptools
setuptools-scm
@@ -72,6 +97,7 @@ buildPythonPackage (finalAttrs: {
bitsandbytes
numpy
packaging
psutil
torch
unsloth-zoo
xformers
@@ -90,8 +116,7 @@ buildPythonPackage (finalAttrs: {
torchvision
];
# pyproject.toml requires an obsolete version of protobuf,
# but it is not used.
# pyproject.toml pins obsolete versions for several runtime deps.
# Upstream issue: https://github.com/unslothai/unsloth-zoo/pull/68
pythonRelaxDeps = [
"datasets"
@@ -100,6 +125,17 @@ buildPythonPackage (finalAttrs: {
"torch"
];
# Upstream currently lists CLI/studio dependencies as runtime requirements,
# but they are not part of the packaged library here.
pythonRemoveDeps = [
"tyro"
"wheel"
"typer"
"pydantic"
"pyyaml"
"nest-asyncio"
];
# The source repository contains no test
doCheck = false;
@@ -107,8 +143,8 @@ buildPythonPackage (finalAttrs: {
# NotImplementedError: Unsloth: No NVIDIA GPU found? Unsloth currently only supports GPUs!
dontUsePythonImportsCheck = true;
passthru.tests = {
qlora-train-and-merge =
passthru.tests = rec {
cuda =
# FIXME: Replace python3.pkgs with python3Packages once possible, as to unbeak splicing.
# Cf. https://github.com/NixOS/nixpkgs/pull/394838#issuecomment-3319287038
cudaPackages.writeGpuTestPython.override { python3Packages = python.pkgs; }
@@ -135,6 +171,8 @@ buildPythonPackage (finalAttrs: {
run_name="__main__"
)
'';
qlora-train-and-merge = cuda;
};
meta = {