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.

MinPSampling.cs 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using LLama.Native;
  3. namespace LLama.Sampling.Tokens;
  4. /// <summary>
  5. /// Minimum P sampling as described in https://github.com/ggerganov/llama.cpp/pull/3841
  6. /// </summary>
  7. public sealed class MinPSampling
  8. : ITokenDataProcessor
  9. {
  10. /// <summary>
  11. /// All tokens with probability greater than this will be kept
  12. /// </summary>
  13. public float P { get; set; }
  14. /// <summary>
  15. /// Minimum number of tokens to keep
  16. /// </summary>
  17. public ulong MinKeep { get; set; } = 1;
  18. /// <inheritdoc />
  19. public void ProcessTokens(SafeLLamaContextHandle ctx, LLamaTokenDataArray tokens, ReadOnlySpan<int> lastTokens)
  20. {
  21. tokens.MinP(ctx, P, MinKeep);
  22. }
  23. /// <inheritdoc />
  24. public void AcceptToken(SafeLLamaContextHandle ctx, int token)
  25. {
  26. }
  27. /// <inheritdoc />
  28. public void Reset()
  29. {
  30. }
  31. /// <inheritdoc />
  32. public void Dispose()
  33. {
  34. }
  35. }