Skip to content

Commit e2a770e

Browse files
authored
Merge pull request SciSharp#726 from zsogitbe/fix_kernelmemory_bug
KernelMemory bug fix
2 parents 9a6e8b5 + 7b309d7 commit e2a770e

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

LLama.KernelMemory/BuilderExtensions.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.KernelMemory;
1+
using Microsoft.KernelMemory;
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
@@ -81,23 +81,22 @@ public static IKernelMemoryBuilder WithLLamaSharpDefaults(this IKernelMemoryBuil
8181
{
8282
var parameters = new ModelParams(config.ModelPath)
8383
{
84-
ContextSize = config?.ContextSize ?? 2048,
85-
Seed = config?.Seed ?? 0,
86-
GpuLayerCount = config?.GpuLayerCount ?? 20,
84+
ContextSize = config.ContextSize ?? 2048,
85+
Seed = config.Seed ?? 0,
86+
GpuLayerCount = config.GpuLayerCount ?? 20,
8787
Embeddings = true,
88-
MainGpu = config?.MainGpu ?? 0,
89-
SplitMode = config?.SplitMode ?? GPUSplitMode.None,
88+
MainGpu = config.MainGpu,
89+
SplitMode = config.SplitMode
9090
};
9191

92-
if (weights == null)
92+
if (weights == null || context == null)
9393
{
9494
weights = LLamaWeights.LoadFromFile(parameters);
9595
context = weights.CreateContext(parameters);
9696
}
9797

9898
var executor = new StatelessExecutor(weights, parameters);
99-
var embedder = new LLamaEmbedder(weights, parameters);
100-
builder.WithLLamaSharpTextEmbeddingGeneration(new LLamaSharpTextEmbeddingGenerator(embedder));
99+
builder.WithLLamaSharpTextEmbeddingGeneration(new LLamaSharpTextEmbeddingGenerator(config, weights));
101100
builder.WithLLamaSharpTextGeneration(new LlamaSharpTextGenerator(weights, context, executor, config?.DefaultInferenceParams));
102101
return builder;
103102
}

LLama.KernelMemory/LLamaSharpTextEmbeddingGenerator.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using LLama;
1+
using LLama;
22
using LLama.Common;
3+
using LLama.Native;
34
using Microsoft.KernelMemory;
45
using Microsoft.KernelMemory.AI;
56

@@ -29,6 +30,9 @@ public LLamaSharpTextEmbeddingGenerator(LLamaSharpConfig config)
2930
this._config = config;
3031
var @params = new ModelParams(_config.ModelPath)
3132
{
33+
ContextSize = config.ContextSize ?? 2048,
34+
Seed = config.Seed ?? 0,
35+
GpuLayerCount = config.GpuLayerCount ?? 20,
3236
Embeddings = true,
3337
MainGpu = _config.MainGpu,
3438
SplitMode = _config.SplitMode
@@ -49,6 +53,9 @@ public LLamaSharpTextEmbeddingGenerator(LLamaSharpConfig config, LLamaWeights we
4953
this._config = config;
5054
var @params = new ModelParams(_config.ModelPath)
5155
{
56+
ContextSize = config.ContextSize ?? 2048,
57+
Seed = config.Seed ?? 0,
58+
GpuLayerCount = config.GpuLayerCount ?? 20,
5259
Embeddings = true,
5360
MainGpu = _config.MainGpu,
5461
SplitMode = _config.SplitMode

0 commit comments

Comments
 (0)