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.

MemoryDisposalTests.cs 1.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using LLama.Common;
  2. namespace LLama.Unittest;
  3. public class MemoryDisposalTests
  4. {
  5. [Fact]
  6. public void ModelDisposal()
  7. {
  8. var @params = new ModelParams(Constants.ModelPath)
  9. {
  10. ContextSize = 2048
  11. };
  12. var model = LLamaWeights.LoadFromFile(@params);
  13. Assert.False(model.NativeHandle.IsClosed);
  14. model.Dispose();
  15. Assert.True(model.NativeHandle.IsClosed);
  16. }
  17. [Fact]
  18. public void ContextDisposal()
  19. {
  20. var @params = new ModelParams(Constants.ModelPath)
  21. {
  22. ContextSize = 2048
  23. };
  24. var model = LLamaWeights.LoadFromFile(@params);
  25. var ctx = model.CreateContext(@params);
  26. // Disposing the model handle does **not** free the memory, because there's stilla context
  27. Assert.False(model.NativeHandle.IsClosed);
  28. model.Dispose();
  29. Assert.False(model.NativeHandle.IsClosed);
  30. // Disposing the context frees context and model weights
  31. ctx.Dispose();
  32. Assert.True(model.NativeHandle.IsClosed);
  33. Assert.True(ctx.NativeHandle.IsClosed);
  34. }
  35. }