External component has thrown an exception
Hello. I have simple code:
using HPPH;
using StableDiffusion.NET;
using DiffusionModel model = ModelBuilder.StableDiffusion(@"G:\path_to_checkpoints\jamJustAnotherMerge_v20bBakedvaePruned.safetensors")
.WithMultithreading()
.Build();
string prompt = "cat";
IImage<ColorRGB> image = model
.TextToImage(prompt, model
.GetDefaultParameter()
.WithSteps(30)
.WithCfg(8.0f)
.WithSampler(Sampler.DPMPP2M)
.WithSize(512, 800));
And i try to run and have error:
ggml_cuda_init: GGML_CUDA_FORCE_MMQ: no
ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no
ggml_cuda_init: found 1 CUDA devices:
Device 0: NVIDIA GeForce RTX 3070, compute capability 8.6, VMM: yes
|==================================================| 1130/1130 - 500.00it/s
Unhandled exception. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at StableDiffusion.NET.Native.
Downloaded from nuget. And downloaded some dlls from stable-diffusion.cpp (cuda dlls). Checkpoint file is sd1.5. What am I doing wrong?
It looks like the problem is the lack of rtx30 support from stablediffusion.cpp
what stable-diffusion-dlls are you using? does the exception also occur if you use one of the backend-packages?
what stable-diffusion-dlls are you using? does the exception also occur if you use one of the backend-packages?
1.stable-diffusion-dlls: trying from packages (size ~550mb) and trying from git. cuda dlls from git (latest) 2. used StableDiffusion.NET.Backend.Cuda12.Windows
Backends.CudaBackend.IsEnabled = true;
var cudaVersion = Backends.CudaBackend.CudaVersion;
cudaVersion shows -1.
If it's reporting cuda-version as -1 it's not able to detect your cuda installation (or cuda is not installed at all). In that case it should not even try to do anything. I'll check what's wrong with loading a backend that is not available.
Do you have cuda installed? if yes check if the CUDA_PATH-environment-variable is set correctly.
If you mean Cuda SDK, then it`s not installed.
In that case I'd say that the exception is caused by a lack of some cuda-dlls. I've no idea how the setup works with the cuda-redistributables if it's not installed.
In that case I'd say that the exception is caused by a lack of some cuda-dlls. I've no idea how the setup works with the cuda-redistributables if it's not installed.
Well, nevertheless, the sd.exe utility works fine. I'm not sure if you need to install any sdk to run stable duffusion on cuda.
sd.exe from last release archive from stable-diffusion.cpp git. sd-master-10feacf-bin-win-cuda12-x64.zip
example with: sd.exe -m ../models/sd3_medium_incl_clips_t5xxlfp16.safetensors --cfg-scale 5 --steps 30 --sampling-method euler -H 1024 -W 1024 --seed 42 -p "fantasy medieval village world inside a glass sphere , high detail, fantasy, realistic, light effect, hyper detail, volumetric lighting, cinematic, macro, depth of field, blur, red light and clouds from the back, highly detailed epic cinematic concept art cg render made in maya, blender and photoshop, octane render, excellent composition, dynamic dramatic cinematic lighting, aesthetic, very inspirational, world inside a glass sphere by james gurney by artgerm with james jean, joe fenton and tristan eaton by ross tran, fine details, 4k resolution" works fine.
05.05.2025 13:28 113 712 640 cublas64_12.dll
05.05.2025 13:28 692 441 600 cublasLt64_12.dll
05.05.2025 13:28 573 952 cudart64_12.dll
09.03.2025 05:08 399 872 sd.exe
09.03.2025 18:27 548 001 792 stable-diffusion.dll
stable-diffusion.dll from nuget from this package. no cuda toolkid or sdk installed.
Did you add all the cuda-dlls you had by your sd.exe too your c# program as well? The only thing I can imagine to cause that issue aside from some missing things is a problem with the settings you're using. Did you verify the exact same settings with sd.exe? (I know that some models are problematic with non-default size configurations)
Same problem. And also RTX30. Apparently, this series is not supported?
If I understand correctly, to support rtx30 you need to add the -CMAKE_CUDA_ARCHITECTURES=86 switch when compiling Stable Diffusion, as specified here: https://github.com/leejet/stable-diffusion.cpp/blob/master/.github/workflows/build.yml#L166.
I am having the same issue on a similar GPU, does stable-diffusion.cpp need to be rebuilt from source for this GPU?
ggml_cuda_init: GGML_CUDA_FORCE_MMQ: no ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no ggml_cuda_init: found 1 CUDA devices: Device 0: NVIDIA GeForce RTX 3060 Laptop GPU, compute capability 8.6, VMM: yes
EDIT: Seems it may be unrelated as even when I uninstall the cuda backend and install the cpu backend I get the same error
EDIT: Can confirm sd.exe is working fine, ableit slowly, with the avx512 binaries, but StableDiffusion.NET still encounters the System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at StableDiffusion.NET.Native.
This indicates you're using a sd.cpp build that had API changes and is not compatible (most likely to recent if you build yourself, the API has been compeltely reworked and I'm not done with the changey yet.) if you using backend nugets make sure the version fit the one of the main package
This indicates you're using a sd.cpp build that had API changes and is not compatible (most likely to recent if you build yourself, the API has been compeltely reworked and I'm not done with the changey yet.) if you using backend nugets make sure the version fit the one of the main package
Thanks for the quick repsonse.
Right now I am testing with StableDiffusion.NET 3.6.0 and StableDiffusion.NET.Backends.CPU 3.6.0 / 3.6.2 so I believe these are matching.
How do I know what sd.cpp builds are compatible with the v3.6.0 of StableDiffusion.NET ?