tryAGI / tryAGI/LangChain

Unable to run LLamaSharp provider on CPU

Open
#521 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
1.1k
Forks
141
Avg merge
2d 18m
Merged PRs (30d)
2

Description

Describe the bug

I'm trying to run the example code without GPU.
In the console I see the following error:

llama_model_load_from_file_impl: invalid value for main_gpu: 0 (available devices: 0)

Using LLamaSharp directly I can get around this error by setting the GpuLayerCount property of ModelParams to 0.

Steps to reproduce the bug

I've tried the following code:

// get model path
var modelPath = HuggingFaceModelDownloader.GetModelAsync(
    repository: "TheBloke/Thespis-13B-v0.5-GGUF",
    fileName: "thespis-13b-v0.5.Q2_K.gguf",
    version: "main");
    
modelPath.Wait();

    // load model
var model = new LLamaSharpModelInstruction(new LLamaSharpConfiguration
        {
//            MainGpu = -1,
            PathToModelFile = modelPath.Result,
            Temperature = 0,
            GpuLayerCount = 0
        }).UseConsoleForDebug();

// building a chain
var prompt = @"
You are an AI assistant that greets the world.
World: Hello, Assistant!
Assistant:";

var chain =
    Set(prompt, outputKey: "prompt")
    | LLM(model, inputKey: "prompt");

chain.RunAsync().Wait();
Expected behavior

The code should also run without a GPU.

Screenshots

No response

NuGet package version
    <PackageReference Include="LLamaSharp" Version="0.23.0" />
    <PackageReference Include="LLamaSharp.Backend.Cpu" Version="0.23.0" />
    <PackageReference Include="LLamaSharp.semantic-kernel" Version="0.23.0" />
    <PackageReference Include="LLamaSharp.kernel-memory" Version="0.23.0" />
    <PackageReference Include="LangChain" Version="0.17.0" />
    <PackageReference Include="LangChain.Providers.LLamaSharp" Version="0.17.0" />
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduced code using LLamaSharpModelInstruction and LLamaSharpConfiguration, then run it with the LLamaSharp CPU backend and GpuLayerCount set to 0. Compare the provider's configuration with direct LLamaSharp behavior; done means the supplied example runs without a GPU and no invalid main_gpu error occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
ai
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.