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

April 2024 Binary Update (#662) * Updated binaries, using [this build](https://github.com/SciSharp/LLamaSharp/actions/runs/8654672719/job/23733195669) for llama.cpp commit `f7001ccc5aa359fcf41bba19d1c99c3d25c9bcc7`. - Added all new functions. - Moved some functions (e.g. `SafeLlamaModelHandle` specific functions) into `SafeLlamaModelHandle.cs` - Exposed tokens on `SafeLlamaModelHandle` and `LLamaWeights` through a `Tokens` property. As new special tokens are added in the future they can be added here. - Changed all token properties to return nullable tokens, to handle some models not having some tokens. - Fixed `DefaultSamplingPipeline` to handle no newline token in some models. * Moved native methods to more specific locations. - Context specific things have been moved into `SafeLLamaContextHandle.cs` and made private - they're exposed through C# properties and methods already. - Checking that GPU layer count is zero if GPU offload is not supported. - Moved methods for creating default structs (`llama_model_quantize_default_params` and `llama_context_default_params`) into relevant structs. * Removed exception if `GpuLayerCount > 0` when GPU is not supported. * - Added low level wrapper methods for new per-sequence state load/save in `SafeLLamaContextHandle` - Added high level wrapper methods (save/load with `State` object or memory mapped file) in `LLamaContext` - Moved native methods for per-sequence state load/save into `SafeLLamaContextHandle` * Added update and defrag methods for KV cache in `SafeLLamaContextHandle` * Updated submodule to `f7001ccc5aa359fcf41bba19d1c99c3d25c9bcc7` * Passing the sequence ID when saving a single sequence state
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.GenerativeModelPath)
  17. {
  18. ContextSize = 2048,
  19. GpuLayerCount = Constants.CIGpuLayerCount
  20. };
  21. _model = LLamaWeights.LoadFromFile(_params);
  22. }
  23. public void Dispose()
  24. {
  25. _model.Dispose();
  26. }
  27. [Fact]
  28. public void BasicModelProperties()
  29. {
  30. Assert.Equal(32000, _model.VocabCount);
  31. Assert.Equal(4096, _model.ContextSize);
  32. Assert.Equal(4096, _model.EmbeddingSize);
  33. }
  34. [Fact]
  35. public void AdvancedModelProperties()
  36. {
  37. // These are the keys in the llama 7B test model. This will need changing if
  38. // tests are switched to use a new model!
  39. var expected = new Dictionary<string, string>
  40. {
  41. { "general.name", "LLaMA v2" },
  42. { "general.architecture", "llama" },
  43. { "general.quantization_version", "2" },
  44. { "general.file_type", "11" },
  45. { "llama.context_length", "4096" },
  46. { "llama.rope.dimension_count", "128" },
  47. { "llama.embedding_length", "4096" },
  48. { "llama.block_count", "32" },
  49. { "llama.feed_forward_length", "11008" },
  50. { "llama.attention.head_count", "32" },
  51. { "llama.attention.head_count_kv", "32" },
  52. { "llama.attention.layer_norm_rms_epsilon", "0.000001" },
  53. { "tokenizer.ggml.eos_token_id", "2" },
  54. { "tokenizer.ggml.model", "llama" },
  55. { "tokenizer.ggml.bos_token_id", "1" },
  56. { "tokenizer.ggml.unknown_token_id", "0" },
  57. };
  58. // Print all keys
  59. foreach (var (key, value) in _model.Metadata)
  60. _testOutputHelper.WriteLine($"{key} = {value}");
  61. // Check the count is equal
  62. Assert.Equal(expected.Count, _model.Metadata.Count);
  63. // Check every key
  64. foreach (var (key, value) in _model.Metadata)
  65. Assert.Equal(expected[key], value);
  66. }
  67. }
  68. }