-
-
Notifications
You must be signed in to change notification settings - Fork 502
Inference module to utilize CFZ CUDNN Toggle Node in ComfyUI-Zluda #1440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
608d20a
ba86e20
db1c8d9
422aeec
94e6e6c
335c729
5ed5155
de16787
6c1dc33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <Styles xmlns="https://github.com/avaloniaui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:controls="using:StabilityMatrix.Avalonia.Controls" | ||
| xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData" | ||
| xmlns:vmInference="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Inference" | ||
| x:DataType="vmInference:CfzCudnnToggleCardViewModel"> | ||
| <Design.PreviewWith> | ||
| <controls:CfzCudnnToggleCard Width="400" /> | ||
| </Design.PreviewWith> | ||
|
|
||
| <Style Selector="controls|CfzCudnnToggleCard"> | ||
| <Setter Property="Template"> | ||
| <ControlTemplate> | ||
| <controls:Card x:Name="PART_Card"> | ||
| <StackPanel Spacing="8"> | ||
| <TextBlock Text="Enable CUDNN" FontSize="14" FontWeight="Bold" /> | ||
| <ToggleSwitch | ||
| IsChecked="{Binding EnableCudnn}" | ||
| Margin="8,0,4,0" | ||
| HorizontalAlignment="Stretch" /> | ||
|
|
||
| <TextBlock Text="CUDNN Benchmark" FontSize="14" FontWeight="Bold" /> | ||
| <ToggleSwitch | ||
| IsChecked="{Binding CudnnBenchmark}" | ||
| Margin="8,0,4,0" | ||
| HorizontalAlignment="Stretch" /> | ||
| </StackPanel> | ||
| </controls:Card> | ||
| </ControlTemplate> | ||
| </Setter> | ||
| </Style> | ||
| </Styles> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| using Injectio.Attributes; | ||
|
|
||
| namespace StabilityMatrix.Avalonia.Controls; | ||
|
|
||
| [RegisterTransient<CfzCudnnToggleCard>] | ||
| public class CfzCudnnToggleCard : TemplatedControlBase; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ namespace StabilityMatrix.Avalonia.ViewModels.Base; | |
| [JsonDerivedType(typeof(RescaleCfgCardViewModel), RescaleCfgCardViewModel.ModuleKey)] | ||
| [JsonDerivedType(typeof(PlasmaNoiseCardViewModel), PlasmaNoiseCardViewModel.ModuleKey)] | ||
| [JsonDerivedType(typeof(NrsCardViewModel), NrsCardViewModel.ModuleKey)] | ||
| [JsonDerivedType(typeof(CfzCudnnToggleCardViewModel), CfzCudnnToggleCardViewModel.ModuleKey)] | ||
| [JsonDerivedType(typeof(FreeUModule))] | ||
| [JsonDerivedType(typeof(HiresFixModule))] | ||
| [JsonDerivedType(typeof(FluxHiresFixModule))] | ||
|
|
@@ -41,6 +42,7 @@ namespace StabilityMatrix.Avalonia.ViewModels.Base; | |
| [JsonDerivedType(typeof(RescaleCfgModule))] | ||
| [JsonDerivedType(typeof(PlasmaNoiseModule))] | ||
| [JsonDerivedType(typeof(NRSModule))] | ||
| [JsonDerivedType(typeof(CfzCudnnToggleModule))] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState | ||
| { | ||
| private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using CommunityToolkit.Mvvm.ComponentModel; | ||
| using Injectio.Attributes; | ||
| using StabilityMatrix.Avalonia.Controls; | ||
| using StabilityMatrix.Avalonia.ViewModels.Base; | ||
| using StabilityMatrix.Core.Attributes; | ||
|
|
||
| namespace StabilityMatrix.Avalonia.ViewModels.Inference; | ||
|
|
||
| [View(typeof(CfzCudnnToggleCard))] | ||
| [ManagedService] | ||
| [RegisterTransient<CfzCudnnToggleCardViewModel>] | ||
| public partial class CfzCudnnToggleCardViewModel : LoadableViewModelBase | ||
| { | ||
| public const string ModuleKey = "CfzCudnnToggle"; | ||
|
|
||
| [ObservableProperty] | ||
| private bool enableCudnn = false; | ||
|
|
||
| [ObservableProperty] | ||
| private bool cudnnBenchmark; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| using System.Linq; | ||
| using Injectio.Attributes; | ||
| using StabilityMatrix.Avalonia.Models.Inference; | ||
| using StabilityMatrix.Avalonia.Services; | ||
| using StabilityMatrix.Avalonia.ViewModels.Base; | ||
| using StabilityMatrix.Avalonia.ViewModels.Inference; | ||
| using StabilityMatrix.Core.Attributes; | ||
| using StabilityMatrix.Core.Models.Api.Comfy.Nodes; | ||
| using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes; | ||
| using StabilityMatrix.Core.Models.Inference; | ||
|
|
||
| namespace StabilityMatrix.Avalonia.ViewModels.Inference.Modules; | ||
|
|
||
| [ManagedService] | ||
| [RegisterTransient<CfzCudnnToggleModule>] | ||
| public class CfzCudnnToggleModule : ModuleBase | ||
| { | ||
| /// <inheritdoc /> | ||
| public CfzCudnnToggleModule(IServiceManager<ViewModelBase> vmFactory) | ||
| : base(vmFactory) | ||
| { | ||
| Title = "Disable CUDNN (ComfyUI-Zluda)"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Applies CUDNN Toggle node between sampler latent output and VAE decode | ||
| /// This prevents "GET was unable to find an engine" errors on AMD cards with Zluda | ||
| /// </summary> | ||
| protected override void OnApplyStep(ModuleApplyStepEventArgs e) | ||
| { | ||
| // Get the primary connection (can be latent or image) | ||
| var primary = e.Builder.Connections.Primary; | ||
| if (primary == null) | ||
| { | ||
| return; // No primary connection to process | ||
| } | ||
|
|
||
| // Check if primary is a latent (from sampler output) | ||
| if (primary.IsT0) // T0 is LatentNodeConnection | ||
| { | ||
| var latentConnection = primary.AsT0; | ||
|
|
||
| // Insert CUDNN toggle node between sampler and VAE decode | ||
| var cudnnToggleOutput = e.Nodes.AddTypedNode( | ||
| new ComfyNodeBuilder.CUDNNToggleAutoPassthrough | ||
|
Check failure on line 45 in StabilityMatrix.Avalonia/ViewModels/Inference/Modules/CfzCudnnToggleModule.cs
|
||
| { | ||
| Name = e.Nodes.GetUniqueName("CUDNNToggle"), | ||
| Model = null, | ||
| Conditioning = null, | ||
| Latent = latentConnection, // Pass through the latent from sampler | ||
| enable_cudnn = false, | ||
| cudnn_benchmark = false, | ||
| } | ||
| ); | ||
|
|
||
| // Update the primary connection to use the CUDNN toggle latent output (Output3) | ||
| // This ensures VAE decode receives latent from CUDNN toggle instead of directly from sampler | ||
| e.Builder.Connections.Primary = cudnnToggleOutput.Output3; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The module currently hardcodes To fix this, you should:
I've included a code suggestion that implements these changes. Note that it uses PascalCase property names ( using Injectio.Attributes;
using StabilityMatrix.Avalonia.Models.Inference;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.ViewModels.Inference;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Models.Api.Comfy.Nodes;
using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes;
using StabilityMatrix.Core.Models.Inference;
namespace StabilityMatrix.Avalonia.ViewModels.Inference.Modules;
[ManagedService]
[RegisterTransient<CfzCudnnToggleModule>]
public class CfzCudnnToggleModule : ModuleBase
{
/// <inheritdoc />
public CfzCudnnToggleModule(IServiceManager<ViewModelBase> vmFactory)
: base(vmFactory)
{
Title = "CUDNN Toggle (ComfyUI-Zluda)";
AddCards(vmFactory.Get<CfzCudnnToggleCardViewModel>());
}
private CfzCudnnToggleCardViewModel Card => GetCard<CfzCudnnToggleCardViewModel>();
/// <summary>
/// Applies CUDNN Toggle node between sampler latent output and VAE decode
/// This prevents "GET was unable to find an engine" errors on AMD cards with Zluda
/// </summary>
protected override void OnApplyStep(ModuleApplyStepEventArgs e)
{
// Get the primary connection (can be latent or image)
var primary = e.Builder.Connections.Primary;
if (primary == null)
{
return; // No primary connection to process
}
// Check if primary is a latent (from sampler output)
if (primary.IsT0) // T0 is LatentNodeConnection
{
var latentConnection = primary.AsT0;
// Insert CUDNN toggle node between sampler and VAE decode
var cudnnToggleOutput = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.CUDNNToggleAutoPassthrough
{
Name = e.Nodes.GetUniqueName("CUDNNToggle"),
Model = null,
Conditioning = null,
Latent = latentConnection, // Pass through the latent from sampler
EnableCudnn = Card.EnableCudnn,
CudnnBenchmark = Card.CudnnBenchmark,
}
);
// Update the primary connection to use the CUDNN toggle latent output (Output3)
// This ensures VAE decode receives latent from CUDNN toggle instead of directly from sampler
e.Builder.Connections.Primary = cudnnToggleOutput.Output3;
}
}
} |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve code organization and maintainability, please keep
[JsonDerivedType]attributes sorted alphabetically by the type name.CfzCudnnToggleCardViewModelshould be placed beforeControlNetCardViewModel.