This repository was archived by the owner on Nov 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +16
-29
lines changed
OnnxStack.ImageUpscaler/Config
OnnxStack.StableDiffusion/Config
OnnxStack.UI/UserControls Expand file tree Collapse file tree 6 files changed +16
-29
lines changed Original file line number Diff line number Diff line change @@ -57,23 +57,6 @@ public static SessionOptions GetSessionOptions(this OnnxModelConfig configuratio
5757 }
5858 }
5959
60- /// <summary>
61- /// Applies the configuration overrides.
62- /// </summary>
63- public static void ApplyConfigurationOverrides ( this IOnnxModelSetConfig innxModelSetConfig )
64- {
65- if ( innxModelSetConfig . ModelConfigurations . IsNullOrEmpty ( ) )
66- return ;
67-
68- foreach ( var modelConfig in innxModelSetConfig . ModelConfigurations )
69- {
70- modelConfig . DeviceId ??= innxModelSetConfig . DeviceId ;
71- modelConfig . ExecutionMode ??= innxModelSetConfig . ExecutionMode ;
72- modelConfig . InterOpNumThreads ??= innxModelSetConfig . InterOpNumThreads ;
73- modelConfig . IntraOpNumThreads ??= innxModelSetConfig . IntraOpNumThreads ;
74- modelConfig . ExecutionProvider ??= innxModelSetConfig . ExecutionProvider ;
75- }
76- }
7760
7861 /// <summary>
7962 /// Determines whether the the source sequence is null or empty
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ public OnnxModelSet(IOnnxModelSetConfig configuration)
2222 _prePackedWeightsContainer = new PrePackedWeightsContainer ( ) ;
2323 _modelSessions = configuration . ModelConfigurations . ToImmutableDictionary (
2424 modelConfig => modelConfig . Type ,
25- modelConfig => new OnnxModelSession ( modelConfig , _prePackedWeightsContainer ) ) ;
25+ modelConfig => new OnnxModelSession ( ApplyConfigurationOverrides ( modelConfig ) , _prePackedWeightsContainer ) ) ;
2626 }
2727
2828
@@ -95,5 +95,19 @@ public void Dispose()
9595 }
9696 _prePackedWeightsContainer ? . Dispose ( ) ;
9797 }
98+
99+ private OnnxModelConfig ApplyConfigurationOverrides ( OnnxModelConfig onnxModelConfig )
100+ {
101+ return new OnnxModelConfig
102+ {
103+ Type = onnxModelConfig . Type ,
104+ OnnxModelPath = onnxModelConfig . OnnxModelPath ,
105+ DeviceId = onnxModelConfig . DeviceId ?? _configuration . DeviceId ,
106+ ExecutionMode = onnxModelConfig . ExecutionMode ?? _configuration . ExecutionMode ,
107+ ExecutionProvider = onnxModelConfig . ExecutionProvider ?? _configuration . ExecutionProvider ,
108+ InterOpNumThreads = onnxModelConfig . InterOpNumThreads ?? _configuration . InterOpNumThreads ,
109+ IntraOpNumThreads = onnxModelConfig . IntraOpNumThreads ?? _configuration . IntraOpNumThreads ,
110+ } ;
111+ }
98112 }
99113}
Original file line number Diff line number Diff line change @@ -11,13 +11,6 @@ public class ImageUpscalerConfig : IConfigSection
1111
1212 public void Initialize ( )
1313 {
14- if ( ModelSets . IsNullOrEmpty ( ) )
15- return ;
16-
17- foreach ( var modelSet in ModelSets )
18- {
19- modelSet . ApplyConfigurationOverrides ( ) ;
20- }
2114 }
2215 }
2316}
Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ public void Initialize()
2323 foreach ( var modelSet in ModelSets )
2424 {
2525 modelSet . InitBlankTokenArray ( ) ;
26- modelSet . ApplyConfigurationOverrides ( ) ;
2726 foreach ( var model in modelSet . ModelConfigurations )
2827 {
2928 if ( ( model . Type == OnnxModelType . Tokenizer || model . Type == OnnxModelType . Tokenizer2 ) && string . IsNullOrEmpty ( model . OnnxModelPath ) )
Original file line number Diff line number Diff line change @@ -126,8 +126,7 @@ private async Task LoadModel()
126126 }
127127
128128 SelectedModel . ModelSet . InitBlankTokenArray ( ) ;
129- SelectedModel . ModelSet . ApplyConfigurationOverrides ( ) ;
130- await _stableDiffusionService . AddModelAsync ( SelectedModel . ModelSet ) ;
129+ await _stableDiffusionService . UpdateModelAsync ( SelectedModel . ModelSet ) ;
131130 SelectedModel . IsLoaded = await _stableDiffusionService . LoadModelAsync ( SelectedModel . ModelSet ) ;
132131 }
133132 catch ( Exception ex )
Original file line number Diff line number Diff line change @@ -84,7 +84,6 @@ private async Task LoadModel()
8484 }
8585 }
8686
87- SelectedModel . ModelSet . ApplyConfigurationOverrides ( ) ;
8887 await _upscaleService . AddModelAsync ( SelectedModel . ModelSet ) ;
8988 SelectedModel . IsLoaded = await _upscaleService . LoadModelAsync ( SelectedModel . ModelSet ) ;
9089 }
You can’t perform that action at this time.
0 commit comments