Commit ad852d97 authored by Your Name's avatar Your Name

Use CUDA only if --backend nvidia or --image-backend nvidia is specified

parent 27527de3
...@@ -3665,34 +3665,25 @@ async def create_image_generation(request: ImageGenerationRequest): ...@@ -3665,34 +3665,25 @@ async def create_image_generation(request: ImageGenerationRequest):
sd_cpp_error = "Could not resolve model path" sd_cpp_error = "Could not resolve model path"
else: else:
# Load sd.cpp model # Load sd.cpp model
# Determine backend to use # Determine backend to use based on CLI args
backend = getattr(global_args, 'backend', 'auto') backend = getattr(global_args, 'backend', 'auto')
image_backend = getattr(global_args, 'image_backend', 'auto') image_backend = getattr(global_args, 'image_backend', 'auto')
# Use CUDA if available, otherwise Vulkan # Use CUDA only if explicitly requested via --backend nvidia or --image-backend nvidia
use_cuda = False use_cuda = (backend == 'nvidia' or backend == 'cuda' or
try: image_backend == 'nvidia' or image_backend == 'cuda')
import torch
use_cuda = torch.cuda.is_available()
except ImportError:
pass
if use_cuda: if use_cuda:
print(f"Using CUDA backend for sd.cpp image generation") print(f"Using CUDA backend for sd.cpp image generation")
sd_model = StableDiffusion(
model_path=model_path,
vae_path=None,
n_threads=4,
n_gpu_layers=-1, # All layers to GPU
)
else: else:
print(f"Using Vulkan backend for sd.cpp image generation") print(f"Using Vulkan backend for sd.cpp image generation")
sd_model = StableDiffusion(
model_path=model_path, sd_model = StableDiffusion(
vae_path=None, model_path=model_path,
n_threads=4, vae_path=None,
n_gpu_layers=-1, # All layers to GPU n_threads=4,
) n_gpu_layers=-1, # All layers to GPU
)
print(f"Using stable-diffusion-cpp-python for image generation") print(f"Using stable-diffusion-cpp-python for image generation")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment