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.

StatelessExecutorTest.cs 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using LLama.Common;
  2. using System.Text;
  3. namespace LLama.Unittest
  4. {
  5. public class StatelessExecutorTest
  6. : IDisposable
  7. {
  8. private readonly LLamaWeights _weights;
  9. private readonly ModelParams _params;
  10. public StatelessExecutorTest()
  11. {
  12. _params = new ModelParams("Models/llama-2-7b-chat.ggmlv3.q3_K_S.bin")
  13. {
  14. ContextSize = 64,
  15. Seed = 1754
  16. };
  17. _weights = LLamaWeights.LoadFromFile(_params);
  18. }
  19. public void Dispose()
  20. {
  21. _weights.Dispose();
  22. }
  23. [Fact]
  24. public void Stateless()
  25. {
  26. var executor = new StatelessExecutor(_weights.CreateContext(_params, Encoding.UTF8));
  27. const string question = "Question. what is a cat?\nAnswer: ";
  28. const string expected = " a domestic or wild animal that is typically small to medium-sized, has fur, four legs, and sharp retractable claws.";
  29. var @params = new InferenceParams { MaxTokens = 32, AntiPrompts = new[] { "." } };
  30. var result1 = string.Join("", executor.Infer(question, @params));
  31. Assert.Equal(expected, result1);
  32. var result2 = string.Join("", executor.Infer(question, @params));
  33. Assert.Equal(expected, result2);
  34. Assert.Equal(result1, result2);
  35. }
  36. [Fact]
  37. public void OutOfContext()
  38. {
  39. var executor = new StatelessExecutor(_weights.CreateContext(_params, Encoding.UTF8));
  40. const string question = "Question. why is a cat the best pet?\nAnswer: ";
  41. var @params = new InferenceParams()
  42. {
  43. MaxTokens = 128,
  44. };
  45. var result1 = string.Join("", executor.Infer(question, @params));
  46. }
  47. }
  48. }