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.1 kB

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