MCPcopy Create free account
hub / github.com/modelscope/modelscope / forward

Method forward

modelscope/models/nlp/ponet/backbone.py:484–580  ·  view source on GitHub ↗
(
        self,
        hidden_states,
        segment_index,
        token_type_mask,
        attention_mask=None,
        head_mask=None,
        encoder_hidden_states=None,
        encoder_attention_mask=None,
        past_key_values=None,
        use_cache=None,
        output_attentions=False,
        output_hidden_states=False,
        return_dict=True,
    )

Source from the content-addressed store, hash-verified

482 [PoNetLayer(config) for _ in range(config.num_hidden_layers)])
483
484 def forward(
485 self,
486 hidden_states,
487 segment_index,
488 token_type_mask,
489 attention_mask=None,
490 head_mask=None,
491 encoder_hidden_states=None,
492 encoder_attention_mask=None,
493 past_key_values=None,
494 use_cache=None,
495 output_attentions=False,
496 output_hidden_states=False,
497 return_dict=True,
498 ):
499 all_hidden_states = () if output_hidden_states else None
500 all_self_attentions = () if output_attentions else None
501 all_cross_attentions = (
502 ) if output_attentions and self.config.add_cross_attention else None
503
504 next_decoder_cache = () if use_cache else None
505 for i, layer_module in enumerate(self.layer):
506 if output_hidden_states:
507 all_hidden_states = all_hidden_states + (hidden_states, )
508
509 layer_head_mask = head_mask[i] if head_mask is not None else None
510 past_key_value = past_key_values[
511 i] if past_key_values is not None else None
512
513 if getattr(self.config, 'gradient_checkpointing',
514 False) and self.training:
515
516 if use_cache:
517 logger.warning(
518 '`use_cache=True` is incompatible with `config.gradient_checkpointing=True`. Setting '
519 '`use_cache=False`...')
520 use_cache = False
521
522 def create_custom_forward(module):
523
524 def custom_forward(*inputs):
525 return module(*inputs, past_key_value,
526 output_attentions)
527
528 return custom_forward
529
530 layer_outputs = torch.utils.checkpoint.checkpoint(
531 create_custom_forward(layer_module),
532 hidden_states,
533 segment_index,
534 token_type_mask,
535 attention_mask,
536 layer_head_mask,
537 encoder_hidden_states,
538 encoder_attention_mask,
539 )
540 else:
541 layer_outputs = layer_module(

Callers

nothing calls this directly

Calls 2

create_custom_forwardFunction · 0.50

Tested by

no test coverage detected