Browse Source

- Applied a lot of minor R# code quality suggestions. Lots of unnecessary imports removed.

- Deleted `NativeInfo` (internal class, not used anywhere)
tags/v0.5.1
Martin Evans 2 years ago
parent
commit
2830e5755c
25 changed files with 19 additions and 72 deletions
  1. +0
    -1
      LLama.Examples/NewVersion/ChatSessionStripRoleName.cs
  2. +0
    -1
      LLama.Examples/NewVersion/ChatSessionWithRoleName.cs
  3. +0
    -1
      LLama.Examples/NewVersion/InstructModeExecute.cs
  4. +0
    -1
      LLama.Examples/NewVersion/InteractiveModeExecute.cs
  5. +0
    -1
      LLama.Examples/NewVersion/LoadAndSaveSession.cs
  6. +0
    -1
      LLama.Examples/NewVersion/LoadAndSaveState.cs
  7. +1
    -4
      LLama.Examples/Program.cs
  8. +0
    -1
      LLama.Unittest/BasicTest.cs
  9. +1
    -2
      LLama.Unittest/GrammarTest.cs
  10. +1
    -2
      LLama.Unittest/LLamaContextTests.cs
  11. +0
    -3
      LLama/Abstractions/IHistoryTransform.cs
  12. +1
    -4
      LLama/Abstractions/ILLamaExecutor.cs
  13. +2
    -3
      LLama/Abstractions/ITextStreamTransform.cs
  14. +1
    -5
      LLama/Abstractions/ITextTransform.cs
  15. +0
    -1
      LLama/Common/ModelParams.cs
  16. +1
    -4
      LLama/LLamaExecutorBase.cs
  17. +2
    -5
      LLama/LLamaInstructExecutor.cs
  18. +1
    -1
      LLama/LLamaInteractExecutor.cs
  19. +1
    -2
      LLama/Native/LLamaContextParams.cs
  20. +1
    -3
      LLama/Native/LLamaModelQuantizeParams.cs
  21. +1
    -4
      LLama/Native/LLamaTokenData.cs
  22. +2
    -5
      LLama/Native/NativeApi.Quantize.cs
  23. +0
    -15
      LLama/Native/NativeInfo.cs
  24. +2
    -1
      LLama/Native/SafeLlamaModelHandle.cs
  25. +1
    -1
      LLama/Utils.cs

+ 0
- 1
LLama.Examples/NewVersion/ChatSessionStripRoleName.cs View File

@@ -1,5 +1,4 @@
using LLama.Common;
using System.Text;

namespace LLama.Examples.NewVersion
{


+ 0
- 1
LLama.Examples/NewVersion/ChatSessionWithRoleName.cs View File

@@ -1,5 +1,4 @@
using LLama.Common;
using System.Text;

namespace LLama.Examples.NewVersion
{


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

@@ -1,5 +1,4 @@
using LLama.Common;
using System.Text;

namespace LLama.Examples.NewVersion
{


+ 0
- 1
LLama.Examples/NewVersion/InteractiveModeExecute.cs View File

@@ -1,5 +1,4 @@
using LLama.Common;
using System.Text;

namespace LLama.Examples.NewVersion
{


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

@@ -1,5 +1,4 @@
using LLama.Common;
using System.Text;

namespace LLama.Examples.NewVersion
{


+ 0
- 1
LLama.Examples/NewVersion/LoadAndSaveState.cs View File

@@ -1,5 +1,4 @@
using LLama.Common;
using System.Text;

namespace LLama.Examples.NewVersion
{


+ 1
- 4
LLama.Examples/Program.cs View File

@@ -1,7 +1,4 @@
using LLama;
using LLama.Common;
using LLama.Examples;
using LLama.Examples.NewVersion;
using LLama.Examples.NewVersion;
using LLama.Examples.Old;

Console.WriteLine("======================================================================================================");


+ 0
- 1
LLama.Unittest/BasicTest.cs View File

@@ -1,4 +1,3 @@
using System.Text;
using LLama.Common;

namespace LLama.Unittest


+ 1
- 2
LLama.Unittest/GrammarTest.cs View File

@@ -1,5 +1,4 @@
using System.Text;
using LLama.Common;
using LLama.Common;
using LLama.Native;

namespace LLama.Unittest


+ 1
- 2
LLama.Unittest/LLamaContextTests.cs View File

@@ -1,5 +1,4 @@
using System.Text;
using LLama.Common;
using LLama.Common;

namespace LLama.Unittest
{


+ 0
- 3
LLama/Abstractions/IHistoryTransform.cs View File

@@ -1,7 +1,4 @@
using LLama.Common;
using System;
using System.Collections.Generic;
using System.Text;

namespace LLama.Abstractions
{


+ 1
- 4
LLama/Abstractions/ILLamaExecutor.cs View File

@@ -1,7 +1,4 @@
using LLama.Common;
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using System.Threading;

namespace LLama.Abstractions


+ 2
- 3
LLama/Abstractions/ITextStreamTransform.cs View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;

namespace LLama.Abstractions
{
@@ -15,6 +13,7 @@ namespace LLama.Abstractions
/// <param name="tokens"></param>
/// <returns></returns>
IEnumerable<string> Transform(IEnumerable<string> tokens);

/// <summary>
/// Takes a stream of tokens and transforms them, returning a new stream of tokens asynchronously.
/// </summary>


+ 1
- 5
LLama/Abstractions/ITextTransform.cs View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace LLama.Abstractions
namespace LLama.Abstractions
{
/// <summary>
/// An interface for text transformations.


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

@@ -1,6 +1,5 @@
using LLama.Abstractions;
using System;
using System.Text;

namespace LLama.Common
{


+ 1
- 4
LLama/LLamaExecutorBase.cs View File

@@ -266,10 +266,7 @@ namespace LLama
public virtual IEnumerable<string> Infer(string text, IInferenceParams? inferenceParams = null, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
if (inferenceParams is null)
{
inferenceParams = new InferenceParams();
}
inferenceParams ??= new InferenceParams();

InferStateArgs args = new InferStateArgs()
{


+ 2
- 5
LLama/LLamaInstructExecutor.cs View File

@@ -108,10 +108,7 @@ namespace LLama
/// <inheritdoc />
protected override void PreprocessInputs(string text, InferStateArgs args)
{
if(args.Antiprompts is null)
{
args.Antiprompts = new List<string>();
}
args.Antiprompts ??= new List<string>();
args.Antiprompts.Add(_instructionPrefix);
if (_is_prompt_run)
{
@@ -160,7 +157,7 @@ namespace LLama

if (_pastTokensCount > 0 && args.WaitForInput)
{
extraOutputs = new string[] { "\n> " };
extraOutputs = new[] { "\n> " };
return true;
}
}


+ 1
- 1
LLama/LLamaInteractExecutor.cs View File

@@ -154,7 +154,7 @@ namespace LLama

if (_embeds.Count > 0 && _embeds.Last() == NativeApi.llama_token_eos())
{
extraOutputs = new string[] { " [end of text]\n" };
extraOutputs = new[] { " [end of text]\n" };
return true;
}



+ 1
- 2
LLama/Native/LLamaContextParams.cs View File

@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace LLama.Native
{
public delegate void LlamaProgressCallback(float progress, IntPtr ctx);

[StructLayout(LayoutKind.Sequential)]
public struct LLamaContextParams
{


+ 1
- 3
LLama/Native/LLamaModelQuantizeParams.cs View File

@@ -1,6 +1,4 @@
using System.Runtime.InteropServices;

namespace LLama.Native
namespace LLama.Native
{
/// <summary>
/// Quantizer parameters used in the native API


+ 1
- 4
LLama/Native/LLamaTokenData.cs View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Runtime.InteropServices;

namespace LLama.Native
{


+ 2
- 5
LLama/Native/NativeApi.Quantize.cs View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Runtime.InteropServices;

namespace LLama.Native
{
@@ -16,6 +13,6 @@ namespace LLama.Native
/// <remarks>not great API - very likely to change</remarks>
/// <returns>Returns 0 on success</returns>
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern int llama_model_quantize(string fname_inp, string fname_out, LLamaModelQuantizeParams* param);
public static extern unsafe int llama_model_quantize(string fname_inp, string fname_out, LLamaModelQuantizeParams* param);
}
}

+ 0
- 15
LLama/Native/NativeInfo.cs View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace LLama.Native
{
internal class NativeInfo
{
internal static readonly int LLAMA_FILE_VERSION = 1;
internal static readonly string LLAMA_FILE_MAGIC = "ggjt";
internal static readonly string LLAMA_FILE_MAGIC_UNVERSIONED = "ggml";
internal static readonly string LLAMA_SESSION_MAGIC = "ggsn";
internal static readonly int LLAMA_SESSION_VERSION = 1;
}
}

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

@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Text;
using LLama.Exceptions;

@@ -150,7 +151,7 @@ namespace LLama.Native
var tokens = new int[count];
fixed (int* tokensPtr = &tokens[0])
{
count = NativeApi.llama_tokenize_with_model(this, bytesPtr, tokensPtr, count, add_bos);
NativeApi.llama_tokenize_with_model(this, bytesPtr, tokensPtr, count, add_bos);
return tokens;
}
}


+ 1
- 1
LLama/Utils.cs View File

@@ -102,7 +102,7 @@ namespace LLama
/// <returns></returns>
public static bool SignedByteToBool(sbyte value)
{
return value > 0 ? true : false;
return value > 0;
}

}


Loading…
Cancel
Save