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.

LLamaBeamView.cs 1.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace LLama.Native;
  4. /// <summary>
  5. /// Information about a single beam in a beam search
  6. /// </summary>
  7. [StructLayout(LayoutKind.Sequential)]
  8. public struct LLamaBeamView
  9. {
  10. private unsafe LLamaToken* tokens;
  11. private nint n_tokens;
  12. /// <summary>
  13. /// Cumulative beam probability (renormalized relative to all beams)
  14. /// </summary>
  15. public float CumulativeProbability;
  16. /// <summary>
  17. /// Callback should set this to true when a beam is at end-of-beam.
  18. /// </summary>
  19. public bool EndOfBeam;
  20. /// <summary>
  21. /// Tokens in this beam
  22. /// </summary>
  23. public readonly Span<LLamaToken> Tokens
  24. {
  25. get
  26. {
  27. unsafe
  28. {
  29. if (n_tokens > int.MaxValue)
  30. throw new InvalidOperationException("More than 2147483647 tokens is not supported");
  31. return new Span<LLamaToken>(tokens, (int)n_tokens);
  32. }
  33. }
  34. }
  35. }