input.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package input
  2. // Input represents one token in the input stream
  3. type Input struct {
  4. // Token is a single element of text.
  5. Token int32
  6. // Multimodal is opaque data representing a non-text
  7. // element such as an image (or part of one if the image
  8. // can be processed in pieces). It may be either together
  9. // with Token or on its own.
  10. Multimodal any
  11. // MultimodalHash is a unique representation of the data
  12. // stored in Multimodal, used for caching and comparing
  13. // equality.
  14. MultimodalHash uint64
  15. // SameBatch forces the following number of tokens to be processed
  16. // in a single batch, breaking and extending batches as needed.
  17. // Useful for things like images that must be processed in one
  18. // shot.
  19. SameBatch int
  20. }
  21. // MultimodalIndex is a multimodal element (such as an image)
  22. // together with an index into the slice of Inputs with the
  23. // corresponding token. Note that the index is not the same
  24. // as the position - to find that use the index with the
  25. // Positions slice.
  26. type MultimodalIndex struct {
  27. Index int
  28. Multimodal any
  29. }
  30. // Batch contains the inputs for a model forward pass
  31. type Batch struct {
  32. // Inputs is the input tokens, including placeholders for multimodal inputs.
  33. Inputs []int32
  34. // Multimodal is a set of multimodal embeddings previously created by
  35. // EncodeMultimodal, along with an index into Inputs. Unused for text-only
  36. // models or for batches without multimodal elements.
  37. Multimodal []MultimodalIndex
  38. // Positions is the position for each Input, relative to its sequence. Equal
  39. // in length to Inputs.
  40. Positions []int32
  41. // Sequences is the sequence for each Input. Equal in length to Inputs.
  42. Sequences []int
  43. // Outputs are the set of indicies into Inputs for which output data should
  44. // be returned.
  45. Outputs []int32
  46. }