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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.Text;
  2. using LLama.Common;
  3. using LLama.Native;
  4. using Xunit.Abstractions;
  5. namespace LLama.Unittest
  6. {
  7. public sealed class BasicTest
  8. : IDisposable
  9. {
  10. private readonly ITestOutputHelper _testOutputHelper;
  11. private readonly ModelParams _params;
  12. private readonly LLamaWeights _model;
  13. public BasicTest(ITestOutputHelper testOutputHelper)
  14. {
  15. _testOutputHelper = testOutputHelper;
  16. _params = new ModelParams(Constants.ModelPath)
  17. {
  18. ContextSize = 2048
  19. };
  20. _model = LLamaWeights.LoadFromFile(_params);
  21. }
  22. public void Dispose()
  23. {
  24. _model.Dispose();
  25. }
  26. [Fact]
  27. public void BasicModelProperties()
  28. {
  29. Assert.Equal(32000, _model.VocabCount);
  30. Assert.Equal(4096, _model.ContextSize);
  31. Assert.Equal(4096, _model.EmbeddingSize);
  32. }
  33. [Fact]
  34. public void AdvancedModelProperties()
  35. {
  36. // These are the keys in the llama 7B test model. This will need changing if
  37. // tests are switched to use a new model!
  38. var expected = new Dictionary<string, string>
  39. {
  40. { "general.name", "LLaMA v2" },
  41. { "general.architecture", "llama" },
  42. { "general.quantization_version", "2" },
  43. { "general.file_type", "11" },
  44. { "llama.context_length", "4096" },
  45. { "llama.rope.dimension_count", "128" },
  46. { "llama.embedding_length", "4096" },
  47. { "llama.block_count", "32" },
  48. { "llama.feed_forward_length", "11008" },
  49. { "llama.attention.head_count", "32" },
  50. { "llama.attention.head_count_kv", "32" },
  51. { "llama.attention.layer_norm_rms_epsilon", "0.000001" },
  52. { "tokenizer.ggml.eos_token_id", "2" },
  53. { "tokenizer.ggml.model", "llama" },
  54. { "tokenizer.ggml.bos_token_id", "1" },
  55. { "tokenizer.ggml.unknown_token_id", "0" },
  56. };
  57. // Print all keys
  58. foreach (var (key, value) in _model.Metadata)
  59. _testOutputHelper.WriteLine($"{key} = {value}");
  60. // Check the count is equal
  61. Assert.Equal(expected.Count, _model.Metadata.Count);
  62. // Check every key
  63. foreach (var (key, value) in _model.Metadata)
  64. Assert.Equal(expected[key], value);
  65. }
  66. }
  67. }