Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KernelMemory bug fix #726

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions LLama.KernelMemory/BuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.KernelMemory;
using Microsoft.KernelMemory;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -81,23 +81,22 @@ public static IKernelMemoryBuilder WithLLamaSharpDefaults(this IKernelMemoryBuil
{
var parameters = new ModelParams(config.ModelPath)
{
ContextSize = config?.ContextSize ?? 2048,
Seed = config?.Seed ?? 0,
GpuLayerCount = config?.GpuLayerCount ?? 20,
ContextSize = config.ContextSize ?? 2048,
Seed = config.Seed ?? 0,
GpuLayerCount = config.GpuLayerCount ?? 20,
Embeddings = true,
MainGpu = config?.MainGpu ?? 0,
SplitMode = config?.SplitMode ?? GPUSplitMode.None,
MainGpu = config.MainGpu,
SplitMode = config.SplitMode
};

if (weights == null)
if (weights == null || context == null)
{
weights = LLamaWeights.LoadFromFile(parameters);
context = weights.CreateContext(parameters);
}

var executor = new StatelessExecutor(weights, parameters);
var embedder = new LLamaEmbedder(weights, parameters);
builder.WithLLamaSharpTextEmbeddingGeneration(new LLamaSharpTextEmbeddingGenerator(embedder));
builder.WithLLamaSharpTextEmbeddingGeneration(new LLamaSharpTextEmbeddingGenerator(config, weights));
builder.WithLLamaSharpTextGeneration(new LlamaSharpTextGenerator(weights, context, executor, config?.DefaultInferenceParams));
return builder;
}
Expand Down
9 changes: 8 additions & 1 deletion LLama.KernelMemory/LLamaSharpTextEmbeddingGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LLama;
using LLama;
using LLama.Common;
using LLama.Native;
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.AI;

Expand Down Expand Up @@ -29,6 +30,9 @@ public LLamaSharpTextEmbeddingGenerator(LLamaSharpConfig config)
this._config = config;
var @params = new ModelParams(_config.ModelPath)
{
ContextSize = config.ContextSize ?? 2048,
Seed = config.Seed ?? 0,
GpuLayerCount = config.GpuLayerCount ?? 20,
Embeddings = true,
MainGpu = _config.MainGpu,
SplitMode = _config.SplitMode
Expand All @@ -49,6 +53,9 @@ public LLamaSharpTextEmbeddingGenerator(LLamaSharpConfig config, LLamaWeights we
this._config = config;
var @params = new ModelParams(_config.ModelPath)
{
ContextSize = config.ContextSize ?? 2048,
Seed = config.Seed ?? 0,
GpuLayerCount = config.GpuLayerCount ?? 20,
Embeddings = true,
MainGpu = _config.MainGpu,
SplitMode = _config.SplitMode
Expand Down
Loading