|
| 1 | +using Injectio.Attributes; |
| 2 | +using StabilityMatrix.Avalonia.Models.Inference; |
| 3 | +using StabilityMatrix.Avalonia.Services; |
| 4 | +using StabilityMatrix.Avalonia.ViewModels.Base; |
| 5 | +using StabilityMatrix.Avalonia.ViewModels.Inference; |
| 6 | +using StabilityMatrix.Core.Attributes; |
| 7 | +using StabilityMatrix.Core.Models.Api.Comfy.Nodes; |
| 8 | +using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes; |
| 9 | +using StabilityMatrix.Core.Models.Inference; |
| 10 | + |
| 11 | +namespace StabilityMatrix.Avalonia.ViewModels.Inference.Modules; |
| 12 | + |
| 13 | +[ManagedService] |
| 14 | +[RegisterTransient<CfzCudnnToggleModule>] |
| 15 | +public class CfzCudnnToggleModule : ModuleBase |
| 16 | +{ |
| 17 | + /// <inheritdoc /> |
| 18 | + public CfzCudnnToggleModule(IServiceManager<ViewModelBase> vmFactory) |
| 19 | + : base(vmFactory) |
| 20 | + { |
| 21 | + Title = "CUDNN Toggle (ComfyUI-Zluda)"; |
| 22 | + AddCards(vmFactory.Get<CfzCudnnToggleCardViewModel>()); |
| 23 | + } |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Applies CUDNN Toggle node between sampler latent output and VAE decode |
| 27 | + /// This prevents "GET was unable to find an engine" errors on AMD cards with Zluda |
| 28 | + /// </summary> |
| 29 | + protected override void OnApplyStep(ModuleApplyStepEventArgs e) |
| 30 | + { |
| 31 | + // Get the primary connection (can be latent or image) |
| 32 | + var primary = e.Builder.Connections.Primary; |
| 33 | + if (primary == null) |
| 34 | + { |
| 35 | + return; // No primary connection to process |
| 36 | + } |
| 37 | + |
| 38 | + // Check if primary is a latent (from sampler output) |
| 39 | + if (primary.IsT0) // T0 is LatentNodeConnection |
| 40 | + { |
| 41 | + var card = GetCard<CfzCudnnToggleCardViewModel>(); |
| 42 | + var latentConnection = primary.AsT0; |
| 43 | + |
| 44 | + // Insert CUDNN toggle node between sampler and VAE decode |
| 45 | + var cudnnToggleOutput = e.Nodes.AddTypedNode( |
| 46 | + new ComfyNodeBuilder.CUDNNToggleAutoPassthrough |
| 47 | + { |
| 48 | + Name = e.Nodes.GetUniqueName("CUDNNToggle"), |
| 49 | + Model = null, |
| 50 | + Conditioning = null, |
| 51 | + Latent = latentConnection, // Pass through the latent from sampler |
| 52 | + EnableCudnn = !card.DisableCudnn, |
| 53 | + CudnnBenchmark = false, |
| 54 | + } |
| 55 | + ); |
| 56 | + |
| 57 | + // Update the primary connection to use the CUDNN toggle latent output (Output3) |
| 58 | + // This ensures VAE decode receives latent from CUDNN toggle instead of directly from sampler |
| 59 | + e.Builder.Connections.Primary = cudnnToggleOutput.Output3; |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments