From c0a36eaa2c735b151e51e98df542c5ba6a695ec6 Mon Sep 17 00:00:00 2001 From: Alan Date: Sun, 29 Mar 2026 12:03:47 +1100 Subject: [PATCH] made dependancies pure --- .envrc | 2 +- .gitignore | 1 + README.md | 12 ++++---- flake.lock | 61 +++++++++++++++++++++++++++++++++++++++ flake.nix | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 21 -------------- 6 files changed, 155 insertions(+), 27 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/.envrc b/.envrc index 1d953f4..3550a30 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use nix +use flake diff --git a/.gitignore b/.gitignore index 90eafaf..db3e93c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ unsloth_compiled_cache outputs_qwen35 +__marimo__ diff --git a/README.md b/README.md index aeba966..3364746 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,13 @@ ## Overview -### `shell.nix` -Provides a development environment compatible within Nix. It handles: -- Installing PyTorch optimized for AMD ROCm (`rocm7.2`). -- Installing `unsloth` and `unsloth-zoo` for efficient fine-tuning. -- Installing `marimo` and `ipython` as QOL. +### `flake.nix` +Provides a pure development environment via Nix Flakes. It handles: +- Configures Python 3.13 with ROCm support enabled. +- Provides PyTorch and specialized ML libraries (transformers, accelerate). +- Packages `unsloth` and `unsloth-zoo` with necessary patches for compatibility. +- Includes `marimo` and `ipython` for interactive development. +- Automatically managed via `direnv` (`use flake`) or `nix develop`. ### `train.py` A `marimo` script that executes the fine-tuning process: diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d95764d --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1774386573, + "narHash": "sha256-4hAV26quOxdC6iyG7kYaZcM3VOskcPUrdCQd/nx8obc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "46db2e09e1d3f113a13c0d7b81e2f221c63b8ce9", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0749bae --- /dev/null +++ b/flake.nix @@ -0,0 +1,85 @@ +{ + description = "Minimal example training a Qwen3.5 0.8B lora on AMD RYZEN AI MAX+ 395 APU"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = import nixpkgs { + inherit system; + config = { + allowUnfree = true; + rocmSupport = true; + }; + }; + + python = pkgs.python313.override { + packageOverrides = self: super: { + datasets = super.datasets.overridePythonAttrs (oldAttrs: rec { + version = "4.3.0"; + src = pkgs.fetchFromGitHub { + owner = "huggingface"; + repo = "datasets"; + tag = version; + hash = "sha256-3rDSHAMwoe9CkRLs3PDXSw2ONUrUWyBSZFpzk2C1A3A="; + }; + }); + unsloth-zoo = super.unsloth-zoo.overridePythonAttrs (oldAttrs: { + pythonImportsCheck = []; + }); + unsloth = super.unsloth.overridePythonAttrs (oldAttrs: { + dependencies = + oldAttrs.dependencies + ++ [ + super.pydantic + super.nest-asyncio + ]; + pythonRelaxDeps = + oldAttrs.pythonRelaxDeps + ++ [ + "trl" + ]; + postPatch = '' + # Relax setuptools version constraint in pyproject.toml + sed -i 's/setuptools==80\.9\.0/setuptools>=80.9/g' pyproject.toml || true + + # Relax setuptools-scm version constraint in pyproject.toml + sed -i 's/setuptools-scm==9\.2\.0/setuptools-scm>=9.2/g' pyproject.toml || true + ''; + }); + }; + }; + + pythonEnv = python.withPackages (ps: + with ps; [ + ## Base ML/DS libs + torch + torchvision + torchaudio + transformers + accelerate + + ## Unsloth + unsloth + + ## QOL + marimo + ipython + ]); + in { + devShell = pkgs.mkShell { + packages = [ + pythonEnv + ]; + }; + } + ); +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index c95210a..0000000 --- a/shell.nix +++ /dev/null @@ -1,21 +0,0 @@ -{nixpkgs ? import {}}: -nixpkgs.mkShell { - nativeBuildInputs = with nixpkgs; [ - ruff - python3 - ]; - - LD_LIBRARY_PATH = "${nixpkgs.stdenv.cc.cc.lib}/lib:${nixpkgs.zstd.out}/lib:${nixpkgs.zlib.out}/lib"; - shellHook = '' - if [[ ! -d ".venv" ]]; then - python -m venv .venv - source .venv/bin/activate - pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm7.2/ --upgrade --force-reinstall - pip install "unsloth[amd] @ git+https://github.com/unslothai/unsloth" - pip install "unsloth-zoo[main] @ git+https://github.com/unslothai/unsloth-zoo" - pip install marimo ipython - else - source .venv/bin/activate - fi - ''; -}