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.

BasicTest.cs 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Text;
  2. using LLama.Common;
  3. namespace LLama.Unittest
  4. {
  5. public sealed class BasicTest
  6. : IDisposable
  7. {
  8. private readonly ModelParams _params;
  9. private readonly LLamaWeights _model;
  10. public BasicTest()
  11. {
  12. _params = new ModelParams(Constants.ModelPath)
  13. {
  14. ContextSize = 2048
  15. };
  16. _model = LLamaWeights.LoadFromFile(_params);
  17. }
  18. public void Dispose()
  19. {
  20. _model.Dispose();
  21. }
  22. [Fact]
  23. public void BasicModelProperties()
  24. {
  25. Assert.Equal(32000, _model.VocabCount);
  26. Assert.Equal(2048, _model.ContextSize);
  27. Assert.Equal(4096, _model.EmbeddingSize);
  28. Assert.Equal(Encoding.UTF8, _model.Encoding);
  29. }
  30. [Fact]
  31. public void CloneContext()
  32. {
  33. var original = _model.CreateContext(_params);
  34. // Evaluate something (doesn't matter what, as long as it begins with token 1)
  35. original.Eval(new[] { 1, 42, 321 }, 0);
  36. // Clone current state
  37. var clone = original.Clone();
  38. // Now evaluate something more
  39. var reply1a = original.Eval(new[] { 4, 5, 6 }, 3);
  40. var reply2a = original.Eval(new[] { 7, 8, 9 }, 6);
  41. // Assert that the context replied differently each time
  42. Assert.NotEqual(reply1a, reply2a);
  43. // Give the same prompts to the cloned state
  44. var reply1b = clone.Eval(new[] { 4, 5, 6 }, 3);
  45. var reply2b = clone.Eval(new[] { 7, 8, 9 }, 6);
  46. // Assert that the cloned context replied in the same way as originally
  47. Assert.Equal(reply1a, reply1b);
  48. Assert.Equal(reply2a, reply2b);
  49. }
  50. }
  51. }