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.

LLamaBeamsState.cs 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace LLama.Native;
  4. /// <summary>
  5. /// Passed to beam_search_callback function.
  6. /// Whenever 0 &lt; common_prefix_length, this number of tokens should be copied from any of the beams
  7. /// (e.g. beams[0]) as they will be removed (shifted) from all beams in all subsequent callbacks.
  8. /// </summary>
  9. [StructLayout(LayoutKind.Sequential)]
  10. public readonly struct LLamaBeamsState
  11. {
  12. /// <summary>
  13. /// The state of each individual beam
  14. /// </summary>
  15. private readonly unsafe LLamaBeamView* beam_views;
  16. /// <summary>
  17. /// Number of elements in beam_views
  18. /// </summary>
  19. private readonly nint n_beams;
  20. /// <summary>
  21. /// Current max length of prefix tokens shared by all beams.
  22. /// </summary>
  23. public readonly ulong CommonPrefixLength;
  24. /// <summary>
  25. /// True iff this is the last callback invocation.
  26. /// </summary>
  27. public readonly bool LastCall;
  28. /// <summary>
  29. /// The current state of each beam
  30. /// </summary>
  31. public Span<LLamaBeamView> Beams
  32. {
  33. get
  34. {
  35. unsafe
  36. {
  37. if (n_beams > int.MaxValue)
  38. throw new InvalidOperationException("More than 2147483647 beams is not supported");
  39. return new Span<LLamaBeamView>(beam_views, (int)n_beams);
  40. }
  41. }
  42. }
  43. }