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 858 B

1234567891011121314151617181920212223242526272829303132
  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 ReadOnlySpan<float> ProcessLogits(SafeLLamaContextHandle ctx, ReadOnlySpan<float> logits, ReadOnlySpan<LLamaToken> lastTokens)
  12. {
  13. return logits;
  14. }
  15. /// <inheritdoc />
  16. protected override LLamaToken ProcessTokenDataArray(SafeLLamaContextHandle ctx, LLamaTokenDataArray candidates, ReadOnlySpan<LLamaToken> lastTokens)
  17. {
  18. return candidates.SampleTokenGreedy(ctx);
  19. }
  20. /// <inheritdoc />
  21. public override ISamplingPipeline Clone()
  22. {
  23. return new GreedySamplingPipeline
  24. {
  25. Grammar = Grammar?.Clone()
  26. };
  27. }
  28. }