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.
|
- using LLama.Common;
-
- namespace LLama.Unittest;
-
- public class MemoryDisposalTests
- {
- [Fact]
- public void ModelDisposal()
- {
- var @params = new ModelParams(Constants.ModelPath)
- {
- ContextSize = 2048
- };
- var model = LLamaWeights.LoadFromFile(@params);
-
- Assert.False(model.NativeHandle.IsClosed);
- model.Dispose();
- Assert.True(model.NativeHandle.IsClosed);
- }
-
- [Fact]
- public void ContextDisposal()
- {
- var @params = new ModelParams(Constants.ModelPath)
- {
- ContextSize = 2048
- };
- var model = LLamaWeights.LoadFromFile(@params);
-
- var ctx = model.CreateContext(@params);
-
- // Disposing the model handle does **not** free the memory, because there's stilla context
- Assert.False(model.NativeHandle.IsClosed);
- model.Dispose();
- Assert.False(model.NativeHandle.IsClosed);
-
- // Disposing the context frees context and model weights
- ctx.Dispose();
- Assert.True(model.NativeHandle.IsClosed);
- Assert.True(ctx.NativeHandle.IsClosed);
- }
- }
|