Skip to content

update to latest stable-diffusion.cpp#2

Merged
lmagder merged 5 commits intolmagder:mainfrom
iimez:main
Oct 27, 2024
Merged

update to latest stable-diffusion.cpp#2
lmagder merged 5 commits intolmagder:mainfrom
iimez:main

Conversation

@iimez
Copy link
Copy Markdown
Contributor

@iimez iimez commented Oct 20, 2024

I updated stable-diffusion.cpp to be able to play with flux and stable-diffusion 3.5.

Changes:

  • Added IPNDM and IPNDM_V sampling methods to enum
  • Added new guidance param to txt2img and img2img
  • Added GITS scheduling to enum
  • Added diffusionModel, clipL, clipG and t5xxl params to context creation params

Copy link
Copy Markdown
Owner

@lmagder lmagder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this PR! It's helpful to update this to the newest version and something I have been meaning to get around to anyway.

Comment thread src/NodeModule.cpp Outdated
Napi::PropertyDescriptor::Value("Default", Napi::Number::New(env, DEFAULT)),
Napi::PropertyDescriptor::Value("Discrete", Napi::Number::New(env, DISCRETE)),
Napi::PropertyDescriptor::Value("Karras", Napi::Number::New(env, KARRAS)),
Napi::PropertyDescriptor::Value("GITS", Napi::Number::New(env, GITS)),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nitpick, but the order of these is different from the types file

Comment thread index.d.ts
DPMPP2M,
DPMPP2Mv2,
LCM,
IPNDM,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add these new values to sampleMethodEnum.DefineProperties() also in the C++ code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops missed that, thanks for catching.

Comment thread CMakeLists.txt
)

if(NOT WIN32)
if(EXISTS ${CMAKE_SYSROOT}/usr/lib/x86_64-linux-gnu/libvulkan.so)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to not try find_package(Vulkan) first and only do this if !Vulkan_FOUND or does find_package find the wrong thing? I know I had some weird issues on GH actions runners with CUDA.

Comment thread src/NodeModule.cpp
Napi::Value tmp;
const auto params = info[0].ToObject();
const auto model = params.Get("model").ToString().Utf8Value();
const auto model = (tmp = params.Get("model"), tmp.IsUndefined() ? "" : tmp.ToString().Utf8Value());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it valid to pass a "" model to new_sd_ctx? I assumed no, which was why this was previously not an optional param but maybe I'm wrong?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It became optional in the flux PR here https://github.com/leejet/stable-diffusion.cpp/pull/356/files#diff-a8e875e8f7684a2f9e35212d88ee9574001952eb2c049385e73d5e24fd6e2a83L172-R205 - for flux inference need to set the diffusionModel instead of model.

Comment thread CMakeLists.txt

set(IMPLIB_SOURCE_FILES "")
if (CUDAToolkit_FOUND)
set(SD_CUBLAS ON)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to check !Vulkan_FOUND to disable the CUDA paths here? I don't think one binary can support both in GGML currently.

Same for all the if (CUDAToolkit_FOUND)s

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right its either/or. I updated it like you suggested, so it will build with Vulkan if its installed and disable CUDA in that case.

@lmagder lmagder merged commit f141aa4 into lmagder:main Oct 27, 2024
@lmagder
Copy link
Copy Markdown
Owner

lmagder commented Oct 27, 2024

Thanks for the updates!

@iimez
Copy link
Copy Markdown
Contributor Author

iimez commented Oct 27, 2024

Very welcome, thanks for building and publishing the bindings! I was looking into how we could ship a prebuild for Vulkan possibly, is that something you would like to add?

@lmagder
Copy link
Copy Markdown
Owner

lmagder commented Oct 27, 2024

Yeah I think I would need to rejig the build scripts a bit, but it seems like a good idea. I want to test this a bit before making a new release so I'll take a look

@iimez
Copy link
Copy Markdown
Contributor Author

iimez commented Oct 27, 2024

Ah and note that this commit from your stable-diffusion.cpp fork is missing in this PR, because I switched to leejet/stable-diffusion.cpp for testing.

Also, while checking out stable-diffusion.cpp's backend loading code I noticed that flash attention is only used for CPU backends atm. So it might make sense to switch the USE_FLASH_ATTN flag ON only when neither CUDA nor Vulkan is available. Or switch it always ON regardless, apart from the warning there seems to be no negative consequences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants