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.

GreedySamplingPipeline.cs 812 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using LLama.Native;
  3. namespace LLama.Sampling;
  4. /// <summary>
  5. /// A sampling pipeline which always selects the most likely token
  6. /// </summary>
  7. public class GreedySamplingPipeline
  8. : BaseSamplingPipeline
  9. {
  10. /// <inheritdoc />
  11. protected override void ProcessLogits(SafeLLamaContextHandle ctx, Span<float> logits, ReadOnlySpan<LLamaToken> lastTokens)
  12. {
  13. }
  14. /// <inheritdoc />
  15. protected override LLamaToken ProcessTokenDataArray(SafeLLamaContextHandle ctx, LLamaTokenDataArray candidates, ReadOnlySpan<LLamaToken> lastTokens)
  16. {
  17. return candidates.SampleTokenGreedy(ctx);
  18. }
  19. /// <inheritdoc />
  20. public override ISamplingPipeline Clone()
  21. {
  22. return new GreedySamplingPipeline
  23. {
  24. Grammar = Grammar?.Clone()
  25. };
  26. }
  27. }