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.

TemperatureSampling.cs 904 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using LLama.Native;
  3. namespace LLama.Sampling.Tokens;
  4. /// <summary>
  5. /// Sample with temperature.
  6. /// As temperature increases, the prediction becomes more diverse but also vulnerable to hallucinations -- generating tokens that are sensible but not factual
  7. /// </summary>
  8. public sealed class TemperatureSampling
  9. : ITokenDataProcessor
  10. {
  11. /// <summary>
  12. /// Temperature value to apply
  13. /// </summary>
  14. public float Temperature { get; set; } = 0.5f;
  15. /// <inheritdoc />
  16. public void ProcessTokens(SafeLLamaContextHandle ctx, LLamaTokenDataArray tokens, ReadOnlySpan<int> lastTokens)
  17. {
  18. tokens.Temperature(ctx, Temperature);
  19. }
  20. /// <inheritdoc />
  21. public void AcceptToken(SafeLLamaContextHandle ctx, int token)
  22. {
  23. }
  24. /// <inheritdoc />
  25. public void Reset()
  26. {
  27. }
  28. /// <inheritdoc />
  29. public void Dispose()
  30. {
  31. }
  32. }