MCPcopy Create free account
hub / github.com/EmbodiedGPT/EmbodiedGPT_Pytorch / forward

Method forward

robohusky/model/modeling_husky.py:474–547  ·  view source on GitHub ↗

r""" Args: inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`): Embedded representation of the inputs. Should be float, not int tokens. attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *

(
            self,
            inputs_embeds,
            attention_mask: Optional[torch.Tensor] = None,
            output_attentions: Optional[bool] = None,
            output_hidden_states: Optional[bool] = None,
            return_dict: Optional[bool] = None,
    )

Source from the content-addressed store, hash-verified

472 self.gradient_checkpointing = False
473
474 def forward(
475 self,
476 inputs_embeds,
477 attention_mask: Optional[torch.Tensor] = None,
478 output_attentions: Optional[bool] = None,
479 output_hidden_states: Optional[bool] = None,
480 return_dict: Optional[bool] = None,
481 ) -> Union[Tuple, BaseModelOutput]:
482 r"""
483 Args:
484 inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
485 Embedded representation of the inputs. Should be float, not int tokens.
486 attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
487 Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
488
489 - 1 for tokens that are **not masked**,
490 - 0 for tokens that are **masked**.
491
492 [What are attention masks?](../glossary#attention-mask)
493 output_attentions (`bool`, *optional*):
494 Whether or not to return the attentions tensors of all attention layers. See `attentions` under
495 returned tensors for more detail.
496 output_hidden_states (`bool`, *optional*):
497 Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
498 for more detail.
499 return_dict (`bool`, *optional*):
500 Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
501 """
502 output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
503 output_hidden_states = (
504 output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
505 )
506 return_dict = return_dict if return_dict is not None else self.config.use_return_dict
507
508 encoder_states = () if output_hidden_states else None
509 all_attentions = () if output_attentions else None
510
511 hidden_states = inputs_embeds
512 for idx, encoder_layer in enumerate(self.layers):
513 if output_hidden_states:
514 encoder_states = encoder_states + (hidden_states,)
515 if self.gradient_checkpointing and self.training:
516
517 def create_custom_forward(module):
518 def custom_forward(*inputs):
519 return module(*inputs, output_attentions)
520
521 return custom_forward
522
523 layer_outputs = torch.utils.checkpoint.checkpoint(
524 create_custom_forward(encoder_layer),
525 hidden_states,
526 attention_mask,
527 )
528 else:
529 layer_outputs = encoder_layer(
530 hidden_states,
531 attention_mask,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected