Skip to content

Commit 4319c0b

Browse files
committed
Add inference workflow profiles
1 parent 31e0f45 commit 4319c0b

5 files changed

Lines changed: 309 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
99
### Added
1010
- Added support for the civitai.red (mature-content) domain — NSFW CivitAI links now open and copy as civitai.red URLs, and pasting a civitai.red URL into the CivitAI model browser search works the same as a civitai.com URL
1111
- Added official Inference support for Z-Image/Z-Image-Turbo, Anima, and Flux.2 UNet-only workflows, including their text encoder, latent, scheduler, and sampling requirements
12+
- Added an Inference workflow profile selector with recommended defaults for Z-Image Base and Z-Image Turbo
1213
### Changed
1314
- The CivitAI base model type filter now uses CivitAI's official `/api/v1/enums` endpoint, with fallbacks to the previous technique and a built-in list, so the filter stays populated even if the CivitAI response format changes or the service is unreachable
1415
### Fixed

StabilityMatrix.Avalonia/Controls/Inference/ModelCard.axaml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,46 @@
239239
</Grid>
240240
</Expander.Header>
241241
<StackPanel Margin="0,4,0,0" Spacing="8">
242+
<!-- Workflow Profile -->
243+
<Grid ColumnDefinitions="90,*,Auto">
244+
<TextBlock
245+
Grid.Column="0"
246+
VerticalAlignment="Center"
247+
Text="Workflow"
248+
TextAlignment="Left" />
249+
<controls:BetterComboBox
250+
Grid.Column="1"
251+
Padding="8,6,4,6"
252+
HorizontalAlignment="Stretch"
253+
ItemsSource="{Binding WorkflowProfiles}"
254+
SelectedItem="{Binding SelectedWorkflowProfile}">
255+
<controls:BetterComboBox.Resources>
256+
<converters:EnumStringConverter x:Key="EnumStringConverter" />
257+
</controls:BetterComboBox.Resources>
258+
<controls:BetterComboBox.ItemTemplate>
259+
<DataTemplate>
260+
<TextBlock Text="{Binding ., Converter={StaticResource EnumStringConverter}}" />
261+
</DataTemplate>
262+
</controls:BetterComboBox.ItemTemplate>
263+
<controls:BetterComboBox.SelectionBoxItemTemplate>
264+
<DataTemplate>
265+
<TextBlock Text="{Binding ., Converter={StaticResource EnumStringConverter}}" />
266+
</DataTemplate>
267+
</controls:BetterComboBox.SelectionBoxItemTemplate>
268+
</controls:BetterComboBox>
269+
<Button
270+
Grid.Column="2"
271+
Margin="4,0,0,0"
272+
VerticalAlignment="Stretch"
273+
Command="{Binding ApplyRecommendedDefaultsCommand}"
274+
IsEnabled="{Binding HasRecommendedDefaults}"
275+
ToolTip.Tip="Apply recommended sampler defaults">
276+
<fluent:SymbolIcon FontSize="16" Symbol="Sparkle" />
277+
</Button>
278+
</Grid>
279+
242280
<!-- Encoder Type -->
243-
<Grid ColumnDefinitions="90,*">
281+
<Grid ColumnDefinitions="90,*" IsVisible="{Binding ShowEncoderTypeSelection}">
244282
<TextBlock
245283
Grid.Column="0"
246284
VerticalAlignment="Center"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using StabilityMatrix.Core.Extensions;
2+
3+
namespace StabilityMatrix.Avalonia.Models.Inference;
4+
5+
public enum InferenceWorkflowProfile
6+
{
7+
[StringValue("Auto")]
8+
Auto,
9+
10+
[StringValue("Default / Checkpoint")]
11+
DefaultCheckpoint,
12+
13+
[StringValue("Flux")]
14+
Flux,
15+
16+
[StringValue("Flux.2")]
17+
Flux2,
18+
19+
[StringValue("Z-Image Base")]
20+
ZImageBase,
21+
22+
[StringValue("Z-Image Turbo")]
23+
ZImageTurbo,
24+
25+
[StringValue("Anima / SD")]
26+
Anima,
27+
28+
[StringValue("HiDream")]
29+
HiDream,
30+
31+
[StringValue("Custom")]
32+
Custom,
33+
}

StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using StabilityMatrix.Core.Attributes;
1515
using StabilityMatrix.Core.Extensions;
1616
using StabilityMatrix.Core.Models;
17+
using StabilityMatrix.Core.Models.Api.Comfy;
1718
using StabilityMatrix.Core.Models.Api.Comfy.Nodes;
1819
using StabilityMatrix.Core.Models.Inference;
1920
using StabilityMatrix.Core.Models.Settings;
@@ -77,6 +78,7 @@ TabContext tabContext
7778
SeedCardViewModel.GenerateNewSeed();
7879

7980
ModelCardViewModel = vmFactory.Get<ModelCardViewModel>();
81+
ModelCardViewModel.RecommendedDefaultsRequested += ApplyRecommendedDefaults;
8082

8183
// When the model changes in the ModelCardViewModel, we'll have access to it in the TabContext
8284

@@ -169,7 +171,7 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
169171

170172
var useSd3Latent =
171173
SamplerCardViewModel.ModulesCardViewModel.IsModuleEnabled<FluxGuidanceModule>()
172-
|| (IsUnetLoader && !IsStableDiffusionUnet && !IsFlux2Unet);
174+
|| (IsUnetLoader && UsesSd3Latent);
173175
var usePlasmaNoise = SamplerCardViewModel.ModulesCardViewModel.IsModuleEnabled<PlasmaNoiseModule>();
174176

175177
if (IsFlux2Unet)
@@ -245,16 +247,62 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
245247

246248
protected bool IsUnetLoader => ModelCardViewModel.SelectedModelLoader is ModelLoader.Unet;
247249

248-
protected bool IsStableDiffusionUnet =>
249-
IsUnetLoader && ModelCardViewModel.SelectedClipType is "stable_diffusion";
250+
protected InferenceWorkflowProfile ResolvedWorkflowProfile => ModelCardViewModel.ResolvedWorkflowProfile;
250251

251-
protected bool IsFlux2Unet => IsUnetLoader && ModelCardViewModel.SelectedClipType is "flux2";
252+
protected bool IsAnimaUnet =>
253+
IsUnetLoader
254+
&& (
255+
ResolvedWorkflowProfile is InferenceWorkflowProfile.Anima
256+
|| (
257+
ResolvedWorkflowProfile is InferenceWorkflowProfile.Custom
258+
&& ModelCardViewModel.SelectedClipType is "stable_diffusion"
259+
)
260+
);
261+
262+
protected bool IsFlux2Unet =>
263+
IsUnetLoader
264+
&& (
265+
ResolvedWorkflowProfile is InferenceWorkflowProfile.Flux2
266+
|| (
267+
ResolvedWorkflowProfile is InferenceWorkflowProfile.Custom
268+
&& ModelCardViewModel.SelectedClipType is "flux2"
269+
)
270+
);
252271

253-
protected bool IsLumina2Unet => IsUnetLoader && ModelCardViewModel.SelectedClipType is "lumina2";
272+
protected bool IsZImageUnet =>
273+
IsUnetLoader
274+
&& (
275+
ResolvedWorkflowProfile
276+
is InferenceWorkflowProfile.ZImageBase
277+
or InferenceWorkflowProfile.ZImageTurbo
278+
|| (
279+
ResolvedWorkflowProfile is InferenceWorkflowProfile.Custom
280+
&& ModelCardViewModel.SelectedClipType is "lumina2"
281+
)
282+
);
283+
284+
protected bool UsesSd3Latent =>
285+
ResolvedWorkflowProfile
286+
is InferenceWorkflowProfile.Flux
287+
or InferenceWorkflowProfile.ZImageBase
288+
or InferenceWorkflowProfile.ZImageTurbo
289+
or InferenceWorkflowProfile.HiDream
290+
|| (
291+
ResolvedWorkflowProfile is InferenceWorkflowProfile.Custom
292+
&& ModelCardViewModel.SelectedClipType is not "stable_diffusion" and not "flux2"
293+
);
294+
295+
protected bool UsesFluxGuidanceSampler =>
296+
ResolvedWorkflowProfile is InferenceWorkflowProfile.Flux or InferenceWorkflowProfile.HiDream
297+
|| (
298+
ResolvedWorkflowProfile is InferenceWorkflowProfile.Custom
299+
&& IsUnetLoader
300+
&& ModelCardViewModel.SelectedClipType is not "stable_diffusion" and not "lumina2" and not "flux2"
301+
);
254302

255303
protected void ApplyModelSamplingForCurrentWorkflow(ModuleApplyStepEventArgs applyArgs)
256304
{
257-
if (!IsLumina2Unet)
305+
if (!IsZImageUnet)
258306
return;
259307

260308
var builder = applyArgs.Builder;
@@ -281,7 +329,7 @@ protected void ApplySamplerForCurrentWorkflow(
281329
}
282330
else if (
283331
(includeGgufAsFluxGuidance && ModelCardViewModel.IsGguf)
284-
|| (IsUnetLoader && !IsStableDiffusionUnet && !IsLumina2Unet)
332+
|| (IsUnetLoader && UsesFluxGuidanceSampler)
285333
)
286334
{
287335
SamplerCardViewModel.ApplyStepsInitialCustomSampler(applyArgs, true);
@@ -296,6 +344,25 @@ protected void ApplySamplerForCurrentWorkflow(
296344
}
297345
}
298346

347+
private void ApplyRecommendedDefaults(InferenceWorkflowProfile profile)
348+
{
349+
switch (profile)
350+
{
351+
case InferenceWorkflowProfile.ZImageTurbo:
352+
SamplerCardViewModel.SelectedSampler = ComfySampler.ResMultistep;
353+
SamplerCardViewModel.SelectedScheduler = ComfyScheduler.Simple;
354+
SamplerCardViewModel.Steps = 8;
355+
SamplerCardViewModel.CfgScale = 1.0d;
356+
break;
357+
case InferenceWorkflowProfile.ZImageBase:
358+
SamplerCardViewModel.SelectedSampler = ComfySampler.ResMultistep;
359+
SamplerCardViewModel.SelectedScheduler = ComfyScheduler.Simple;
360+
SamplerCardViewModel.Steps = 30;
361+
SamplerCardViewModel.CfgScale = 4.0d;
362+
break;
363+
}
364+
}
365+
299366
/// <inheritdoc />
300367
protected override IEnumerable<ImageSource> GetInputImages()
301368
{

0 commit comments

Comments
 (0)