diff --git a/flake.lock b/flake.lock index e98110e..d2ba7f2 100644 --- a/flake.lock +++ b/flake.lock @@ -3,16 +3,15 @@ "a1111-src": { "flake": false, "locked": { - "lastModified": 1693456714, - "narHash": "sha256-V16VkOq0+wea4zbfeKBLAQBth022ZkpG8lh0p9u4txs=", + "lastModified": 1699030214, + "narHash": "sha256-UQ2cJ92JdSHOe0g5IkaCXPO0MYyWpLAcp6f8p+T6bxs=", "owner": "automatic1111", "repo": "stable-diffusion-webui", - "rev": "5ef669de080814067961f28357256e8fe27544f4", + "rev": "4afaaf8a020c1df457bcf7250cb1c7f609699fa7", "type": "github" }, "original": { "owner": "automatic1111", - "ref": "v1.6.0", "repo": "stable-diffusion-webui", "type": "github" } @@ -207,9 +206,43 @@ "hercules-ci-effects": "hercules-ci-effects", "invokeai-src": "invokeai-src", "nixpkgs": "nixpkgs_2", + "sd-src": "sd-src", + "sgm-src": "sgm-src", "textgen-src": "textgen-src" } }, + "sd-src": { + "flake": false, + "locked": { + "lastModified": 1679711060, + "narHash": "sha256-yEtrz/JTq53JDI4NZI26KsD8LAgiViwiNaB2i1CBs/I=", + "owner": "Stability-AI", + "repo": "stablediffusion", + "rev": "cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf", + "type": "github" + }, + "original": { + "owner": "Stability-AI", + "repo": "stablediffusion", + "type": "github" + } + }, + "sgm-src": { + "flake": false, + "locked": { + "lastModified": 1692287310, + "narHash": "sha256-Gvpjfv5hFEeQl67OeTXVhiB4zvgV5UZ5B/ar4rBW0d0=", + "owner": "Stability-AI", + "repo": "generative-models", + "rev": "477d8b9a7730d9b2e92b326a770c0420d00308c9", + "type": "github" + }, + "original": { + "owner": "Stability-AI", + "repo": "generative-models", + "type": "github" + } + }, "textgen-src": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 7d45c55..bc83149 100644 --- a/flake.nix +++ b/flake.nix @@ -7,11 +7,19 @@ description = "A Nix Flake that makes AI reproducible and easy to run"; inputs = { + sgm-src = { + url = "github:Stability-AI/generative-models"; + flake = false; + }; nixpkgs = { url = "github:NixOS/nixpkgs/nixos-unstable"; }; a1111-src = { - url = "github:automatic1111/stable-diffusion-webui/v1.6.0"; + url = "github:automatic1111/stable-diffusion-webui"; + flake = false; + }; + sd-src = { + url = "github:Stability-AI/stablediffusion"; flake = false; }; invokeai-src = { diff --git a/overlays/python/default.nix b/overlays/python/default.nix index 2132661..373fbd2 100644 --- a/overlays/python/default.nix +++ b/overlays/python/default.nix @@ -14,6 +14,8 @@ lib: { wandb = relaxProtobuf (prev.wandb.overridePythonAttrs { doCheck = false; }); + anyio = prev.anyio.overridePythonAttrs { doCheck = false; dontUsePytestCheck = true;}; + mocket = prev.mocket.overridePythonAttrs { doCheck = false; dontUsePytestCheck = true;}; markdown-it-py = prev.markdown-it-py.overrideAttrs (old: { nativeBuildInputs = old.nativeBuildInputs ++ [ final.pythonRelaxDepsHook ]; pythonRelaxDeps = [ "linkify-it-py" ]; diff --git a/packages/blendmodes/default.nix b/packages/blendmodes/default.nix new file mode 100644 index 0000000..53b6a9e --- /dev/null +++ b/packages/blendmodes/default.nix @@ -0,0 +1,26 @@ +# WARNING: This file was automatically generated. You should avoid editing it. +# If you run pynixify again, the file will be either overwritten or +# deleted, and you will lose the changes you made to it. + +{ aenum, buildPythonPackage, deprecation, fetchPypi, lib, numpy, pillow }: + +buildPythonPackage rec { + pname = "blendmodes"; + version = "2022"; + + src = fetchPypi { + inherit pname version; + sha256 = "00zx3025rlpgdsy78znm9xqml3kfd41sq34gjss391qfx70z2s4k"; + }; + + propagatedBuildInputs = [ pillow aenum deprecation numpy ]; + + # TODO FIXME + doCheck = false; + + meta = with lib; { + description = + "Use this module to apply a number of blending modes to a background and foreground image"; + homepage = "https://github.com/FHPythonUtils/BlendModes"; + }; +} diff --git a/packages/gradio-client/default.nix b/packages/gradio-client/default.nix index b2631c6..cb7930b 100644 --- a/packages/gradio-client/default.nix +++ b/packages/gradio-client/default.nix @@ -15,13 +15,13 @@ buildPythonPackage rec { pname = "gradio-client"; - version = "0.2.5"; + version = "0.7.0"; format = "pyproject"; src = fetchPypi { pname = "gradio_client"; inherit version; - hash = "sha256-GiTdegmXbbcP0yzbVRK297FcGghPMQtfazAhyXlNkKQ="; + hash = "sha256-+MNVJzfaWocluz4b6hD3e703gj8NeU1BDphe9xJyCaw="; }; nativeBuildInputs = [ diff --git a/packages/gradio/default.nix b/packages/gradio/default.nix index 19732ca..874b977 100644 --- a/packages/gradio/default.nix +++ b/packages/gradio/default.nix @@ -4,13 +4,10 @@ , pythonOlder , writeTextFile , setuptools -, altair , analytics-python -, aiofiles , aiohttp , fastapi , ffmpy -, gradio-client , markdown-it-py , linkify-it-py , mdit-py-plugins @@ -33,11 +30,9 @@ , pytest-asyncio , mlflow , huggingface-hub -, transformers -, wandb +, transformers , wandb , respx , scikitimage -, semantic-version , shap , ipython , hatchling @@ -45,12 +40,11 @@ , hatch-fancy-pypi-readme , pytestCheckHook , websockets -, pythonRelaxDepsHook }: buildPythonPackage rec { pname = "gradio"; - version = "3.31.0"; + version = "3.41.2"; disabled = pythonOlder "3.7"; format = "pyproject"; @@ -58,24 +52,18 @@ buildPythonPackage rec { # and its releases are also more frequent than github tags src = fetchPypi { inherit pname version; - sha256 = "sha256-4YIhhj64daLOfOqmzsJC8SaNym/OOwe/5fpb0BA8N90="; - }; + sha256 = "sha256-lcYrUEGVq+M2PQFRZ86Eis3he3W4lKeaLeeMz8/YLLI="; }; - pythonRelaxDeps = [ "mdit-py-plugins" ]; nativeBuildInputs = [ hatchling hatch-requirements-txt hatch-fancy-pypi-readme - pythonRelaxDepsHook ]; propagatedBuildInputs = [ - altair - aiohttp - aiofiles analytics-python + aiohttp fastapi ffmpy - gradio-client matplotlib numpy orjson @@ -91,17 +79,20 @@ buildPythonPackage rec { fsspec httpx pydantic - semantic-version websockets markdown-it-py ] ++ markdown-it-py.optional-dependencies.plugins - ++ markdown-it-py.optional-dependencies.linkify; + ++ markdown-it-py.optional-dependencies.linkify; postPatch = '' # Unpin h11, as its version was only pinned to aid dependency resolution. # Basically a revert of https://github.com/gradio-app/gradio/pull/1680 substituteInPlace requirements.txt \ --replace "h11<0.13,>=0.11" "" + substituteInPlace requirements.txt \ + --replace "# required for fastapi forms" "" + substituteInPlace requirements-oauth.txt \ + --replace "# required for starlette SessionMiddleware" "" ''; # TODO FIXME diff --git a/packages/k_diffusion/default.nix b/packages/k_diffusion/default.nix new file mode 100644 index 0000000..48d3042 --- /dev/null +++ b/packages/k_diffusion/default.nix @@ -0,0 +1,41 @@ +# WARNING: This file was automatically generated. You should avoid editing it. +# If you run pynixify again, the file will be either overwritten or +# deleted, and you will lose the changes you made to it. + +{ accelerate, buildPythonPackage, clip-anytorch, einops, fetchPypi, jsonmerge +, kornia, lib, pillow, resize-right, scikit-image, scipy, torch, torchdiffeq +, torchvision, tqdm, wandb, clean-fid, torchsde }: + +buildPythonPackage rec { + pname = "k-diffusion"; + version = "0.1.0"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-nsPzKQCtuyvCr/biuOVKx0ZyWfV1qU2m1z4aeoRhSPw="; + }; + + propagatedBuildInputs = [ + accelerate + clip-anytorch + einops + jsonmerge + kornia + pillow + resize-right + scikit-image + scipy + torch + torchdiffeq + torchvision + torchsde + tqdm + wandb + clean-fid + ]; + + # TODO FIXME + doCheck = false; + + meta = with lib; { }; +} diff --git a/packages/openclip/default.nix b/packages/openclip/default.nix new file mode 100644 index 0000000..4ff5880 --- /dev/null +++ b/packages/openclip/default.nix @@ -0,0 +1,47 @@ +# WARNING: This file was automatically generated. You should avoid editing it. +# If you run pynixify again, the file will be either overwritten or +# deleted, and you will lose the changes you made to it. + +{ buildPythonPackage +, fetchFromGitHub +, ftfy +, huggingface-hub +, lib +, regex +, sentencepiece +, torch +, torchvision +, tqdm +, protobuf +}: + +buildPythonPackage rec { + pname = "open_clip"; + version = "2.20.0"; + + src = fetchFromGitHub { + owner = "mlfoundations"; + repo = "open_clip"; + rev = "v2.20.0"; + sha256 = "sha256-Ca4oi2LqleIFAGBJB7YIi4nXe2XhOP6ErDFXgXtJLxM="; + }; + + propagatedBuildInputs = [ + torch + torchvision + regex + ftfy + tqdm + huggingface-hub + sentencepiece + protobuf + ]; + + # TODO FIXME + doCheck = false; + + meta = with lib; { + description = "OpenCLIP"; + homepage = "https://github.com/mlfoundations/open_clip"; + }; +} diff --git a/packages/opencliptorch/default.nix b/packages/opencliptorch/default.nix new file mode 100644 index 0000000..3cc245b --- /dev/null +++ b/packages/opencliptorch/default.nix @@ -0,0 +1,46 @@ +# WARNING: This file was automatically generated. You should avoid editing it. +# If you run pynixify again, the file will be either overwritten or +# deleted, and you will lose the changes you made to it. + +{ buildPythonPackage +, fetchFromGitHub +, ftfy +, huggingface-hub +, lib +, regex +, sentencepiece +, torch +, torchvision +, tqdm +, protobuf +, fetchPypi +}: + +buildPythonPackage rec { + pname = "open-clip-torch"; + version = "2.7.0"; + format = "setuptools"; + + + src = fetchTarball { + url = "https://files.pythonhosted.org/packages/eb/e5/1f5469f53ea8b09661984fedf41cd55b7585e2e0c7a2d245255ab0fb385e/open_clip_torch-2.7.0.tar.gz"; + sha256 = "sha256:16133ym9fzcv8a0h84213hsy083sf0ali5qqfsgyadm28x5w4avi"; + }; + + propagatedBuildInputs = [ + torch + torchvision + regex + ftfy + tqdm + huggingface-hub + sentencepiece + protobuf + ]; + + # TODO FIXME + doCheck = false; + + meta = with lib; { + }; +} diff --git a/packages/tomesd/default.nix b/packages/tomesd/default.nix new file mode 100644 index 0000000..26e2cec --- /dev/null +++ b/packages/tomesd/default.nix @@ -0,0 +1,17 @@ +{ buildPythonPackage, fetchPypi, lib, torch, numpy, pyre-extensions, pythonRelaxDepsHook, which }: + +buildPythonPackage rec { + pname = "tomesd"; + version = "0.1.3"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-Fbui6VL0ZDyDVZUeiS/akY3cy9/yI43DaNQr0Hj87ck="; + }; + nativeBuildInputs = [ pythonRelaxDepsHook which ]; + + # TODO FIXME + doCheck = false; + + meta = with lib; { }; +} diff --git a/packages/xformers/default.nix b/packages/xformers/default.nix new file mode 100644 index 0000000..f0a2eae --- /dev/null +++ b/packages/xformers/default.nix @@ -0,0 +1,23 @@ +# WARNING: This file was automatically generated. You should avoid editing it. +# If you run pynixify again, the file will be either overwritten or +# deleted, and you will lose the changes you made to it. + +{ buildPythonPackage, fetchPypi, lib, torch, numpy, pyre-extensions, pythonRelaxDepsHook, which }: + +buildPythonPackage rec { + pname = "xformers"; + version = "0.0.16"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-ksfwVWpo9EhkkmkbP1ZxQO4ZK1Y9kEGFtmabH4u4rlM="; + }; + nativeBuildInputs = [ pythonRelaxDepsHook which ]; + pythonRelaxDeps = [ "pyre-extensions" ]; + propagatedBuildInputs = [ torch numpy pyre-extensions /*triton*/ ]; + + # TODO FIXME + doCheck = false; + + meta = with lib; { }; +} diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index bee3423..a4ab4f3 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -10,7 +10,8 @@ in commonOverlays = [ overlays.python-fixPackages (l.overlays.callManyPackages [ - ../../packages/mediapipe + ../../packages/k_diffusion + ../../packages/openclip ../../packages/safetensors ../../packages/easing-functions ../../packages/dynamicprompts @@ -18,8 +19,8 @@ in ../../packages/fastapi ../../packages/fastapi-events ../../packages/fastapi-socketio - ../../packages/starlette ../../packages/pytorch-lightning + ../../packages/starlette ../../packages/compel ../../packages/taming-transformers-rom1504 ../../packages/albumentations @@ -43,6 +44,14 @@ in ../../packages/getpass-asterisk ../../packages/mediapipe ../../packages/python-engineio + ../../packages/lpips + ../../packages/blip + ../../packages/gradio + ../../packages/gradio-client + ../../packages/analytics-python + ../../packages/tomesd + ../../packages/blendmodes + ../../packages/xformers ]) (final: prev: lib.mapAttrs (_: pkg: pkg.overrideAttrs (old: { @@ -74,7 +83,7 @@ in src = inputs.a1111-src; - mkAutomatic1111Variant = args: pkgs.callPackage ./package.nix ({ inherit src; } // args); + mkAutomatic1111Variant = args: pkgs.callPackage ./package.nix ({ inherit src; sd-src = inputs.sd-src; sgm-src = inputs.sgm-src; } // args); in { packages = { a1111-nvidia = mkAutomatic1111Variant { @@ -83,7 +92,7 @@ in }; legacyPackages = { a1111-amd = throw '' - BREEEE AMD?! + AMD not done yet. ''; }; }; diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index 85ab2b3..f7d6130 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -1,106 +1,174 @@ -{ python3Packages +{ python3Packages, +sd-src, +sgm-src, # misc -, lib -, src + lib + , src # extra deps }: +let + submodel = pkg: python3Packages.${pkg} + "/lib/python3.10/site-packages"; + taming-transformers = submodel "taming-transformers-rom1504"; + k_diffusion = submodel "k_diffusion"; + codeformer = (submodel "codeformer") + "/codeformer"; + blip = (submodel "blip") + "/blip"; + in python3Packages.buildPythonPackage { pname = "Automatic1111"; - format = "pyproject"; + format = "other"; version = "v1.6.0"; inherit src; propagatedBuildInputs = with python3Packages; [ - semver - mediapipe - numpy - torchsde - uvicorn - pyperclip - invisible-watermark - fastapi - fastapi-events - fastapi-socketio - timm - scikit-image - controlnet-aux - compel - python-dotenv - uvloop - watchfiles - httptools - websockets - dnspython - albumentations - opencv4 - pudb - imageio - imageio-ffmpeg - compel - npyscreen - pytorch-lightning - protobuf - omegaconf - test-tube - einops - taming-transformers-rom1504 - torch-fidelity - torchmetrics - transformers - kornia - k-diffusion - picklescan - diffusers - pypatchmatch - realesrgan - pillow - send2trash - flask - flask-cors - dependency-injector - gfpgan - eventlet - clipseg - getpass-asterisk - safetensors - datasets - accelerate - huggingface-hub - easing-functions - dynamicprompts - torchvision - test-tube - ]; + k_diffusion + inflection + gdown + altair + aiofiles + openclip + semver + numpy + torchsde + uvicorn + pyperclip + invisible-watermark + fastapi + fastapi-events + fastapi-socketio + timm + scikit-image + controlnet-aux + compel + python-dotenv + uvloop + watchfiles + httptools + websockets + dnspython + albumentations + opencv4 + pudb + imageio + imageio-ffmpeg + compel + npyscreen + pytorch-lightning + protobuf + omegaconf + test-tube + einops + taming-transformers-rom1504 + torch-fidelity + torchmetrics + transformers + kornia + k-diffusion + picklescan + diffusers + pypatchmatch + realesrgan + pillow + send2trash + flask + flask-cors + dependency-injector + gfpgan + eventlet + clipseg + getpass-asterisk + safetensors + datasets + accelerate + huggingface-hub + easing-functions + dynamicprompts + torchvision + test-tube + lark + gradio + gradio-client + tomesd + piexif + blendmodes + xformers + python-multipart + ]; nativeBuildInputs = with python3Packages; [ pythonRelaxDepsHook pip ]; - pythonRemoveDeps = [ "clip" "pyreadline3" "flaskwebgui" "opencv-python" "fastapi-socketio" ]; + pythonRemoveDeps = [ "clip" "pyreadline3" "flaskwebgui" "opencv-python" ]; pythonRelaxDeps = [ "dnspython" "flask" "requests" "numpy" "pytorch-lightning" "torchsde" "uvicorn" "invisible-watermark" "accelerate" "scikit-image" "safetensors" "huggingface-hub" "torchvision" "test-tube" "fastapi" ]; - makeWrapperArgs = [ - '' --run 'ls .' - '' - # See note about consumer GPUs: - # https://docs.amd.com/bundle/ROCm-Deep-Learning-Guide-v5.4.3/page/Troubleshooting.html - " --set-default HSA_OVERRIDE_GFX_VERSION 10.3.0" - '' --run 'export INVOKEAI_ROOT="''${INVOKEAI_ROOT:-$HOME/.invokeai}"' '' - '' --run ' - if [[ ! -d "$INVOKEAI_ROOT" && "''${0##*/}" != invokeai-configure ]] - then - echo "State directory does not exist, running invokeai-configure" - if [[ "''${NIXIFIED_AI_NONINTERACTIVE:-0}" != 0 ]]; then - ${placeholder "out"}/bin/invokeai-configure --yes --skip-sd-weights - else - ${placeholder "out"}/bin/invokeai-configure - fi - fi - ' - '' - ]; - patchPhase = '' - #runHook prePatch - echo here - ''; + dontUsePytestCheck = true; + + doCheck = false; + + buildPhase = '' + runHook preBuild + mkdir -p dist + cp -r . $out + chmod -R +w $out + cd $out + + #replace dirs in paths_internal.py + #mkdir -p /var/lib/.webui + sed -i 's#os\.path\.join(script_path, "config_states")#os\.path\.join(data_path, "config_states")#' ./modules/paths_internal.py + #delete lines trying to pull git repos and setting up tests in launch.py + sed -i '28,43d' launch.py + + #firstly, we need to make launch.py runnable by adding python shebang + cat <<-EOF > exec_launch.py.unwrapped + $(echo "#!/usr/bin/python") + $(cat launch.py) + EOF + chmod +x exec_launch.py.unwrapped + + #creating wrapper around launch.py with PYTHONPATH correctly set + makeWrapper "$(pwd)/exec_launch.py.unwrapped" exec_launch.py \ + --set-default PYTHONPATH $PYTHONPATH + + mkdir $out/bin + pushd $out/bin + ln -s ../exec_launch.py launch.py + buck='$' #escaping $ inside shell inside shell is tricky + #next is an additional shell wrapper, which sets sensible default args for CLI + #additional arguments will be passed further + cat <<-EOF > flake-launch + #!/usr/bin/env bash + pushd $out #For some reason, fastapi only works when current workdir is set inside the repo + trap "popd" EXIT + + "$out/bin/launch.py" --skip-install "$buck{@}" + EOF + # below lie remnants of my attempt to make webui use similar paths as InvokeAI for models download + # additions of such options in upstream is a welcome sign, however they're mostly ignored and therefore useless + # TODO: check in 6 months, maybe it'll work + # For now, your best bet is to use ZFS dataset with dedup enabled or make symlinks after the fact + + #--codeformer-models-path "\$mp/codeformer" \ + #--gfpgan-models-path "\$mp/gfpgan" --esrgan-models-path "\$mp/esrgan" \ + #--bsrgan-models-path "\$mp/bsrgan" --realesrgan-models-path "\$mp/realesrgan" \ + #--clip-models-path "\$mp/clip" + chmod +x flake-launch + popd + + runHook postBuild + ''; + installPhase = '' + runHook preInstall + + rm -rf repositories/ + mkdir repositories + pushd repositories + ln -s ${sd-src}/ stable-diffusion-stability-ai + ln -s ${sgm-src}/ generative-models + ln -s ${taming-transformers}/ taming-transformers + ln -s ${k_diffusion}/ k-diffusion + ln -s ${codeformer}/ CodeFormer + ln -s ${blip}/ BLIP + popd + runHook postInstall + ''; meta = { description = "Fancy Web UI for Stable Diffusion"; homepage = "https://github.com/AUTOMATIC1111/stable-diffusion-webui"; - mainProgram = "stable-diffusion-webui"; + mainProgram = "flake-launch"; }; } diff --git a/starta1111.sh b/starta1111.sh new file mode 100755 index 0000000..a5fdb4d --- /dev/null +++ b/starta1111.sh @@ -0,0 +1 @@ +nix run .#a1111-nvidia -- --data-dir /home/denis/.webui --ckpt-dir /home/denis/.invokeai/autoimport/main --theme dark --medvram --no-half-vae --opt-sdp-attention --opt-split-attention --no-gradio-queue