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

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