Martin Evans 2 years ago
parent
commit
8746aa5222
46 changed files with 587 additions and 1476 deletions
  1. +1
    -1
      LLama.Examples/Examples/BatchedExecutorGuidance.cs
  2. +2
    -2
      LLama/LLamaStatelessExecutor.cs
  3. +7
    -0
      LLama/Native/LLamaModelMetadataOverride.cs
  4. +10
    -0
      LLama/Native/LLamaModelParams.cs
  5. +10
    -0
      LLama/Native/LLamaModelQuantizeParams.cs
  6. +17
    -0
      LLama/Native/LLamaVocabPreType.cs
  7. +1
    -1
      LLama/Native/NativeApi.Sampling.cs
  8. +12
    -3
      LLama/Native/NativeApi.cs
  9. +22
    -2
      LLama/Native/SafeLlamaModelHandle.cs
  10. BIN
      LLama/runtimes/deps/avx/libllama.dll
  11. BIN
      LLama/runtimes/deps/avx/libllama.so
  12. BIN
      LLama/runtimes/deps/avx/libllava_shared.so
  13. BIN
      LLama/runtimes/deps/avx/llama.dll
  14. BIN
      LLama/runtimes/deps/avx/llava_shared.dll
  15. BIN
      LLama/runtimes/deps/avx2/libllama.dll
  16. BIN
      LLama/runtimes/deps/avx2/libllama.so
  17. BIN
      LLama/runtimes/deps/avx2/libllava_shared.so
  18. BIN
      LLama/runtimes/deps/avx2/llama.dll
  19. BIN
      LLama/runtimes/deps/avx2/llava_shared.dll
  20. BIN
      LLama/runtimes/deps/avx512/libllama.dll
  21. BIN
      LLama/runtimes/deps/avx512/libllama.so
  22. BIN
      LLama/runtimes/deps/avx512/libllava_shared.so
  23. BIN
      LLama/runtimes/deps/avx512/llama.dll
  24. BIN
      LLama/runtimes/deps/avx512/llava_shared.dll
  25. BIN
      LLama/runtimes/deps/clblast/libllama.so
  26. BIN
      LLama/runtimes/deps/clblast/libllava_shared.so
  27. BIN
      LLama/runtimes/deps/clblast/llama.dll
  28. BIN
      LLama/runtimes/deps/clblast/llava_shared.dll
  29. BIN
      LLama/runtimes/deps/cu11.7.1/libllama.so
  30. BIN
      LLama/runtimes/deps/cu11.7.1/libllava_shared.so
  31. BIN
      LLama/runtimes/deps/cu11.7.1/llama.dll
  32. BIN
      LLama/runtimes/deps/cu11.7.1/llava_shared.dll
  33. BIN
      LLama/runtimes/deps/cu12.1.0/libllama.so
  34. BIN
      LLama/runtimes/deps/cu12.1.0/libllava_shared.so
  35. BIN
      LLama/runtimes/deps/cu12.1.0/llama.dll
  36. BIN
      LLama/runtimes/deps/cu12.1.0/llava_shared.dll
  37. BIN
      LLama/runtimes/deps/libllama.dll
  38. BIN
      LLama/runtimes/deps/libllama.so
  39. BIN
      LLama/runtimes/deps/libllava_shared.so
  40. BIN
      LLama/runtimes/deps/llama.dll
  41. BIN
      LLama/runtimes/deps/llava_shared.dll
  42. +505
    -1467
      LLama/runtimes/deps/osx-arm64/ggml-metal.metal
  43. BIN
      LLama/runtimes/deps/osx-arm64/libllama.dylib
  44. BIN
      LLama/runtimes/deps/osx-arm64/libllava_shared.dylib
  45. BIN
      LLama/runtimes/deps/osx-x64/libllama.dylib
  46. BIN
      LLama/runtimes/deps/osx-x64/libllava_shared.dylib

+ 1
- 1
LLama.Examples/Examples/BatchedExecutorGuidance.cs View File

@@ -79,7 +79,7 @@ public class BatchedExecutorGuidance
guidance.Prompt(g);

// Early exit if we reach the natural end of the guided sentence
if (g == model.Tokens.EOS)
if (model.Tokens.IsEndOfGeneration(g))
break;

// Update progress bar


+ 2
- 2
LLama/LLamaStatelessExecutor.cs View File

@@ -123,8 +123,8 @@ namespace LLama
);
}

// Check if this is the EOS token
if (id == _weights.Tokens.EOS)
// Check if this token should end generation
if (_weights.Tokens.IsEndOfGeneration(id))
break;

// Decode this token into text


+ 7
- 0
LLama/Native/LLamaModelMetadataOverride.cs View File

@@ -43,6 +43,8 @@ public unsafe struct LLamaModelMetadataOverride
/// </summary>
[FieldOffset(136)]
public long BoolValue;

//todo: char val_str[128];
}

/// <summary>
@@ -65,4 +67,9 @@ public enum LLamaModelKvOverrideType
/// Overriding a bool value
/// </summary>
Bool = 2,

/// <summary>
/// Overriding a string value
/// </summary>
String = 3,
}

+ 10
- 0
LLama/Native/LLamaModelParams.cs View File

@@ -81,6 +81,16 @@ namespace LLama.Native
}
private sbyte _use_mlock;
/// <summary>
/// validate model tensor data
/// </summary>
public bool check_tensors
{
readonly get => Convert.ToBoolean(_check_tensors);
set => _check_tensors = Convert.ToSByte(value);
}
private sbyte _check_tensors;
/// <summary>
/// Create a LLamaModelParams with default values
/// </summary>


+ 10
- 0
LLama/Native/LLamaModelQuantizeParams.cs View File

@@ -70,6 +70,16 @@ namespace LLama.Native
}
private sbyte _pure;

/// <summary>
/// quantize to the same number of shards
/// </summary>
public bool keep_split
{
get => Convert.ToBoolean(_keep_split);
set => _keep_split = Convert.ToSByte(value);
}
private sbyte _keep_split;

/// <summary>
/// pointer to importance matrix data
/// </summary>


+ 17
- 0
LLama/Native/LLamaVocabPreType.cs View File

@@ -0,0 +1,17 @@
namespace LLama.Native;

/// <summary>
///
/// </summary>
/// <remarks>llama_vocab_pre_type</remarks>
internal enum LLamaVocabPreType
{
LLAMA_VOCAB_PRE_TYPE_DEFAULT = 0,
LLAMA_VOCAB_PRE_TYPE_LLAMA3 = 1,
LLAMA_VOCAB_PRE_TYPE_DEEPSEEK_LLM = 2,
LLAMA_VOCAB_PRE_TYPE_DEEPSEEK_CODER = 3,
LLAMA_VOCAB_PRE_TYPE_FALCON = 4,
LLAMA_VOCAB_PRE_TYPE_MPT = 5,
LLAMA_VOCAB_PRE_TYPE_STARCODER = 6,
LLAMA_VOCAB_PRE_TYPE_GPT2 = 7,
}

+ 1
- 1
LLama/Native/NativeApi.Sampling.cs View File

@@ -176,7 +176,7 @@ namespace LLama.Native
public static extern LLamaToken llama_sample_token_greedy(SafeLLamaContextHandle ctx, ref LLamaTokenDataArrayNative candidates);

/// <summary>
/// Randomly selects a token from the candidates based on their probabilities.
/// Randomly selects a token from the candidates based on their probabilities using the RNG of ctx.
/// </summary>
/// <param name="ctx"></param>
/// <param name="candidates">Pointer to LLamaTokenDataArray</param>


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

@@ -133,6 +133,14 @@ namespace LLama.Native
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint llama_n_seq_max(SafeLLamaContextHandle ctx);

/// <summary>
/// Get the pooling type for this context
/// </summary>
/// <param name="ctx"></param>
/// <returns></returns>
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern LLamaPoolingType llama_pooling_type(SafeLLamaContextHandle ctx);

/// <summary>
/// Get the embeddings for the a specific sequence.
/// Equivalent to: llama_get_embeddings(ctx) + ctx->output_ids[i]*n_embd
@@ -218,19 +226,20 @@ namespace LLama.Native
/// <param name="model"></param>
/// <param name="llamaToken"></param>
/// <param name="buffer">buffer to write string into</param>
/// <param name="special">If true, special tokens are rendered in the output</param>
/// <returns>The length written, or if the buffer is too small a negative that indicates the length required</returns>
public static int llama_token_to_piece(SafeLlamaModelHandle model, LLamaToken llamaToken, Span<byte> buffer)
public static int llama_token_to_piece(SafeLlamaModelHandle model, LLamaToken llamaToken, Span<byte> buffer, bool special)
{
unsafe
{
fixed (byte* bufferPtr = buffer)
{
return llama_token_to_piece_native(model, llamaToken, bufferPtr, buffer.Length);
return llama_token_to_piece_native(model, llamaToken, bufferPtr, buffer.Length, special);
}
}

[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "llama_token_to_piece")]
static extern unsafe int llama_token_to_piece_native(SafeLlamaModelHandle model, LLamaToken llamaToken, byte* buffer, int length);
static extern unsafe int llama_token_to_piece_native(SafeLlamaModelHandle model, LLamaToken llamaToken, byte* buffer, int length, bool special);
}

/// <summary>


+ 22
- 2
LLama/Native/SafeLlamaModelHandle.cs View File

@@ -361,6 +361,15 @@ namespace LLama.Native
/// <returns></returns>
[DllImport(NativeApi.libraryName, CallingConvention = CallingConvention.Cdecl)]
private static extern int llama_token_eot(SafeLlamaModelHandle model);

/// <summary>
/// Check if the token is supposed to end generation (end-of-generation, eg. EOS, EOT, etc.)
/// </summary>
/// <param name="model"></param>
/// <param name="token"></param>
/// <returns></returns>
[DllImport(NativeApi.libraryName, CallingConvention = CallingConvention.Cdecl)]
private static extern bool llama_token_is_eog(SafeLlamaModelHandle model, LLamaToken token);
#endregion

#region LoRA
@@ -402,10 +411,11 @@ namespace LLama.Native
/// </summary>
/// <param name="token">Token to decode</param>
/// <param name="dest">A span to attempt to write into. If this is too small nothing will be written</param>
/// <param name="special">If true, special charcters will be converted to text. If false they will be invisible.</param>
/// <returns>The size of this token. **nothing will be written** if this is larger than `dest`</returns>
public uint TokenToSpan(LLamaToken token, Span<byte> dest)
public uint TokenToSpan(LLamaToken token, Span<byte> dest, bool special = false)
{
var length = NativeApi.llama_token_to_piece(this, token, dest);
var length = NativeApi.llama_token_to_piece(this, token, dest, special);
return (uint)Math.Abs(length);
}

@@ -623,6 +633,16 @@ namespace LLama.Native
/// Codellama end of infill middle
/// </summary>
public LLamaToken? EOT => Normalize(llama_token_eot(_model));

/// <summary>
/// Check if the given token should end generation
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
public bool IsEndOfGeneration(LLamaToken token)
{
return llama_token_is_eog(_model, token);
}
}
}
}

BIN
LLama/runtimes/deps/avx/libllama.dll View File


BIN
LLama/runtimes/deps/avx/libllama.so View File


BIN
LLama/runtimes/deps/avx/libllava_shared.so View File


BIN
LLama/runtimes/deps/avx/llama.dll View File


BIN
LLama/runtimes/deps/avx/llava_shared.dll View File


BIN
LLama/runtimes/deps/avx2/libllama.dll View File


BIN
LLama/runtimes/deps/avx2/libllama.so View File


BIN
LLama/runtimes/deps/avx2/libllava_shared.so View File


BIN
LLama/runtimes/deps/avx2/llama.dll View File


BIN
LLama/runtimes/deps/avx2/llava_shared.dll View File


BIN
LLama/runtimes/deps/avx512/libllama.dll View File


BIN
LLama/runtimes/deps/avx512/libllama.so View File


BIN
LLama/runtimes/deps/avx512/libllava_shared.so View File


BIN
LLama/runtimes/deps/avx512/llama.dll View File


BIN
LLama/runtimes/deps/avx512/llava_shared.dll View File


BIN
LLama/runtimes/deps/clblast/libllama.so View File


BIN
LLama/runtimes/deps/clblast/libllava_shared.so View File


BIN
LLama/runtimes/deps/clblast/llama.dll View File


BIN
LLama/runtimes/deps/clblast/llava_shared.dll View File


BIN
LLama/runtimes/deps/cu11.7.1/libllama.so View File


BIN
LLama/runtimes/deps/cu11.7.1/libllava_shared.so View File


BIN
LLama/runtimes/deps/cu11.7.1/llama.dll View File


BIN
LLama/runtimes/deps/cu11.7.1/llava_shared.dll View File


BIN
LLama/runtimes/deps/cu12.1.0/libllama.so View File


BIN
LLama/runtimes/deps/cu12.1.0/libllava_shared.so View File


BIN
LLama/runtimes/deps/cu12.1.0/llama.dll View File


BIN
LLama/runtimes/deps/cu12.1.0/llava_shared.dll View File


BIN
LLama/runtimes/deps/libllama.dll View File


BIN
LLama/runtimes/deps/libllama.so View File


BIN
LLama/runtimes/deps/libllava_shared.so View File


BIN
LLama/runtimes/deps/llama.dll View File


BIN
LLama/runtimes/deps/llava_shared.dll View File


+ 505
- 1467
LLama/runtimes/deps/osx-arm64/ggml-metal.metal
File diff suppressed because it is too large
View File


BIN
LLama/runtimes/deps/osx-arm64/libllama.dylib View File


BIN
LLama/runtimes/deps/osx-arm64/libllava_shared.dylib View File


BIN
LLama/runtimes/deps/osx-x64/libllama.dylib View File


BIN
LLama/runtimes/deps/osx-x64/libllava_shared.dylib View File


Loading…
Cancel
Save