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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. {
  13. ContextSize = 768,
  14. };
  15. _weights = LLamaWeights.LoadFromFile(@params);
  16. _context = _weights.CreateContext(@params);
  17. }
  18. public void Dispose()
  19. {
  20. _weights.Dispose();
  21. _context.Dispose();
  22. }
  23. [Fact]
  24. public void CheckProperties()
  25. {
  26. Assert.Equal(768, _context.ContextSize);
  27. Assert.Equal(4096, _context.EmbeddingSize);
  28. Assert.Equal(32000, _context.VocabCount);
  29. }
  30. [Fact]
  31. public void Tokenize()
  32. {
  33. var tokens = _context.Tokenize("The quick brown fox", true);
  34. Assert.Equal(new[] { 1, 450, 4996, 17354, 1701, 29916 }, tokens);
  35. }
  36. [Fact]
  37. public void TokenizeWithoutBOS()
  38. {
  39. var tokens = _context.Tokenize("The quick brown fox", false);
  40. Assert.Equal(new[] { 450, 4996, 17354, 1701, 29916 }, tokens);
  41. }
  42. [Fact]
  43. public void TokenizeEmpty()
  44. {
  45. var tokens = _context.Tokenize("", false);
  46. Assert.Equal(Array.Empty<int>(), tokens);
  47. }
  48. }
  49. }