Skip to content

Commit a7d1139

Browse files
authored
Merge pull request LykosAI#1124 from ionite34/fix-scopes
2 parents 850728e + 3bf92a6 commit a7d1139

6 files changed

Lines changed: 89 additions & 77 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to Stability Matrix will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html).
77

8+
## v2.15.0-pre.2
9+
### Fixed
10+
- Fixed Inference custom step (e.g. HiresFix) Samplers potentially sharing state with other card UIs like model browser.
11+
812
## v2.15.0-pre.1
913
### Added
1014
- Added settings to disable base models from appearing in the Checkpoint Manager and Civitai Model Browser base model selectors

StabilityMatrix.Avalonia/Services/ScopedServiceManager.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace StabilityMatrix.Avalonia.Services;
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
namespace StabilityMatrix.Avalonia.Services;
24

35
internal class ScopedServiceManager<T> : IServiceManager<T>
46
{
@@ -78,6 +80,13 @@ public T Get(Type serviceType)
7880

7981
// 3. If not scoped, delegate to the parent manager to resolve Singleton or Transient
8082
// (Parent's Get will throw if the type isn't registered there either)
81-
return parentManager.Get(serviceType);
83+
// return parentManager.Get(serviceType);
84+
85+
// We don't use parent manager for scoped contexts anymore,
86+
// since we'll lose the scope through transients,
87+
// then we have to make Inference Cards scoped as well,
88+
// which cases samplers to be shared with Civit page and other issues.
89+
// 3. Just use the scoped service provider, since we might need to keep the scope through transients as well
90+
return (T)scopedServiceProvider.GetRequiredService(serviceType);
8291
}
8392
}

StabilityMatrix.Avalonia/ViewModels/Inference/ModelCardViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace StabilityMatrix.Avalonia.ViewModels.Inference;
2020

2121
[View(typeof(ModelCard))]
2222
[ManagedService]
23-
[RegisterScoped<ModelCardViewModel>]
23+
[RegisterTransient<ModelCardViewModel>]
2424
public partial class ModelCardViewModel(
2525
IInferenceClientManager clientManager,
2626
IServiceManager<ViewModelBase> vmFactory,

StabilityMatrix.Avalonia/ViewModels/Inference/PromptCardViewModel.cs

Lines changed: 70 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace StabilityMatrix.Avalonia.ViewModels.Inference;
4545

4646
[View(typeof(PromptCard))]
4747
[ManagedService]
48-
[RegisterScoped<PromptCardViewModel>]
48+
[RegisterTransient<PromptCardViewModel>]
4949
public partial class PromptCardViewModel
5050
: DisposableLoadableViewModelBase,
5151
IParametersLoadableState,
@@ -337,15 +337,15 @@ public void ApplyStep(ModuleApplyStepEventArgs e)
337337
{
338338
Name = $"PositiveCLIP_{modelConnections.Name}",
339339
Clip = e.Builder.Connections.Base.Clip!,
340-
Text = e.Builder.Connections.PositivePrompt
340+
Text = e.Builder.Connections.PositivePrompt,
341341
}
342342
);
343343
var negativeClip = e.Nodes.AddTypedNode(
344344
new ComfyNodeBuilder.CLIPTextEncode
345345
{
346346
Name = $"NegativeCLIP_{modelConnections.Name}",
347347
Clip = e.Builder.Connections.Base.Clip!,
348-
Text = e.Builder.Connections.NegativePrompt
348+
Text = e.Builder.Connections.NegativePrompt,
349349
}
350350
);
351351

@@ -419,60 +419,60 @@ public async Task<bool> ValidatePrompts()
419419
private async Task ShowHelpDialog()
420420
{
421421
var md = $$"""
422-
## {{Resources.Label_Emphasis}}
423-
You can also use (`Ctrl+Up`/`Ctrl+Down`) in the editor to adjust the
424-
weight emphasis of the token under the caret or the currently selected text.
425-
```prompt
426-
(keyword)
427-
(keyword:1.0)
428-
```
429-
430-
## {{Resources.Label_Deemphasis}}
431-
```prompt
432-
[keyword]
433-
```
434-
435-
## {{Resources.Label_EmbeddingsOrTextualInversion}}
436-
They may be used in either the positive or negative prompts.
437-
Essentially they are text presets, so the position where you place them
438-
could make a difference.
439-
```prompt
440-
<embedding:model>
441-
<embedding:model:1.0>
442-
```
443-
444-
## {{Resources.Label_NetworksLoraOrLycoris}}
445-
Unlike embeddings, network tags do not get tokenized to the model,
446-
so the position in the prompt where you place them does not matter.
447-
```prompt
448-
<lora:model>
449-
<lora:model:1.0>
450-
<lyco:model>
451-
<lyco:model:1.0>
452-
```
453-
454-
## {{Resources.Label_Comments}}
455-
Inline comments can be marked by a hashtag ' # '.
456-
All text after a ' # ' on a line will be disregarded during generation.
457-
```prompt
458-
# comments
459-
a red cat # also comments
460-
detailed
461-
```
462-
463-
## {{Resources.Label_Wildcards}}
464-
Wildcards can be used to select a random value from a list of options.
465-
```prompt
466-
{red|green|blue} cat
467-
```
468-
In this example, a color will be randomly chosen at the start of each generation.
469-
The final output could be "red cat", "green cat", or "blue cat".
470-
471-
You can also use networks and embeddings in wildcards. For example:
472-
```prompt
473-
{<lora:model:1>|<embedding:model>} cat
474-
```
475-
""";
422+
## {{Resources.Label_Emphasis}}
423+
You can also use (`Ctrl+Up`/`Ctrl+Down`) in the editor to adjust the
424+
weight emphasis of the token under the caret or the currently selected text.
425+
```prompt
426+
(keyword)
427+
(keyword:1.0)
428+
```
429+
430+
## {{Resources.Label_Deemphasis}}
431+
```prompt
432+
[keyword]
433+
```
434+
435+
## {{Resources.Label_EmbeddingsOrTextualInversion}}
436+
They may be used in either the positive or negative prompts.
437+
Essentially they are text presets, so the position where you place them
438+
could make a difference.
439+
```prompt
440+
<embedding:model>
441+
<embedding:model:1.0>
442+
```
443+
444+
## {{Resources.Label_NetworksLoraOrLycoris}}
445+
Unlike embeddings, network tags do not get tokenized to the model,
446+
so the position in the prompt where you place them does not matter.
447+
```prompt
448+
<lora:model>
449+
<lora:model:1.0>
450+
<lyco:model>
451+
<lyco:model:1.0>
452+
```
453+
454+
## {{Resources.Label_Comments}}
455+
Inline comments can be marked by a hashtag ' # '.
456+
All text after a ' # ' on a line will be disregarded during generation.
457+
```prompt
458+
# comments
459+
a red cat # also comments
460+
detailed
461+
```
462+
463+
## {{Resources.Label_Wildcards}}
464+
Wildcards can be used to select a random value from a list of options.
465+
```prompt
466+
{red|green|blue} cat
467+
```
468+
In this example, a color will be randomly chosen at the start of each generation.
469+
The final output could be "red cat", "green cat", or "blue cat".
470+
471+
You can also use networks and embeddings in wildcards. For example:
472+
```prompt
473+
{<lora:model:1>|<embedding:model>} cat
474+
```
475+
""";
476476

477477
var dialog = DialogHelper.CreateMarkdownDialog(md, "Prompt Syntax", TextEditorPreset.Prompt);
478478
dialog.MinDialogWidth = 800;
@@ -531,7 +531,7 @@ private async Task DebugShowTokens()
531531
builder.AppendLine($"## Networks ({networks.Count}):");
532532
builder.AppendLine("```csharp");
533533
builder.AppendLine(
534-
JsonSerializer.Serialize(networks, new JsonSerializerOptions() { WriteIndented = true, })
534+
JsonSerializer.Serialize(networks, new JsonSerializerOptions() { WriteIndented = true })
535535
);
536536
builder.AppendLine("```");
537537
}
@@ -622,11 +622,10 @@ private async Task AmplifyPrompt()
622622
"illustrious" => [ModelTags.Illustrious],
623623
_ => [],
624624
};
625-
var mode = IsFocused
626-
? PromptExpansionRequestMode.Focused
627-
: IsImaginative
628-
? PromptExpansionRequestMode.Imaginative
629-
: PromptExpansionRequestMode.Balanced;
625+
var mode =
626+
IsFocused ? PromptExpansionRequestMode.Focused
627+
: IsImaginative ? PromptExpansionRequestMode.Imaginative
628+
: PromptExpansionRequestMode.Balanced;
630629
try
631630
{
632631
var expandedPrompt = await promptGenApi.ExpandPrompt(
@@ -636,11 +635,11 @@ private async Task AmplifyPrompt()
636635
{
637636
PositivePrompt = prompt.ProcessedText ?? prompt.RawText,
638637
NegativePrompt = negativePrompt.ProcessedText ?? negativePrompt.RawText,
639-
Model = selectedModel?.Local?.DisplayModelName
638+
Model = selectedModel?.Local?.DisplayModelName,
640639
},
641640
Model = IsThinkingEnabled ? "PromptV1ThinkingDev" : "PromptV1Dev",
642641
Mode = mode,
643-
ModelTags = modelTags
642+
ModelTags = modelTags,
644643
}
645644
);
646645

@@ -661,8 +660,8 @@ private async Task AmplifyPrompt()
661660
"Rate Limit Reached"
662661
);
663662
dialog.PrimaryButtonText = "Upgrade";
664-
dialog.PrimaryButtonCommand = new RelayCommand(
665-
() => ProcessRunner.OpenUrl("https://patreon.com/join/StabilityMatrix")
663+
dialog.PrimaryButtonCommand = new RelayCommand(() =>
664+
ProcessRunner.OpenUrl("https://patreon.com/join/StabilityMatrix")
666665
);
667666
dialog.IsPrimaryButtonEnabled = true;
668667
dialog.DefaultButton = ContentDialogButton.Primary;
@@ -753,7 +752,7 @@ public override JsonObject SaveStateToJsonObject()
753752
{
754753
Prompt = PromptDocument.Text,
755754
NegativePrompt = NegativePromptDocument.Text,
756-
ModulesCardState = ModulesCardViewModel.SaveStateToJsonObject()
755+
ModulesCardState = ModulesCardViewModel.SaveStateToJsonObject(),
757756
}
758757
);
759758
}
@@ -785,7 +784,7 @@ public GenerationParameters SaveStateToParameters(GenerationParameters parameter
785784
return parameters with
786785
{
787786
PositivePrompt = PromptDocument.Text,
788-
NegativePrompt = NegativePromptDocument.Text
787+
NegativePrompt = NegativePromptDocument.Text,
789788
};
790789
}
791790

@@ -799,7 +798,7 @@ private async Task<bool> ShowLoginDialog()
799798
dialog.Buttons =
800799
[
801800
new TaskDialogButton(Resources.Action_Login, TaskDialogStandardResult.OK),
802-
TaskDialogButton.CloseButton
801+
TaskDialogButton.CloseButton,
803802
];
804803

805804
if (await dialog.ShowAsync(true) is not TaskDialogStandardResult.OK)
@@ -808,7 +807,7 @@ private async Task<bool> ShowLoginDialog()
808807
var vm = vmFactory.Get<OAuthDeviceAuthViewModel>();
809808
vm.ChallengeRequest = new OpenIddictClientModels.DeviceChallengeRequest
810809
{
811-
ProviderName = OpenIdClientConstants.LykosAccount.ProviderName
810+
ProviderName = OpenIdClientConstants.LykosAccount.ProviderName,
812811
};
813812
await vm.ShowDialogAsync();
814813

StabilityMatrix.Avalonia/ViewModels/Inference/SamplerCardViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace StabilityMatrix.Avalonia.ViewModels.Inference;
2727

2828
[View(typeof(SamplerCard))]
2929
[ManagedService]
30-
[RegisterScoped<SamplerCardViewModel>]
30+
[RegisterTransient<SamplerCardViewModel>]
3131
public partial class SamplerCardViewModel : LoadableViewModelBase, IParametersLoadableState, IComfyStep
3232
{
3333
private ISettingsManager settingsManager;

StabilityMatrix.Avalonia/ViewModels/Inference/Video/ImgToVidModelCardViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace StabilityMatrix.Avalonia.ViewModels.Inference.Video;
1111

1212
[View(typeof(ModelCard))]
1313
[ManagedService]
14-
[RegisterScoped<ImgToVidModelCardViewModel>]
14+
[RegisterTransient<ImgToVidModelCardViewModel>]
1515
public class ImgToVidModelCardViewModel : ModelCardViewModel
1616
{
1717
public ImgToVidModelCardViewModel(
@@ -30,7 +30,7 @@ public override void ApplyStep(ModuleApplyStepEventArgs e)
3030
new ComfyNodeBuilder.ImageOnlyCheckpointLoader
3131
{
3232
Name = "ImageOnlyCheckpointLoader",
33-
CkptName = SelectedModel?.RelativePath ?? throw new ValidationException("Model not selected")
33+
CkptName = SelectedModel?.RelativePath ?? throw new ValidationException("Model not selected"),
3434
}
3535
);
3636

0 commit comments

Comments
 (0)