Skip to content
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

fooocus: init #68

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-unstable";
};
fooocus-src = {
url = "github:lllyasviel/Fooocus";
flake = false;
};
invokeai-src = {
url = "github:invoke-ai/InvokeAI/v3.3.0post3";
flake = false;
Expand Down Expand Up @@ -51,6 +55,7 @@
hercules-ci-effects.flakeModule
# ./modules/nixpkgs-config
./overlays
./projects/fooocus
./projects/invokeai
./projects/textgen
./website
Expand Down
56 changes: 56 additions & 0 deletions projects/fooocus/base_directory.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
diff --git a/modules/config.py b/modules/config.py
index 1f4e82e..70e6ac0 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -10,8 +10,8 @@ from modules.model_loader import load_file_from_url
from modules.util import get_files_from_folder


-config_path = os.path.abspath("./config.txt")
-config_example_path = os.path.abspath("config_modification_tutorial.txt")
+config_path = os.path.expanduser("~/Fooocus/config.txt")
+config_example_path = os.path.expanduser("~/Fooocus/config_modification_tutorial.txt")
config_dict = {}
always_save_keys = []
visited_keys = []
@@ -107,7 +107,7 @@ def get_path_output() -> str:
Checking output path argument and overriding default path.
"""
global config_dict
- path_output = get_dir_or_set_default('path_outputs', '../outputs/')
+ path_output = get_dir_or_set_default('path_outputs', 'outputs')
if args_manager.args.output_path:
print(f'[CONFIG] Overriding config value path_outputs with {args_manager.args.output_path}')
config_dict['path_outputs'] = path_output = args_manager.args.output_path
@@ -129,21 +129,21 @@ def get_dir_or_set_default(key, default_value):
else:
if v is not None:
print(f'Failed to load config key: {json.dumps({key:v})} is invalid or does not exist; will use {json.dumps({key:default_value})} instead.')
- dp = os.path.abspath(os.path.join(os.path.dirname(__file__), default_value))
+ dp = os.path.abspath(os.path.join(os.path.expanduser('~/Fooocus'), default_value))
os.makedirs(dp, exist_ok=True)
config_dict[key] = dp
return dp


-path_checkpoints = get_dir_or_set_default('path_checkpoints', '../models/checkpoints/')
-path_loras = get_dir_or_set_default('path_loras', '../models/loras/')
-path_embeddings = get_dir_or_set_default('path_embeddings', '../models/embeddings/')
-path_vae_approx = get_dir_or_set_default('path_vae_approx', '../models/vae_approx/')
-path_upscale_models = get_dir_or_set_default('path_upscale_models', '../models/upscale_models/')
-path_inpaint = get_dir_or_set_default('path_inpaint', '../models/inpaint/')
-path_controlnet = get_dir_or_set_default('path_controlnet', '../models/controlnet/')
-path_clip_vision = get_dir_or_set_default('path_clip_vision', '../models/clip_vision/')
-path_fooocus_expansion = get_dir_or_set_default('path_fooocus_expansion', '../models/prompt_expansion/fooocus_expansion')
+path_checkpoints = get_dir_or_set_default('path_checkpoints', 'models/checkpoints')
+path_loras = get_dir_or_set_default('path_loras', 'models/loras')
+path_embeddings = get_dir_or_set_default('path_embeddings', 'models/embeddings')
+path_vae_approx = get_dir_or_set_default('path_vae_approx', 'models/vae_approx')
+path_upscale_models = get_dir_or_set_default('path_upscale_models', 'models/upscale_models')
+path_inpaint = get_dir_or_set_default('path_inpaint', 'models/inpaint')
+path_controlnet = get_dir_or_set_default('path_controlnet', 'models/controlnet')
+path_clip_vision = get_dir_or_set_default('path_clip_vision', 'models/clip_vision')
+path_fooocus_expansion = get_dir_or_set_default('path_fooocus_expansion', 'models/prompt_expansion/fooocus_expansion')
path_outputs = get_path_output()


39 changes: 39 additions & 0 deletions projects/fooocus/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ config, inputs, lib, ... }:

let
l = lib // config.flake.lib;
inherit (config.flake) overlays;

commonOverlays = [
overlays.python-fixPackages
(l.overlays.callManyPackages [
../../packages/safetensors
../../packages/accelerate
../../packages/pytorch-lightning
])
];

variantOverlays = {
amd = [ overlays.python-torchRocm ];
nvidia = [ overlays.python-torchCuda ];
};

mkVariant =
pkgs: name:
pkgs.callPackage ./package.nix {
src = inputs.fooocus-src;
python3Packages =
l.overlays.applyOverlays pkgs.python3Packages
(commonOverlays ++ variantOverlays.${name});
};

in {
perSystem =
{ config, pkgs, ... }:
{
packages = {
fooocus-amd = mkVariant pkgs "amd";
fooocus-nvidia = mkVariant pkgs "nvidia";
};
};
}
12 changes: 12 additions & 0 deletions projects/fooocus/no_prepare_environment.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/launch.py b/launch.py
index db174f5..cbe2183 100644
--- a/launch.py
+++ b/launch.py
@@ -74,7 +74,6 @@ def ini_args():
return args


-prepare_environment()
build_launcher()
args = ini_args()

59 changes: 59 additions & 0 deletions projects/fooocus/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{ python3, python3Packages, applyPatches, writeShellScriptBin, src }:

let
# getVersion = lib.flip lib.pipe [
# (src: builtins.readFile "${src}/fooocus_version.py")
# (builtins.match ".*version = '([0-9\.]+)'.*")
# builtins.head
# ];

python = with python3Packages; python3.withPackages (_: [
torchsde
torchvision
einops
transformers
safetensors
accelerate
pyyaml
pillow
scipy
tqdm
psutil
numpy
pytorch-lightning
omegaconf
gradio
pygit2
opencv4
httpx
]);

patchedSource = applyPatches {
name = "fooocus-source";
inherit src;
patches = [
./base_directory.patch
./no_prepare_environment.patch
];
};

in

writeShellScriptBin "fooocus" ''
if [ -d "/usr/lib/wsl/lib" ]
then
echo "Running via WSL (Windows Subsystem for Linux), setting LD_LIBRARY_PATH=/usr/lib/wsl/lib"
set -x
export LD_LIBRARY_PATH="/usr/lib/wsl/lib"
set +x
fi

# See note about consumer GPUs:
# https://docs.amd.com/bundle/ROCm-Deep-Learning-Guide-v5.4.3/page/Troubleshooting.html
export HSA_OVERRIDE_GFX_VERSION=10.3.0

mkdir -p ~/Fooocus
cp -r --no-preserve=mode,ownership ${src}/models ~/Fooocus

exec ${python}/bin/python ${patchedSource}/launch.py
''