Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit d4574df

Browse files
committed
Lazy load BlankTokenValueArray
1 parent 3c3600c commit d4574df

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

OnnxStack.StableDiffusion/Config/StableDiffusionConfig.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public void Initialize()
2222

2323
foreach (var modelSet in ModelSets)
2424
{
25-
modelSet.InitBlankTokenArray();
2625
foreach (var model in modelSet.ModelConfigurations)
2726
{
2827
if ((model.Type == OnnxModelType.Tokenizer || model.Type == OnnxModelType.Tokenizer2) && string.IsNullOrEmpty(model.OnnxModelPath))

OnnxStack.StableDiffusion/Config/StableDiffusionModelSet.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace OnnxStack.StableDiffusion.Config
1010
{
1111
public record StableDiffusionModelSet : IOnnxModelSetConfig
1212
{
13+
private ImmutableArray<int> _blankTokenValueArray;
14+
1315
public string Name { get; set; }
1416
public bool IsEnabled { get; set; }
1517
public int PadTokenId { get; set; }
@@ -31,12 +33,17 @@ public record StableDiffusionModelSet : IOnnxModelSetConfig
3133
public ExecutionProvider ExecutionProvider { get; set; }
3234
public List<OnnxModelConfig> ModelConfigurations { get; set; }
3335

34-
[JsonIgnore]
35-
public ImmutableArray<int> BlankTokenValueArray { get; set; }
3636

37-
public void InitBlankTokenArray()
37+
[JsonIgnore]
38+
public ImmutableArray<int> BlankTokenValueArray
3839
{
39-
BlankTokenValueArray = Enumerable.Repeat(BlankTokenId, 20480).ToImmutableArray();
40+
get
41+
{
42+
if (_blankTokenValueArray.IsDefaultOrEmpty)
43+
_blankTokenValueArray = Enumerable.Repeat(BlankTokenId, 20480).ToImmutableArray();
44+
45+
return _blankTokenValueArray;
46+
}
4047
}
4148
}
4249
}

OnnxStack.StableDiffusion/Services/StableDiffusionService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public StableDiffusionService(StableDiffusionConfig configuration, IOnnxModelSer
4949
/// <returns></returns>
5050
public async Task<bool> LoadModelAsync(StableDiffusionModelSet model)
5151
{
52-
model.InitBlankTokenArray();
5352
var modelSet = await _modelService.LoadModelAsync(model);
5453
return modelSet is not null;
5554
}

0 commit comments

Comments
 (0)