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.

TailFreeSampling.cs 906 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using LLama.Native;
  3. namespace LLama.Sampling.Tokens;
  4. /// <summary>
  5. /// Tail Free Sampling described in https://www.trentonbricken.com/Tail-Free-Sampling/.
  6. /// </summary>
  7. public sealed class TailFreeSampling
  8. : ITokenDataProcessor
  9. {
  10. /// <summary>
  11. /// Z value for tail free sampling
  12. /// </summary>
  13. public float Z { 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.TailFree(ctx, Z, 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. }