Commit e538d802 authored by Your Name's avatar Your Name

Fix CUDA backend - use comprehensive Vulkan disable variables

For stable-diffusion-cpp-python:
- GGML_VK_VISIBLE_DEVICES=
- GGML_VULKAN_DEVICE=

For llama-cpp-python (additional):
- VK_ICD_FILENAMES=/dev/null
- VK_DRIVER_FILES=/dev/null
- VK_LOADER_DRIVERS_DISABLE=*
- VK_LOADER_LAYERS_DISABLE=~all~

All variables are restored on cleanup for subsequent Vulkan models.
parent 11bada84
...@@ -1584,8 +1584,15 @@ class VulkanBackend(ModelBackend): ...@@ -1584,8 +1584,15 @@ class VulkanBackend(ModelBackend):
if self.force_cuda: if self.force_cuda:
print("DEBUG: Forcing CUDA backend for llama-cpp-python...") print("DEBUG: Forcing CUDA backend for llama-cpp-python...")
# Disable Vulkan to ensure CUDA is used (llama-cpp with both CUDA+Vulkan needs this) # Disable Vulkan to ensure CUDA is used (llama-cpp with both CUDA+Vulkan needs this)
os.environ['VK_ICD_FILENAMES'] = '/dev/null' # Disable Vulkan ICD # For both stable-diffusion-cpp-python and llama-cpp-python
print(f"DEBUG: Set VK_ICD_FILENAMES=/dev/null to disable Vulkan and force CUDA") os.environ['GGML_VK_VISIBLE_DEVICES'] = ''
os.environ['GGML_VULKAN_DEVICE'] = ''
# Additional variables for llama-cpp-python
os.environ['VK_ICD_FILENAMES'] = '/dev/null'
os.environ['VK_DRIVER_FILES'] = '/dev/null'
os.environ['VK_LOADER_DRIVERS_DISABLE'] = '*'
os.environ['VK_LOADER_LAYERS_DISABLE'] = '~all~'
print(f"DEBUG: Set Vulkan disable env vars to force CUDA")
# Ensure CUDA is used - set environment to prefer CUDA # Ensure CUDA is used - set environment to prefer CUDA
if 'CUDA_VISIBLE_DEVICES' not in os.environ: if 'CUDA_VISIBLE_DEVICES' not in os.environ:
# Use all available CUDA devices # Use all available CUDA devices
...@@ -1970,9 +1977,12 @@ class VulkanBackend(ModelBackend): ...@@ -1970,9 +1977,12 @@ class VulkanBackend(ModelBackend):
def cleanup(self) -> None: def cleanup(self) -> None:
# When cleaning up a CUDA-forced model, restore Vulkan settings for future Vulkan models # When cleaning up a CUDA-forced model, restore Vulkan settings for future Vulkan models
if self.force_cuda: if self.force_cuda:
# Unset the CUDA-forcing environment variable so Vulkan models can work # Unset all CUDA-forcing environment variables so Vulkan models can work
if 'VK_ICD_FILENAMES' in os.environ: for var in ['GGML_VK_VISIBLE_DEVICES', 'GGML_VULKAN_DEVICE',
del os.environ['VK_ICD_FILENAMES'] 'VK_ICD_FILENAMES', 'VK_DRIVER_FILES',
'VK_LOADER_DRIVERS_DISABLE', 'VK_LOADER_LAYERS_DISABLE']:
if var in os.environ:
del os.environ[var]
print("DEBUG: Cleanup - restored Vulkan environment for future models") print("DEBUG: Cleanup - restored Vulkan environment for future models")
if self.model is not None: if self.model is not None:
del self.model del self.model
......
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