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.

ModelsParamsTests.cs 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using LLama.Common;
  2. using System.Text.Json;
  3. namespace LLama.Unittest
  4. {
  5. public class ModelsParamsTests
  6. {
  7. [Fact]
  8. public void SerializeRoundTripSystemTextJson()
  9. {
  10. var options = new JsonSerializerOptions();
  11. options.Converters.Add(new EncodingConverter());
  12. var expected = new ModelParams("abc/123")
  13. {
  14. BatchSize = 17,
  15. ContextSize = 42,
  16. Seed = 42,
  17. GpuLayerCount = 111,
  18. TensorSplits = { [0] = 3 }
  19. };
  20. var json = JsonSerializer.Serialize(expected, options);
  21. var actual = JsonSerializer.Deserialize<ModelParams>(json, options)!;
  22. // Cannot compare splits with default equality, check they are sequence equal and then set to null
  23. Assert.Equal((IEnumerable<float>)expected.TensorSplits, expected.TensorSplits);
  24. actual.TensorSplits = null!;
  25. expected.TensorSplits = null!;
  26. Assert.Equal(expected, actual);
  27. }
  28. //[Fact]
  29. //public void SerializeRoundTripNewtonsoft()
  30. //{
  31. // var expected = new ModelParams("abc/123")
  32. // {
  33. // BatchSize = 17,
  34. // ContextSize = 42,
  35. // Seed = 42,
  36. // GpuLayerCount = 111,
  37. // LoraAdapters =
  38. // {
  39. // new("abc", 1),
  40. // new("def", 0)
  41. // },
  42. // TensorSplits = { [0] = 3 }
  43. // };
  44. // var settings = new Newtonsoft.Json.JsonSerializerSettings();
  45. // var json = Newtonsoft.Json.JsonConvert.SerializeObject(expected, settings);
  46. // var actual = Newtonsoft.Json.JsonConvert.DeserializeObject<ModelParams>(json, settings)!;
  47. // // Cannot compare splits with default equality, check they are sequence equal and then set to null
  48. // Assert.Equal((IEnumerable<float>)expected.TensorSplits, expected.TensorSplits);
  49. // actual.TensorSplits = null!;
  50. // expected.TensorSplits = null!;
  51. // Assert.Equal(expected, actual);
  52. //}
  53. }
  54. }