This commit is contained in:
Denis Manherz 2023-11-13 17:50:11 +01:00
parent b7b32cb6ea
commit f6d3580cae
14 changed files with 431 additions and 119 deletions

View file

@ -3,16 +3,15 @@
"a1111-src": { "a1111-src": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1693456714, "lastModified": 1699030214,
"narHash": "sha256-V16VkOq0+wea4zbfeKBLAQBth022ZkpG8lh0p9u4txs=", "narHash": "sha256-UQ2cJ92JdSHOe0g5IkaCXPO0MYyWpLAcp6f8p+T6bxs=",
"owner": "automatic1111", "owner": "automatic1111",
"repo": "stable-diffusion-webui", "repo": "stable-diffusion-webui",
"rev": "5ef669de080814067961f28357256e8fe27544f4", "rev": "4afaaf8a020c1df457bcf7250cb1c7f609699fa7",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "automatic1111", "owner": "automatic1111",
"ref": "v1.6.0",
"repo": "stable-diffusion-webui", "repo": "stable-diffusion-webui",
"type": "github" "type": "github"
} }
@ -207,9 +206,43 @@
"hercules-ci-effects": "hercules-ci-effects", "hercules-ci-effects": "hercules-ci-effects",
"invokeai-src": "invokeai-src", "invokeai-src": "invokeai-src",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_2",
"sd-src": "sd-src",
"sgm-src": "sgm-src",
"textgen-src": "textgen-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": { "textgen-src": {
"flake": false, "flake": false,
"locked": { "locked": {

View file

@ -7,11 +7,19 @@
description = "A Nix Flake that makes AI reproducible and easy to run"; description = "A Nix Flake that makes AI reproducible and easy to run";
inputs = { inputs = {
sgm-src = {
url = "github:Stability-AI/generative-models";
flake = false;
};
nixpkgs = { nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-unstable"; url = "github:NixOS/nixpkgs/nixos-unstable";
}; };
a1111-src = { 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; flake = false;
}; };
invokeai-src = { invokeai-src = {

View file

@ -14,6 +14,8 @@ lib: {
wandb = relaxProtobuf (prev.wandb.overridePythonAttrs { wandb = relaxProtobuf (prev.wandb.overridePythonAttrs {
doCheck = false; 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: { markdown-it-py = prev.markdown-it-py.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ final.pythonRelaxDepsHook ]; nativeBuildInputs = old.nativeBuildInputs ++ [ final.pythonRelaxDepsHook ];
pythonRelaxDeps = [ "linkify-it-py" ]; pythonRelaxDeps = [ "linkify-it-py" ];

View file

@ -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";
};
}

View file

@ -15,13 +15,13 @@
buildPythonPackage rec { buildPythonPackage rec {
pname = "gradio-client"; pname = "gradio-client";
version = "0.2.5"; version = "0.7.0";
format = "pyproject"; format = "pyproject";
src = fetchPypi { src = fetchPypi {
pname = "gradio_client"; pname = "gradio_client";
inherit version; inherit version;
hash = "sha256-GiTdegmXbbcP0yzbVRK297FcGghPMQtfazAhyXlNkKQ="; hash = "sha256-+MNVJzfaWocluz4b6hD3e703gj8NeU1BDphe9xJyCaw=";
}; };
nativeBuildInputs = [ nativeBuildInputs = [

View file

@ -4,13 +4,10 @@
, pythonOlder , pythonOlder
, writeTextFile , writeTextFile
, setuptools , setuptools
, altair
, analytics-python , analytics-python
, aiofiles
, aiohttp , aiohttp
, fastapi , fastapi
, ffmpy , ffmpy
, gradio-client
, markdown-it-py , markdown-it-py
, linkify-it-py , linkify-it-py
, mdit-py-plugins , mdit-py-plugins
@ -33,11 +30,9 @@
, pytest-asyncio , pytest-asyncio
, mlflow , mlflow
, huggingface-hub , huggingface-hub
, transformers , transformers , wandb
, wandb
, respx , respx
, scikitimage , scikitimage
, semantic-version
, shap , shap
, ipython , ipython
, hatchling , hatchling
@ -45,12 +40,11 @@
, hatch-fancy-pypi-readme , hatch-fancy-pypi-readme
, pytestCheckHook , pytestCheckHook
, websockets , websockets
, pythonRelaxDepsHook
}: }:
buildPythonPackage rec { buildPythonPackage rec {
pname = "gradio"; pname = "gradio";
version = "3.31.0"; version = "3.41.2";
disabled = pythonOlder "3.7"; disabled = pythonOlder "3.7";
format = "pyproject"; format = "pyproject";
@ -58,24 +52,18 @@ buildPythonPackage rec {
# and its releases are also more frequent than github tags # and its releases are also more frequent than github tags
src = fetchPypi { src = fetchPypi {
inherit pname version; inherit pname version;
sha256 = "sha256-4YIhhj64daLOfOqmzsJC8SaNym/OOwe/5fpb0BA8N90="; sha256 = "sha256-lcYrUEGVq+M2PQFRZ86Eis3he3W4lKeaLeeMz8/YLLI="; };
};
pythonRelaxDeps = [ "mdit-py-plugins" ];
nativeBuildInputs = [ nativeBuildInputs = [
hatchling hatchling
hatch-requirements-txt hatch-requirements-txt
hatch-fancy-pypi-readme hatch-fancy-pypi-readme
pythonRelaxDepsHook
]; ];
propagatedBuildInputs = [ propagatedBuildInputs = [
altair
aiohttp
aiofiles
analytics-python analytics-python
aiohttp
fastapi fastapi
ffmpy ffmpy
gradio-client
matplotlib matplotlib
numpy numpy
orjson orjson
@ -91,7 +79,6 @@ buildPythonPackage rec {
fsspec fsspec
httpx httpx
pydantic pydantic
semantic-version
websockets websockets
markdown-it-py markdown-it-py
] ++ markdown-it-py.optional-dependencies.plugins ] ++ markdown-it-py.optional-dependencies.plugins
@ -102,6 +89,10 @@ buildPythonPackage rec {
# Basically a revert of https://github.com/gradio-app/gradio/pull/1680 # Basically a revert of https://github.com/gradio-app/gradio/pull/1680
substituteInPlace requirements.txt \ substituteInPlace requirements.txt \
--replace "h11<0.13,>=0.11" "" --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 # TODO FIXME

View file

@ -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; { };
}

View file

@ -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";
};
}

View file

@ -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; {
};
}

View file

@ -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; { };
}

View file

@ -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; { };
}

View file

@ -10,7 +10,8 @@ in
commonOverlays = [ commonOverlays = [
overlays.python-fixPackages overlays.python-fixPackages
(l.overlays.callManyPackages [ (l.overlays.callManyPackages [
../../packages/mediapipe ../../packages/k_diffusion
../../packages/openclip
../../packages/safetensors ../../packages/safetensors
../../packages/easing-functions ../../packages/easing-functions
../../packages/dynamicprompts ../../packages/dynamicprompts
@ -18,8 +19,8 @@ in
../../packages/fastapi ../../packages/fastapi
../../packages/fastapi-events ../../packages/fastapi-events
../../packages/fastapi-socketio ../../packages/fastapi-socketio
../../packages/starlette
../../packages/pytorch-lightning ../../packages/pytorch-lightning
../../packages/starlette
../../packages/compel ../../packages/compel
../../packages/taming-transformers-rom1504 ../../packages/taming-transformers-rom1504
../../packages/albumentations ../../packages/albumentations
@ -43,6 +44,14 @@ in
../../packages/getpass-asterisk ../../packages/getpass-asterisk
../../packages/mediapipe ../../packages/mediapipe
../../packages/python-engineio ../../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 (final: prev: lib.mapAttrs
(_: pkg: pkg.overrideAttrs (old: { (_: pkg: pkg.overrideAttrs (old: {
@ -74,7 +83,7 @@ in
src = inputs.a1111-src; 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 { in {
packages = { packages = {
a1111-nvidia = mkAutomatic1111Variant { a1111-nvidia = mkAutomatic1111Variant {
@ -83,7 +92,7 @@ in
}; };
legacyPackages = { legacyPackages = {
a1111-amd = throw '' a1111-amd = throw ''
BREEEE AMD?! AMD not done yet.
''; '';
}; };
}; };

View file

@ -1,17 +1,31 @@
{ python3Packages { python3Packages,
sd-src,
sgm-src,
# misc # misc
, lib lib
, src , src
# extra deps # 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 { python3Packages.buildPythonPackage {
pname = "Automatic1111"; pname = "Automatic1111";
format = "pyproject"; format = "other";
version = "v1.6.0"; version = "v1.6.0";
inherit src; inherit src;
propagatedBuildInputs = with python3Packages; [ propagatedBuildInputs = with python3Packages; [
k_diffusion
inflection
gdown
altair
aiofiles
openclip
semver semver
mediapipe
numpy numpy
torchsde torchsde
uvicorn uvicorn
@ -69,38 +83,92 @@ python3Packages.buildPythonPackage {
dynamicprompts dynamicprompts
torchvision torchvision
test-tube test-tube
lark
gradio
gradio-client
tomesd
piexif
blendmodes
xformers
python-multipart
]; ];
nativeBuildInputs = with python3Packages; [ pythonRelaxDepsHook pip ]; 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" ]; 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}"' '' dontUsePytestCheck = true;
'' --run '
if [[ ! -d "$INVOKEAI_ROOT" && "''${0##*/}" != invokeai-configure ]] doCheck = false;
then
echo "State directory does not exist, running invokeai-configure" buildPhase = ''
if [[ "''${NIXIFIED_AI_NONINTERACTIVE:-0}" != 0 ]]; then runHook preBuild
${placeholder "out"}/bin/invokeai-configure --yes --skip-sd-weights mkdir -p dist
else cp -r . $out
${placeholder "out"}/bin/invokeai-configure chmod -R +w $out
fi cd $out
fi
' #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
patchPhase = '' #delete lines trying to pull git repos and setting up tests in launch.py
#runHook prePatch sed -i '28,43d' launch.py
echo here
#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 = { meta = {
description = "Fancy Web UI for Stable Diffusion"; description = "Fancy Web UI for Stable Diffusion";
homepage = "https://github.com/AUTOMATIC1111/stable-diffusion-webui"; homepage = "https://github.com/AUTOMATIC1111/stable-diffusion-webui";
mainProgram = "stable-diffusion-webui"; mainProgram = "flake-launch";
}; };
} }

1
starta1111.sh Executable file
View file

@ -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