paddlenlp/ops/faster_transformer/transformer/encoder.py
def infer_transformer_encoder(
        input,
        q_weight,
        q_bias,
        k_weight,
        k_bias,
        v_weight,
        v_bias,
        attn_out_weight,
        attn_out_bias,
        attn_mask,
        norm1_weight,
        norm1_bias,
        norm2_weight,
        norm2_bias,
        ffn_inter_weight,
        ffn_inter_bias,
        ffn_out_weight,
        ffn_out_bias,
        #   sequence_id_offset,
        #   trt_seqlen_offset,
        #   amax_list,
        n_head,
        size_per_head,
        n_layer=12,
        use_gelu=True,
        remove_padding=False,
        int8_mode=0,
        layer_idx=0,
        allow_gemm_test=False,
        use_trt_kernel=False,
        normalize_before=False):
    """
    Fusion Encoder API intergrating Encoder inference in FasterTransformer. It
    accepts the weight and bias of TransformerEncoder and some other parameters
    for inference.
    """
    helper = LayerHelper('fusion_encoder', **locals())
    inputs = {
        'Input': input,
        'SelfQueryWeight': q_weight,
        'SelfQueryBias': q_bias,
        'SelfKeyWeight': k_weight,
        'SelfKeyBias': k_bias,
        'SelfValueWeight': v_weight,
        'SelfValueBias': v_bias,
        'SelfAttnOutputWeight': attn_out_weight,
        'SelfAttnOutputBias': attn_out_bias,
        "SelfAttnMask": attn_mask,
        'SelfAttnOutputLayernormWeight': norm1_weight,
        'SelfAttnOutputLayernormBias': norm1_bias,
        'OutputLayernormWeight': norm2_weight,
        'OutputLayernormBias': norm2_bias,
        'FFNInterWeight': ffn_inter_weight,
        'FFNInterBias': ffn_inter_bias,
        'FFNOutputWeight': ffn_out_weight,
        'FFNOutputBias': ffn_out_bias,
        # "SequenceIdOffset": sequence_id_offset,
        # "TRTSeqLenOffset": trt_seqlen_offset,
        # 'AmaxList': amax_list
    }
    attrs = {
        'head_num': n_head,
        'size_per_head': size_per_head,
        'use_gelu': use_gelu,
        "remove_padding": remove_padding,
        'int8_mode': int8_mode,
        'num_layer': n_layer,
        'layer_idx': layer_idx,
        'allow_gemm_test': allow_gemm_test,
        'use_trt_kernel': use_trt_kernel,
        'normalize_before': normalize_before
    }
    encoder_out = helper.create_variable(dtype=input.dtype)
    outputs = {"EncoderOut": encoder_out}

    helper.append_op(
        type='fusion_encoder', inputs=inputs, outputs=outputs, attrs=attrs)
    return encoder_out

    Fusion Encoder API intergrating Encoder inference in FasterTransformer. It
    accepts the weight and bias of TransformerEncoder and some other parameters
    for inference.
    
Fusion Encoder API intergrating Encoder inference in FasterTransformer. It
accepts the weight and bias of TransformerEncoder and some other parameters
for inference.
Fusion Encoder API intergrating Encoder inference in FasterTransformer . It accepts the weight and bias of TransformerEncoder and some other parameters for inference .
def infer_transformer_encoder(
        input,
        q_weight,
        q_bias,
        k_weight,
        k_bias,
        v_weight,
        v_bias,
        attn_out_weight,
        attn_out_bias,
        attn_mask,
        norm1_weight,
        norm1_bias,
        norm2_weight,
        norm2_bias,
        ffn_inter_weight,
        ffn_inter_bias,
        ffn_out_weight,
        ffn_out_bias,
        n_head,
        size_per_head,
        n_layer=12,
        use_gelu=True,
        remove_padding=False,
        int8_mode=0,
        layer_idx=0,
        allow_gemm_test=False,
        use_trt_kernel=False,
        normalize_before=False):
    helper = LayerHelper('fusion_encoder', **locals())
    inputs = {
        'Input': input,
        'SelfQueryWeight': q_weight,
        'SelfQueryBias': q_bias,
        'SelfKeyWeight': k_weight,
        'SelfKeyBias': k_bias,
        'SelfValueWeight': v_weight,
        'SelfValueBias': v_bias,
        'SelfAttnOutputWeight': attn_out_weight,
        'SelfAttnOutputBias': attn_out_bias,
        "SelfAttnMask": attn_mask,
        'SelfAttnOutputLayernormWeight': norm1_weight,
        'SelfAttnOutputLayernormBias': norm1_bias,
        'OutputLayernormWeight': norm2_weight,
        'OutputLayernormBias': norm2_bias,
        'FFNInterWeight': ffn_inter_weight,
        'FFNInterBias': ffn_inter_bias,
        'FFNOutputWeight': ffn_out_weight,
        'FFNOutputBias': ffn_out_bias,
    }
    attrs = {
        'head_num': n_head,
        'size_per_head': size_per_head,
        'use_gelu': use_gelu,
        "remove_padding": remove_padding,
        'int8_mode': int8_mode,
        'num_layer': n_layer,
        'layer_idx': layer_idx,
        'allow_gemm_test': allow_gemm_test,
        'use_trt_kernel': use_trt_kernel,
        'normalize_before': normalize_before
    }
    encoder_out = helper.create_variable(dtype=input.dtype)
    outputs = {"EncoderOut": encoder_out}
    helper.append_op(
        type='fusion_encoder', inputs=inputs, outputs=outputs, attrs=attrs)
    return encoder_out
def infer_transformer_encoder ( input , q_weight , q_bias , k_weight , k_bias , v_weight , v_bias , attn_out_weight , attn_out_bias , attn_mask , norm1_weight , norm1_bias , norm2_weight , norm2_bias , ffn_inter_weight , ffn_inter_bias , ffn_out_weight , ffn_out_bias , n_head , size_per_head , n_layer = 12 , use_gelu = True , remove_padding = False , int8_mode = 0 , layer_idx = 0 , allow_gemm_test = False , use_trt_kernel = False , normalize_before = False ) : helper = LayerHelper ( 'fusion_encoder' , ** locals ( ) ) inputs = { 'Input' : input , 'SelfQueryWeight' : q_weight , 'SelfQueryBias' : q_bias , 'SelfKeyWeight' : k_weight , 'SelfKeyBias' : k_bias , 'SelfValueWeight' : v_weight , 'SelfValueBias' : v_bias , 'SelfAttnOutputWeight' : attn_out_weight , 'SelfAttnOutputBias' : attn_out_bias , "SelfAttnMask" : attn_mask , 'SelfAttnOutputLayernormWeight' : norm1_weight , 'SelfAttnOutputLayernormBias' : norm1_bias , 'OutputLayernormWeight' : norm2_weight , 'OutputLayernormBias' : norm2_bias , 'FFNInterWeight' : ffn_inter_weight , 'FFNInterBias' : ffn_inter_bias , 'FFNOutputWeight' : ffn_out_weight , 'FFNOutputBias' : ffn_out_bias , } attrs = { 'head_num' : n_head , 'size_per_head' : size_per_head , 'use_gelu' : use_gelu , "remove_padding" : remove_padding , 'int8_mode' : int8_mode , 'num_layer' : n_layer , 'layer_idx' : layer_idx , 'allow_gemm_test' : allow_gemm_test , 'use_trt_kernel' : use_trt_kernel , 'normalize_before' : normalize_before } encoder_out = helper . create_variable ( dtype = input . dtype ) outputs = { "EncoderOut" : encoder_out } helper . append_op ( type = 'fusion_encoder' , inputs = inputs , outputs = outputs , attrs = attrs ) return encoder_out
Fusion Encoder API intergrating Encoder inference in FasterTransformer.
Fusion Encoder API intergrating Encoder inference in FasterTransformer .
#   sequence_id_offset, #   trt_seqlen_offset, #   amax_list, """
    Fusion Encoder API intergrating Encoder inference in FasterTransformer. It
    accepts the weight and bias of TransformerEncoder and some other parameters
    for inference.
    """ # "SequenceIdOffset": sequence_id_offset, # "TRTSeqLenOffset": trt_seqlen_offset, # 'AmaxList': amax_list
input
q_weight
q_bias
k_weight
k_bias
v_weight
v_bias
attn_out_weight
attn_out_bias
attn_mask
norm1_weight
norm1_bias
norm2_weight
norm2_bias
ffn_inter_weight
ffn_inter_bias
ffn_out_weight
ffn_out_bias
n_head
size_per_head
n_layer
use_gelu
remove_padding
int8_mode
layer_idx
allow_gemm_test
use_trt_kernel
normalize_before