Browse Source

feat: upgrade the native libraries.

tags/v0.4.1-preview
Yaohui Liu 3 years ago
parent
commit
1062fe1a7e
No known key found for this signature in database GPG Key ID: E86D01E1809BD23E
16 changed files with 52 additions and 7 deletions
  1. +1
    -1
      LLama.Examples/NewVersion/InstructModeExecute.cs
  2. +2
    -2
      LLama.Examples/NewVersion/InteractiveModeExecute.cs
  3. +1
    -1
      LLama.Examples/NewVersion/LoadAndSaveSession.cs
  4. +3
    -0
      LLama/Common/InferenceParams.cs
  5. +20
    -1
      LLama/Common/ModelParams.cs
  6. +7
    -0
      LLama/LLamaInstructExecutor.cs
  7. +2
    -2
      LLama/LLamaSharp.csproj
  8. +3
    -0
      LLama/Native/NativeApi.cs
  9. +13
    -0
      LLama/Utils.cs
  10. BIN
      LLama/runtimes/libllama-cuda11.dll
  11. BIN
      LLama/runtimes/libllama-cuda11.so
  12. BIN
      LLama/runtimes/libllama-cuda12.dll
  13. BIN
      LLama/runtimes/libllama-cuda12.so
  14. BIN
      LLama/runtimes/libllama.dll
  15. BIN
      LLama/runtimes/libllama.dylib
  16. BIN
      LLama/runtimes/libllama.so

+ 1
- 1
LLama.Examples/NewVersion/InstructModeExecute.cs View File

@@ -22,7 +22,7 @@ namespace LLama.Examples.NewVersion
"make friend with human, no less than 200 words.\"");
Console.ForegroundColor = ConsoleColor.White;

var inferenceParams = new InferenceParams() { Temperature = 0.8f, MaxTokens = 300 };
var inferenceParams = new InferenceParams() { Temperature = 0.8f, MaxTokens = 600 };

while (true)
{


+ 2
- 2
LLama.Examples/NewVersion/InteractiveModeExecute.cs View File

@@ -18,12 +18,12 @@ namespace LLama.Examples.NewVersion
InteractiveExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 256)));

Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("The executor has been enabled. In this example, the prompt is printed, the maximum tokens is set to 64 and the context size is 256. (an example for small scale usage)");
Console.WriteLine("The executor has been enabled. In this example, the prompt is printed, the maximum tokens is set to 128 and the context size is 256. (an example for small scale usage)");
Console.ForegroundColor = ConsoleColor.White;

Console.Write(prompt);

var inferenceParams = new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" }, MaxTokens = 64 };
var inferenceParams = new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" }, MaxTokens = 128 };

while (true)
{


+ 1
- 1
LLama.Examples/NewVersion/LoadAndSaveSession.cs View File

@@ -47,7 +47,7 @@ namespace LLama.Examples.NewVersion

ex.Model.Dispose();
ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5)));
session = new ChatSession(ex).WithOutputTransform(new LLamaTransforms.KeywordTextOutputStreamTransform(new string[] { "User:", "Bob:" }, redundancyLength: 8));
session = new ChatSession(ex);
session.LoadSession(statePath);

Console.ForegroundColor = ConsoleColor.Yellow;


+ 3
- 0
LLama/Common/InferenceParams.cs View File

@@ -5,6 +5,9 @@ using System.Text;
namespace LLama.Common
{
using llama_token = Int32;
/// <summary>
/// The paramters used for inference.
/// </summary>
public class InferenceParams
{
/// <summary>


+ 20
- 1
LLama/Common/ModelParams.cs View File

@@ -4,13 +4,23 @@ using System.Text;

namespace LLama.Common
{
/// <summary>
/// The parameters for initializing a LLama model.
/// </summary>
public class ModelParams
{
/// <summary>
/// Model context size (n_ctx)
/// </summary>
public int ContextSize { get; set; } = 512;

/// <summary>
/// the GPU that is used for scratch and small tensors
/// </summary>
public int MainGpu { get; set; } = 0;
/// <summary>
/// if true, reduce VRAM usage at the cost of performance
/// </summary>
public bool LowVram { get; set; } = false;
/// <summary>
/// Number of layers to run in VRAM / GPU memory (n_gpu_layers)
/// </summary>
@@ -40,6 +50,10 @@ namespace LLama.Common
/// </summary>
public string ModelPath { get; set; }
/// <summary>
/// model alias
/// </summary>
public string ModelAlias { get; set; } = "unknown";
/// <summary>
/// lora adapter path (lora_adapter)
/// </summary>
public string LoraAdapter { get; set; } = string.Empty;
@@ -67,6 +81,11 @@ namespace LLama.Common
/// </summary>
public bool EmbeddingMode { get; set; } = false;

/// <summary>
/// how split tensors should be distributed across GPUs
/// </summary>
public float[] TensorSplits { get; set; } = new float[] { 0 };

/// <summary>
///
/// </summary>


+ 7
- 0
LLama/LLamaInstructExecutor.cs View File

@@ -17,6 +17,7 @@ namespace LLama
public class InstructExecutor : StatefulExecutorBase
{
bool _is_prompt_run = true;
string _instructionPrefix;
llama_token[] _inp_pfx;
llama_token[] _inp_sfx;
/// <summary>
@@ -30,6 +31,7 @@ namespace LLama
{
_inp_pfx = _model.Tokenize(instructionPrefix, true).ToArray();
_inp_sfx = _model.Tokenize(instructionSuffix, false).ToArray();
_instructionPrefix = instructionPrefix;
}

/// <inheritdoc />
@@ -104,6 +106,11 @@ namespace LLama
/// <inheritdoc />
protected override void PreprocessInputs(string text, InferStateArgs args)
{
if(args.Antiprompts is null)
{
args.Antiprompts = new List<string>();
}
args.Antiprompts.Add(_instructionPrefix);
if (_is_prompt_run)
{
// When running the first input (prompt) in inteactive mode, we should specially process it.


+ 2
- 2
LLama/LLamaSharp.csproj View File

@@ -8,7 +8,7 @@
<Platforms>AnyCPU;x64;Arm64</Platforms>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>

<Version>0.4.0</Version>
<Version>0.4.1</Version>
<Authors>Yaohui Liu, Haiping Chen</Authors>
<Company>SciSharp STACK</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -21,7 +21,7 @@
The .NET binding of LLama.cpp, providing APIs to run the model and deploy it on Web. For model weights to run, please go to https://github.com/SciSharp/LLamaSharp for more information.
</Description>
<PackageReleaseNotes>
LLamaSharp 0.4.0 supports better APIs than v0.3.0. Note that many break changes were made in this version. APIs of v0.3.0 were moved to LLama.Old namespace.
LLamaSharp 0.4.1 followed up the master branch of llama.cpp. (commit id: aacdbd4)
</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageOutputPath>packages</PackageOutputPath>


+ 3
- 0
LLama/Native/NativeApi.cs View File

@@ -44,6 +44,9 @@ namespace LLama.Native
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern bool llama_mlock_supported();

[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern int llama_eval_export(SafeLLamaContextHandle ctx, string fname);

/// <summary>
/// Various functions for loading a ggml llama model.
/// Allocate (almost) all memory needed for the model.


+ 13
- 0
LLama/Utils.cs View File

@@ -18,6 +18,8 @@ namespace LLama
var lparams = NativeApi.llama_context_default_params();

lparams.n_ctx = @params.ContextSize;
lparams.n_batch = @params.BatchSize;
lparams.main_gpu = @params.MainGpu;
lparams.n_gpu_layers = @params.GpuLayerCount;
lparams.seed = @params.Seed;
lparams.f16_kv = @params.UseFp16Memory;
@@ -25,6 +27,17 @@ namespace LLama
lparams.use_mlock = @params.UseMemoryLock;
lparams.logits_all = @params.Perplexity;
lparams.embedding = @params.EmbeddingMode;
lparams.low_vram = @params.LowVram;

if(@params.TensorSplits.Length != 1)
{
throw new ArgumentException("Currently multi-gpu support is not supported by " +
"both llama.cpp and LLamaSharp.");
}
lparams.tensor_split = new TensorSplits()
{
Item1 = @params.TensorSplits[0]
};

if (!File.Exists(@params.ModelPath))
{


BIN
LLama/runtimes/libllama-cuda11.dll View File


BIN
LLama/runtimes/libllama-cuda11.so View File


BIN
LLama/runtimes/libllama-cuda12.dll View File


BIN
LLama/runtimes/libllama-cuda12.so View File


BIN
LLama/runtimes/libllama.dll View File


BIN
LLama/runtimes/libllama.dylib View File


BIN
LLama/runtimes/libllama.so View File


Loading…
Cancel
Save