Computes decoder hidden states from input ids and cross attention hidden states. Args: input_batch: A dict containing: * input_ids: An int Tensor of shape [batch_size, target_len]. Values should be in the range [0, vocab_size).
(
self,
input_batch: Nested[Tensor],
*,
cross_attention_data: Optional[Tensor] = None,
cross_attention_logit_biases: Optional[Tensor] = None,
**kwargs,
)
| 642 | return logits |
| 643 | |
| 644 | def forward( |
| 645 | self, |
| 646 | input_batch: Nested[Tensor], |
| 647 | *, |
| 648 | cross_attention_data: Optional[Tensor] = None, |
| 649 | cross_attention_logit_biases: Optional[Tensor] = None, |
| 650 | **kwargs, |
| 651 | ) -> dict[str, Tensor]: |
| 652 | """Computes decoder hidden states from input ids and cross attention hidden states. |
| 653 | |
| 654 | Args: |
| 655 | input_batch: A dict containing: |
| 656 | * input_ids: An int Tensor of shape [batch_size, target_len]. |
| 657 | Values should be in the range [0, vocab_size). |
| 658 | * input_segment_ids: An optional Tensor of same shape as `input_ids` with values in |
| 659 | [0, num_segments]. Tokens are only allowed to attend to other tokens within the |
| 660 | same segment. input_segment_ids == 0 represents paddings. If None, inferred from |
| 661 | input_ids != pad_token_id. |
| 662 | * token_type_ids: An optional int Tensor of shape [batch_size, target_len]. |
| 663 | Values should be in the range [0, type_vocab_size). |
| 664 | * positions: An optional int Tensor of shape [batch_size, target_len]. |
| 665 | If None, assumed to be jnp.arange(target_len) for each sequence. |
| 666 | cross_attention_data: A float Tensor of shape [batch_size, source_len, hidden_dim]. |
| 667 | cross_attention_logit_biases: A Tensor of shape [batch_size, target_len, source_len]. |
| 668 | A -inf represents a disconnected position pair. |
| 669 | |
| 670 | Returns: |
| 671 | A dict containing: |
| 672 | hidden_states: A float Tensor of shape [batch_size, target_len, hidden_dim]. |
| 673 | """ |
| 674 | validate_contains_paths(input_batch, paths=["input_ids"]) |
| 675 | input_ids = input_batch["input_ids"] |
| 676 | input_segment_ids = input_batch.get("input_segment_ids", None) |
| 677 | positions = input_batch.get("positions", None) |
| 678 | |
| 679 | _, output = self._forward_for_mode( |
| 680 | mode=ForwardMode.FORWARD, |
| 681 | input_batch=input_batch, |
| 682 | # [batch_size, num_heads, seq_len, seq_len]. |
| 683 | self_attention_logit_biases=self.compute_attention_logit_biases( |
| 684 | input_ids, segment_ids=input_segment_ids, positions=positions |
| 685 | ), |
| 686 | cross_attention_data=cross_attention_data, |
| 687 | cross_attention_logit_biases=cross_attention_logit_biases, |
| 688 | cached_states=None, |
| 689 | **kwargs, |
| 690 | ) |
| 691 | return output |
| 692 | |
| 693 | @nowrap |
| 694 | def init_states( |
nothing calls this directly
no test coverage detected