Holds beam search state data.
| 174 | |
| 175 | @flax.struct.dataclass |
| 176 | class BeamState: |
| 177 | """Holds beam search state data.""" |
| 178 | |
| 179 | # The position of the decoding loop in the length dimension. |
| 180 | cur_index: jax.Array # scalar int32: current decoded length index |
| 181 | # The active sequence log probabilities and finished sequence scores. |
| 182 | live_logprobs: jax.Array # float32: [batch_size, beam_size] |
| 183 | finished_scores: jax.Array # float32: [batch_size, beam_size] |
| 184 | # The current active-beam-searching and finished sequences. |
| 185 | live_seqs: jax.Array # int32: [batch_size, beam_size, max_decode_len] |
| 186 | finished_seqs: jax.Array # int32: [batch_size, beam_size, |
| 187 | # max_decode_len] |
| 188 | # Records which of the 'finished_seqs' is occupied and not a filler slot. |
| 189 | finished_flags: jax.Array # bool: [batch_size, beam_size] |
| 190 | # The current state of the autoregressive decoding caches. |
| 191 | cache: Any # Any pytree of arrays, e.g. flax attention Cache object |
| 192 | |
| 193 | |
| 194 | def beam_init(seed_token, batch_size, beam_size, max_decode_len, cache): |
no outgoing calls
no test coverage detected