paddlenlp/transformers/distill_utils.py
def tinybert_forward(self, input_ids, token_type_ids=None, attention_mask=None):
    """
    Replaces `forward` function while using multi gpus to train.
    """
    assert hasattr(self, self.base_model_prefix), \
        "Student class should inherit from %s" % (self.base_model_class)
    model = getattr(self, self.base_model_prefix)
    encoder = model.encoder

    sequence_output, pooled_output = model(input_ids, token_type_ids,
                                           attention_mask)
    for i in range(len(encoder.hidden_states)):
        # While using tinybert-4l-312d, tinybert-6l-768d, tinybert-4l-312d-zh,
        # tinybert-6l-768d-zh
        # While using tinybert-4l-312d-v2, tinybert-6l-768d-v2
        # encoder.hidden_states[i] = self.tinybert.fit_dense(encoder.hidden_states[i])
        encoder.hidden_states[i] = self.tinybert.fit_denses[i](
            encoder.hidden_states[i])

    return encoder.attentions, encoder.hidden_states

    Replaces `forward` function while using multi gpus to train.
    
Replaces `forward` function while using multi gpus to train.
Replaces ` forward ` function while using multi gpus to train .
def tinybert_forward(self, input_ids, token_type_ids=None, attention_mask=None):
    assert hasattr(self, self.base_model_prefix), \
        "Student class should inherit from %s" % (self.base_model_class)
    model = getattr(self, self.base_model_prefix)
    encoder = model.encoder
    sequence_output, pooled_output = model(input_ids, token_type_ids,
                                           attention_mask)
    for i in range(len(encoder.hidden_states)):
        encoder.hidden_states[i] = self.tinybert.fit_denses[i](
            encoder.hidden_states[i])
    return encoder.attentions, encoder.hidden_states
def tinybert_forward ( self , input_ids , token_type_ids = None , attention_mask = None ) : assert hasattr ( self , self . base_model_prefix ) , "Student class should inherit from %s" % ( self . base_model_class ) model = getattr ( self , self . base_model_prefix ) encoder = model . encoder sequence_output , pooled_output = model ( input_ids , token_type_ids , attention_mask ) for i in range ( len ( encoder . hidden_states ) ) : encoder . hidden_states [ i ] = self . tinybert . fit_denses [ i ] ( encoder . hidden_states [ i ] ) return encoder . attentions , encoder . hidden_states
Replaces `forward` function while using multi gpus to train.
Replaces ` forward ` function while using multi gpus to train .
"""
    Replaces `forward` function while using multi gpus to train.
    """ # While using tinybert-4l-312d, tinybert-6l-768d, tinybert-4l-312d-zh, # tinybert-6l-768d-zh # While using tinybert-4l-312d-v2, tinybert-6l-768d-v2 # encoder.hidden_states[i] = self.tinybert.fit_dense(encoder.hidden_states[i])
self
input_ids
token_type_ids
attention_mask