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.

IModelParamsExtensions.cs 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.IO;
  2. using System;
  3. using System.Buffers;
  4. using LLama.Abstractions;
  5. using LLama.Native;
  6. namespace LLama.Extensions
  7. {
  8. /// <summary>
  9. /// Extention methods to the IModelParams interface
  10. /// </summary>
  11. public static class IModelParamsExtensions
  12. {
  13. /// <summary>
  14. /// Convert the given `IModelParams` into a `LLamaModelParams`
  15. /// </summary>
  16. /// <param name="params"></param>
  17. /// <param name="result"></param>
  18. /// <returns></returns>
  19. /// <exception cref="FileNotFoundException"></exception>
  20. /// <exception cref="ArgumentException"></exception>
  21. public static MemoryHandle ToLlamaModelParams(this IModelParams @params, out LLamaModelParams result)
  22. {
  23. if (@params.TensorSplits != null && @params.TensorSplits.Length != 1)
  24. throw new ArgumentException("Currently multi-gpu support is not supported by both llama.cpp and LLamaSharp.");
  25. result = NativeApi.llama_model_default_params();
  26. result.main_gpu = @params.MainGpu;
  27. result.n_gpu_layers = @params.GpuLayerCount;
  28. result.use_mlock = @params.UseMemoryLock;
  29. result.use_mmap = @params.UseMemorymap;
  30. result.vocab_only = @params.VocabOnly;
  31. var pin = @params.TensorSplits.AsMemory().Pin();
  32. unsafe
  33. {
  34. result.tensor_split = (float*)pin.Pointer;
  35. }
  36. return pin;
  37. }
  38. }
  39. }