Skip to content

Commit

Permalink
Using a pin instead of a fixed block
Browse files Browse the repository at this point in the history
  • Loading branch information
martindevans committed Aug 7, 2023
1 parent 2c933c5 commit f1111a9
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions LLama/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,19 @@ public static SafeLLamaContextHandle InitLLamaContextFromModelParams(IModelParam
lparams.rope_freq_scale = @params.RopeFrequencyScale;
lparams.mul_mat_q = @params.MulMatQ;

using var pin = @params.TensorSplits.AsMemory().Pin();
unsafe
{
fixed (float* splits = @params.TensorSplits)
{
lparams.tensor_split = (nint)splits;
lparams.tensor_split = (nint)pin.Pointer;
}

var model = SafeLlamaModelHandle.LoadFromFile(@params.ModelPath, lparams);
var ctx = SafeLLamaContextHandle.Create(model, lparams);
var model = SafeLlamaModelHandle.LoadFromFile(@params.ModelPath, lparams);
var ctx = SafeLLamaContextHandle.Create(model, lparams);

if (!string.IsNullOrEmpty(@params.LoraAdapter))
model.ApplyLoraFromFile(@params.LoraAdapter, @params.LoraBase, @params.Threads);
if (!string.IsNullOrEmpty(@params.LoraAdapter))
model.ApplyLoraFromFile(@params.LoraAdapter, @params.LoraBase, @params.Threads);

return ctx;
}
}
return ctx;
}

public static IEnumerable<llama_token> Tokenize(SafeLLamaContextHandle ctx, string text, bool add_bos, Encoding encoding)
Expand Down

0 comments on commit f1111a9

Please sign in to comment.