Skip to content

Commit 6e412d4

Browse files
committed
add zluda force sync
1 parent 38c5beb commit 6e412d4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

modules/shared.py

+3
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ def temp_disable_extensions():
402402
"olive_vae_encoder_float32": OptionInfo(False, 'Olive force FP32 for VAE Encoder'),
403403
"olive_static_dims": OptionInfo(True, 'Olive use static dimensions'),
404404
"olive_cache_optimized": OptionInfo(True, 'Olive cache optimized models'),
405+
406+
"zluda_sep": OptionInfo("<h2>ZLUDA</h2>(experimental)", "", gr.HTML, {"visible": devices.backend == "cuda"}),
407+
"zluda_force_sync": OptionInfo(False, 'ZLUDA force synchronization (experimental, restart required)', gr.Checkbox, {"visible": devices.backend == "cuda"}),
405408
}))
406409

407410
options_templates.update(options_section(('advanced', "Inference Settings"), {

modules/zluda.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import platform
22
import torch
3+
from diffusers.models.attention_processor import AttnProcessor
34
from modules import shared, devices
45

56

67
def initialize_zluda():
78
if platform.system() == "Windows" and devices.cuda_ok and torch.cuda.get_device_name(devices.get_optimal_device()).endswith("[ZLUDA]"):
9+
shared.log.warning("Detected ZLUDA device. Currently, ZLUDA support is experimental and unstable.")
810
torch.backends.cudnn.enabled = False
911
if shared.opts.cross_attention_optimization == "Scaled-Dot-Product":
1012
shared.opts.cross_attention_optimization = "Batch matrix-matrix"
13+
if shared.opts.zluda_force_sync:
14+
patch_attention_processor(AttnProcessor)
15+
16+
17+
def patch_attention_processor(cls):
18+
forward = cls.__call__
19+
def patched(self, *args, **kwargs):
20+
R = forward(self, *args, **kwargs)
21+
torch.cuda.synchronize()
22+
return R
23+
cls.__call__ = patched

0 commit comments

Comments
 (0)