You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

LLamaContextTests.cs 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using LLama.Common;
  2. namespace LLama.Unittest
  3. {
  4. public sealed class LLamaContextTests
  5. : IDisposable
  6. {
  7. private readonly LLamaWeights _weights;
  8. private readonly LLamaContext _context;
  9. public LLamaContextTests()
  10. {
  11. var @params = new ModelParams(Constants.ModelPath);
  12. _weights = LLamaWeights.LoadFromFile(@params);
  13. _context = _weights.CreateContext(@params);
  14. }
  15. public void Dispose()
  16. {
  17. _weights.Dispose();
  18. _context.Dispose();
  19. }
  20. [Fact]
  21. public void CheckProperties()
  22. {
  23. Assert.Equal(4096, _context.ContextSize);
  24. Assert.Equal(4096, _context.EmbeddingSize);
  25. Assert.Equal(32000, _context.VocabCount);
  26. Assert.Equal(0, _context.KVCacheTokenCount);
  27. }
  28. [Fact]
  29. public void Tokenize()
  30. {
  31. var tokens = _context.Tokenize("The quick brown fox", true);
  32. Assert.Equal(new[] { 1, 450, 4996, 17354, 1701, 29916 }, tokens);
  33. }
  34. [Fact]
  35. public void TokenizeWithoutBOS()
  36. {
  37. var tokens = _context.Tokenize("The quick brown fox", false);
  38. Assert.Equal(new[] { 450, 4996, 17354, 1701, 29916 }, tokens);
  39. }
  40. [Fact]
  41. public void TokenizeEmpty()
  42. {
  43. var tokens = _context.Tokenize("", false);
  44. Assert.Equal(Array.Empty<int>(), tokens);
  45. }
  46. }
  47. }