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.7 kB

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