Open lboklin opened 2 months ago
I'll investigate more when I get back from work. but when trying to nix run .#comfyui-amd
I am currently getting:
nix build .#comfyui-amd
works. however the resulting ./result/bin/comfyui
fails with:
File "/home/airradda/Git/nixified-ai/./result/bin/comfyui", line 2
cd /nix/store/px5qmzc34cypqpl0p28yzgr8dz7gvwx8-comfyui-unstable-2024-04-15 && \
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
I'll investigate more when I get back from work. but when trying to
nix run .#comfyui-amd
I am currently getting: config.cudaSupport = true config.cudaSupport = false
nix build .#comfyui-amd
works. however the resulting./result/bin/comfyui
fails with:File "/home/airradda/Git/nixified-ai/./result/bin/comfyui", line 2 cd /nix/store/px5qmzc34cypqpl0p28yzgr8dz7gvwx8-comfyui-unstable-2024-04-15 && \ ^ SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
Does config.cudaSupport = true
give you trouble when you nix run .#comfyui-amd
?
Anyhow I've removed it because I figured out the reason I had to add it.
Thanks for (presumably) testing with an AMD card.
File "/home/airradda/Git/nixified-ai/./result/bin/comfyui", line 2 cd /nix/store/px5qmzc34cypqpl0p28yzgr8dz7gvwx8-comfyui-unstable-2024-04-15 && \ ^ SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
I don't know why that would happen; it works on my end. What is your environment? NixOS?
I'll investigate more when I get back from work. but when trying to
nix run .#comfyui-amd
I am currently getting: config.cudaSupport = true config.cudaSupport = falsenix build .#comfyui-amd
works. however the resulting./result/bin/comfyui
fails with:File "/home/airradda/Git/nixified-ai/./result/bin/comfyui", line 2 cd /nix/store/px5qmzc34cypqpl0p28yzgr8dz7gvwx8-comfyui-unstable-2024-04-15 && \ ^ SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
Does
config.cudaSupport = true
give you trouble when younix run .#comfyui-amd
?
Yes, the resulting error was in the config.cudaSupport = true
details.
Thanks for (presumably) testing with an AMD card.
Yes, this is being tested on a 6950 XT.
File "/home/airradda/Git/nixified-ai/./result/bin/comfyui", line 2 cd /nix/store/px5qmzc34cypqpl0p28yzgr8dz7gvwx8-comfyui-unstable-2024-04-15 && \ ^ SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
I don't know why that would happen; it works on my end. What is your environment? NixOS?
Yes, I'm on NixOS Unstable.
Not caused by this PR or Nixified-AI, but I am currently failing to build roctracer
for both ROCM 5 and 6, so I can't test anymore until I find out why:
Thanks for the call out and your work on this!
I took the liberty of copying your added custom-nodes to my nixpkgs comfyui fork. While it's all still a draft I'm working at moving all of it out of my dotfiles. I await a reply from the original author for write permission to the branch.
I'm experimenting with parametrising the whole flake over a configurable set of options by allowing the user to override a flake (nixified-cfg) with one of their own which holds their configuration along with a library of models.
This approach is currently the only way (as far as I can tell) to parametrise a flake (supply a flake with arguments, cf. https://github.com/NixOS/nix/issues/5663). It's a little clunky, but it's declarative, allowing one to manage one's own models and custom nodes (TBI) with their own personal flake, which seems like a neat way to organise ones configurations in any case.
Edit: forgot to link the default (for now) nixified-cfg: https://github.com/lboklin/nixified-cfg. Its readme has basic instructions, but basically you clone it and pass it in with --override-input nixified-cfg <cloned-cfg>
when running comfyui.
I've gotten all the ROCM stuff to build, so now I'm on to the actual Comfy-UI stuff. It seems to be trying to access a non-existent /var/lib/comfy-ui/user
directory. It also appears to not be one of the directories configurable via flags (See Log 2). I'll do a more in depth run after I get back from work.
I've gotten all the ROCM stuff to build, so now I'm on to the actual Comfy-UI stuff. It seems to be trying to access a non-existent
/var/lib/comfy-ui/user
directory. It also appears to not be one of the directories configurable via flags (See Log 2). I'll do a more in depth run after I get back from work. Log Log 2
I think the problem makes sense because /var/lib is mutable and shouldn't be accessed during build time. I'm working on model collections so that you basically build a collection of everything in the config flake and then comfyui points to that collection in its extra_model_paths.yaml
Just a heads-up: I'm restructuring a bunch and things are quite broken atm.
As of this moment, this should work (for nvidia) and give a minimal setup: nix run github:lboklin/nixified-ai#comfyui-nvidia --override-input nixified-cfg github:lboklin/nixified-cfg/eb69f4c62fa0ce19eee2e8a4a5d601176a398bfd
(most recent commit on comfyui-minimal branch as of now).
I swapped the hardcoded paths in the package.nix for some user accessible ones in ~/Documents/Comfy-UI
and, using your input override, I have successfully generated an image. This includes full use of the GPU during generation.
I swapped the hardcoded paths in the package.nix for some user accessible ones in
~/Documents/Comfy-UI
and, using your input override, I have successfully generated an image. This includes full use of the GPU during generation.
Do you mean the subdirectories of the models? I suppose those ought to be configurable as well. Hadn't thought of that!
I tried get a readable diff to show, but I hardcoded the config-data.comfyui.base_path
and the inputPath
, outputPath
, tempPath
, and userPath
.
projects/comfyui/package.nix --- 1/4 --- Nix 7 , stdenv 8 , symlinkJoin 9 , config 10 , modelsPath ? "/home/airradda/Documents/Comfy-UI/Models" 11 , inputPath ? "/home/airradda/Documents/Comfy-UI/Input" 12 , outputPath ? "/home/airradda/Documents/Comfy-UI/Output" 13 , tempPath ? "/home/airradda/Documents/Comfy-UI/Temp" 14 , userPath ? "/home/airradda/Documents/Comfy-UI/User" 15 , customNodes 16 , models 17 }:
projects/comfyui/package.nix --- 2/4 --- Nix 20 20 21 config-data = { 21 config-data = { 22 comfyui = { 22 comfyui = { 23 base_path = modelsPath; 23 base_path = "/home/airradda/Documents/Comfy-UI/Models"; 24 checkpoints = "${modelsPath}/checkpoints"; 24 checkpoints = "${modelsPath}/checkpoints"; 25 clip = "${modelsPath}/clip"; 25 clip = "${modelsPath}/clip"; 26 clip_vision = "${modelsPath}/clip_vision"; 26 clip_vision = "${modelsPath}/clip_vision";
projects/comfyui/package.nix --- 3/4 --- Nix 58 tqdm 58 tqdm 59 ] ++ (builtins.concatMap (node: node.dependencies) customNodes))); 59 ] ++ (builtins.concatMap (node: node.dependencies) customNodes))); 60 60 61 executable = writers.writeDashBin "comfyui" '' 61 executable = writers.writeDashBin "comfyui" '' 62 cd $out && \ 62 cd $out && \ 63 ${pythonEnv}/bin/python comfyui \ 63 ${pythonEnv}/bin/python comfyui \ 64 --input-directory ${inputPath} \ 64 --input-directory "/home/airradda/Documents/Comfy-UI/Input" \ 65 --output-directory ${outputPath} \ 65 --output-directory "/home/airradda/Documents/Comfy-UI/Output" \ 66 --extra-model-paths-config ${modelPathsFile} \ 66 --extra-model-paths-config ${modelPathsFile} \ 67 --temp-directory ${tempPath} \ 67 --temp-directory "/home/airradda/Documents/Comfy-UI/Temp" \ 68 "$@" 68 "$@" 69 ''; 69 '';
@Airradda you can generate a diff with git diff --patch
Edit: also, looks like you are on a slightly older commit (unless you added the defaults yourself - I recently removed them)
So the idea with the declarative model management is that you customise your set of models in the cfg flake, here. You can of course modify the nixified-ai like you did and manage models yourself, mutably; but in this PR my goal is to make that unnecessary because all of that would be handled the nix way, and it should be easy to add what you need right in one's own cfg flake.
I hope I didn't lie by stating in the comments at the top of the file that downloads are cached even if the checksum fails to match. It seemed like it was in one case but in another it seemed to redownload the whole thing once I added the correct one. That is of course less than ideal because some models can be very large, and you really have no good way (afaik) of getting the checksum before deliberately using an incorrect one.
@Airradda you can generate a diff with
git diff --patch
Edit: also, looks like you are on a slightly older commit (unless you added the defaults yourself - I recently removed them)
That is what I posted came from.
The commit is from last night. I explicitly added them back in before hardcoding them as the default weren't applying.
So the idea with the declarative model management is that you customise your set of models in the cfg flake, here. You can of course modify the nixified-ai like you did and manage models yourself, mutably; but in this PR my goal is to make that unnecessary because all of that would be handled the nix way, and it should be easy to add what you need right in one's own cfg flake.
I was also trying to get a minimum setup going before messing with the cfg/nix stuff. The setup I had before, running in a rocm-pytorch container with podman, broke so I was trying to have minimal downtime.
Tonight, I will probably start messing with and/or move to the cfg based setup and see how that goes.
I've progressed on implementing custom nodes management in addition to models, but there is a hurdle: custom nodes can't have their own dependencies and I don't know how to solve the problem cleanly.
Anyway, I've been trying to make a config that has everything the Krita AI plugin needs, and all requirements are met except one (controlnet_aux) due to dependencies. If one is eager, they can be added manually to the comfyui package.
I'm doing this on a separate branch because there is a minor change in the config "api" that I just haven't synced across both projects yet outside of these two branches (https://github.com/lboklin/nixified-ai/tree/comfyui-krita-requirements and https://github.com/lboklin/nixified-cfg/tree/comfyui-krita-requirements).
@lboklin I'm not behind my computer (to provide links) but I've been doing custom nodes in my dotfiles, and I've been doing dependencies in there. These dependencies are bundled up to become ComfyUI's dependencies. Does that solve your issue?
My nixpkgs branch should also be demonstrating this.
@LoganBarnet I'm also not at the computer atm, but I was using your nixpkgs fork as reference. If I try to do it the same way I get "... is a string with context when a set was expected". One of your comments mentioned this problem with linkFarm, so maybe an alternative to that could be concocted, but my intuition is that the problem is greater than that. I'll have a look at it again tomorrow.
Alright, I solved the problem with custom node dependencies. For one, I had to set the derivations' passthru.dependencies
, not merely dependencies
(they were never preserved); but that they weren't propagated was occluded by the previously mentioned error which was caused by cfg.models
and cfg.customNodes
in the configuration flake being set to strings with the outPath of the respective packages rather than their derivations.
So both declarative model management and custom nodes seem to work now. Something is missing for the Krita plugin still so I'm looking into that now, and after that I'll redirect my attention to the NixOS module.
Based on feedback I've moved everything back into this main repo and added a basic package for running a krita-ai server (packages.krita-comfyui-server-"${gpuVendor}"
/ legacyPackages.comfyui."${gpuVendor}".kritaServer
) as well as some general functions in legacyPackages.comfyui."${gpuVendor}"
:
withConfig
with type
{ models : Models,
, customNodes : CustomNodes
, inputPath : String
, outputPath : String
, tempPath : String
, userPath : String
, ...
}
withPlugins
with type (Models -> Models) -> (CustomNodes -> CustomNodes) -> derivation
/var/lib/comfyui
and there within.Example usage of withPlugins
from the commandline: nix build --impure --expr '(builtins.getFlake "github:lboklin/nixified-ai").legacyPackages.x86_64-linux.comfyui.nvidia.withPlugins (ms: { checkpoints = { inherit (ms.checkpoints) DreamShaper_8_pruned; }; }) (ns: { inherit (ns) controlnet-aux; })'
I have built and generated an image using
nix build --impure --expr '(builtins.getFlake "github:lboklin/nixified-ai").legacyPackages.x86_64-linux.comfyui.amd.withPlugins (ms: { checkpoints = { inherit (ms.checkpoints) DreamShaper_8_pruned; }; }) (ns: { inherit (ns) controlnet-aux; })'
.
and I can confirm it is properly making full use of my AMD GPU.
I've added a bunch of models and changed the outputs a bit.
Examples of how one could use the new outputs:
# run a server with absolutely all models and custom nodes:
nix run --impure --expr 'with (builtins.getFlake "github:lboklin/nixified-ai").legacyPackages.x86_64-linux.comfyui.{nvidia,amd}; withPlugins (plugins: plugins)'
# all the checkpoint models but no custom nodes
nix run --impure --expr 'with (builtins.getFlake "github:lboklin/nixified-ai").legacyPackages.x86_64-linux.comfyui.{nvidia,amd}; withPlugins ({ models, customNodes }: { customNodes = {}; models = { inherit (models) checkpoints; }; })'
# run a krita ai server with all optional models included (controlnets and such):
nix run github:lboklin/nixified-ai#krita-comfyui-server-{nvidia,amd}
# run a minimal krita ai server with a custom model set (but please actually put the expression in a file):
nix run --impure --expr 'with (builtins.getFlake "github:lboklin/nixified-ai").legacyPackages.x86_64-linux.comfyui.{nvidia,amd}; kritaServerWithModels (ms: with ms; { checkpoints = { inherit (checkpoints) colossus-xl-v6; }; ipadapter = { inherit (ipadapter) ip-adapter-faceid-plusv2_sdxl; }; loras = { inherit (loras) ip-adapter-faceid-plusv2_sdxl_lora; }; })'
It seems to me like it's not uncommon for custom nodes to require certain models, so I added a passthru for that as well.
reactor-node is broken because it tries to write to the models dir, but I'm leaving it there.
nix run --impure --expr 'with (builtins.getFlake "github:lboklin/nixified-ai").legacyPackages.x86_64-linux.comfyui.{nvidia,amd}; withPlugins ({ models, customNodes }: { customNodes = {}; models = { inherit (models) checkpoints; }; })'
is the only functioning command for me. The others error out because of albumentations
, which produces the following error log. Aside from that, I am able to generate an image and will start trying migrating from my current nixifiedai-cfg setup see if I come across anything else.
nix run --impure --expr 'with (builtins.getFlake "github:lboklin/nixified-ai").legacyPackages.x86_64-linux.comfyui.{nvidia,amd}; withPlugins ({ models, customNodes }: { customNodes = {}; models = { inherit (models) checkpoints; }; })'
is the only functioning command for me. The others error out because ofalbumentations
, which produces the following error log. Aside from that, I am able to generate an image and will start trying migrating from my current nixifiedai-cfg setup see if I come across anything else. Error Log
I recently added that dependency (and others) not because anything was broken but because it was listed in the relevant project's requirements.txt. You should be able to simply remove it if you just want to get past that error.
Yeah, I just removed it from controlnet-aux
and disabled reactor-node
.
On a separate note, in your opinion, what would be the best way to handle extensions and/or alternative UIs?
Yeah, I just removed it from
controlnet-aux
and disabledreactor-node
.On a separate note, in your opinion, what would be the best way to handle extensions and/or alternative UIs?
I suppose a similar treatment as for custom nodes and models; at the top-most level we could add an extensions
and a frontend
attribute to the "plugins" interface. I imagine we might want to prepare more comprehensive sets/plugins that include things from more than one category, or, just like how I implemented model dependencies for custom nodes we could add the other categories as possible dependencies so that adding the custom nodes from https://github.com/blib-la/blibla-comfyui-extensions would also pull in the extensions.
The current example is failing for me with this missing attribute error:
And a nix flake show --legacy
seems to indicate this is correct. However removing the left operand and //
operator leads to a similar missing attribute for the right operand, but packages.x86_64-linux.comfyui-amd
does show up in the nix flake show --legacy
. I assumed this was an issue with my local repo, so I pulled a fresh copy and get the same error. This does not appear to occur for krita-comfyui-server
, both of which fail for different reasons.
@Airradda I suspect you forgot to chance "github:nixified-ai/flake" to "github:lboklin/nixified-ai"
Anyway, I'm working on adding a proper template. I've also refactored a few things. Not sure if it's better in the end, but hopefully it turns out ok. I'll probably push it as one big commit.
A simple solution to the last blocker is that the broken projects are simply left broken, with a note in the readme that they are unmaintained and explicitly instruct to use the last revision of the flake in which they still worked. It's beyond the scope of this PR to update and fix those projects, and the reason that they are broken, after all, is that they are indeed unmaintained.
I'm waiting for a final review before squashing and un-drafting this PR.
Damn, just one of those days I guess. You were correct. Anyway, here are some things from testing from with a fresh new template:
Issues:
basePath
with adding a rec
to the comfyui.override
fetchFromUrl
contains a ?
then mkdir fails with:
error: builder for '/nix/store/ib0h5aq82iah423786z9zrbi9yzaddyq-290640?type=VAE.drv' failed with exit code 1;
last 3 log lines:
> Running phase: buildPhase
> mkdir: missing operand
> Try 'mkdir --help' for more information.
For full logs, run 'nix log /nix/store/ib0h5aq82iah423786z9zrbi9yzaddyq-290640?type=VAE.drv'.
error: 1 dependencies of derivation '/nix/store/vnhpjz0a90mkmqfxl42hwkrm11xhg724-comfyui-models.drv' failed to build
error: 1 dependencies of derivation '/nix/store/x1knpd90ikj23ixq0idrjzkw3v5bgi02-comfyui-unstable-2024-06-12.drv' failed to build
If not then this is a bit of a problem as fetching some models requires ?token=<token>
when fetching from CivitAI.
Error occurred when executing VAEDecode:
'VAE' object has no attribute 'vae_dtype'
File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/execution.py", line 151, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/execution.py", line 81, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/execution.py", line 74, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/nodes.py", line 268, in decode return (vae.decode(samples["samples"]), ) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/comfy/sd.py", line 300, in decode memory_used = self.memory_used_decode(samples_in.shape, self.vae_dtype) ^^^^^^^^^^^^^^
This does not occur in [c27f8ff](https://github.com/nixified-ai/flake/pull/94/commits/c27f8ff8fbef21bd95b04b788d2e826ce03aa673)
Other Notes:
1. I was able to build the flake and generate with all the models without a VAE, and it is still properly using my AMD GPU.
2. I think it would be good to have an example or comments for using separate files for models and custom nodes as they can very quickly get quite large (Mine is 1000+ lines).
3. And/or an example of how to use `fetchFromUrl`, I got it working in what feels like a very hackish way by doing:
```nix
myModels = with {inherit (import ./meta.nix) base-models model-types;}; let
fetchFromUrl = import <nix/fetchurl.nix>;
in {
Damn, just one of those days I guess.
Haha, no worries.
Issues:
* The user defined [paths](https://github.com/lboklin/nixified-ai/blob/7850a9216df1a147f277eac40e9b3f8a3012467e/templates/comfyui/flake.nix#L74-L77) in the template, can't use `basePath` with adding a `rec` to the [`comfyui.override`](https://github.com/lboklin/nixified-ai/blob/7850a9216df1a147f277eac40e9b3f8a3012467e/templates/comfyui/flake.nix#L43)
I took it out just to stop my linter from complaining about it being unnecessary when those lines are commented out, but it's a good point that one should be able to uncomment them and get no errors. Fixed now.
* This probably from the hackish way I did it (See "Other Notes 3.) , but if the URL for `fetchFromUrl` contains a `?` then mkdir fails
It's because the implementation of taking the basename of the url isn't clever enough to strip those characters, it would seem, so I fixed it by passing names explicitly to the fetchers.
* After fixing the above issue the resulting VAE fails when used with:
Error occurred when executing VAEDecode: 'VAE' object has no attribute 'vae_dtype' File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/execution.py", line 151, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/execution.py", line 81, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/execution.py", line 74, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/nodes.py", line 268, in decode return (vae.decode(samples["samples"]), ) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lk4ds5rvlskiaxvqrgm728crwn9yja4m-comfyui-unstable-2024-06-12/comfy/sd.py", line 300, in decode memory_used = self.memory_used_decode(samples_in.shape, self.vae_dtype) ^^^^^^^^^^^^^^
This does not occur in c27f8ff
Hmm, I don't know what causes this. I'm using it without issue, so it must be something to do with other nodes or models, or else it is system-specific (or a flag passed to comfyui?).
I think it would be good to have an example or comments for using separate files for models and custom nodes as they can very quickly get quite large (Mine is 1000+ lines).
Noted. I also want to add an example of using a locally downloaded model with fixed hash. I know how to do it outside of a flake but haven't tried with a flake:
sd3-medium-incl-clips = {
installPath = "checkpoints/stableDiffusion3SD3_sd3MediumInclClips.safetensors";
src = pkgs.requireFile {
url = "file:///path/to/stableDiffusion3SD3_sd3MediumInclClips.safetensors";
sha256 = "108578x7cfwcxfys8rjiklq24m5ifvra4y7byhh04igvqldz5drv";
};
type = model-types.checkpoint;
base = base-models.sd3-medium;
This is based on other people's work, most notably @fazo96's PR and @LoganBarnett's modifications to it.
Currently it is mostly an original implementation with a focus on making it easy to spin up a server without necessarily adding it to one's system config. It currently lacks a NixOS module, partly because @LoganBarnett is already putting a lot of work into getting that into nixpkgs.
This is a draft due to the following unsolved problems:comfyui-amd
at least runs properlycomfyui-nvidia
at least runs properlymake sure the nixos module is functionalremoved NixOS module because a lot of work is being put into such a module by @LoganBarnett in https://github.com/NixOS/nixpkgs/pull/268378 and I don't see a reason for yet another implementation at this timenix run
document the module in the readmeit's been pointed out that the flake may need to use different nixpkgs as inputs to the various projects so as not to break each othermarking them as unmaintained instead, since the other projects haven't been updated in a long time and it's unreasonable that they should stall new additions.make sure invokeai isn't broken by the updated inputs