code: def gen_bias(encoder_inputs, decoder_inputs, step):
      decoder_bsz, decoder_seqlen = decoder_inputs.shape[:2]
      encoder_bsz, encoder_seqlen = encoder_inputs.shape[:2]
      attn_bias = paddle.reshape(
          paddle.arange(0, decoder_seqlen, 1, dtype="float32") + 1,
          [1, -1, 1],
      )
      decoder_bias = paddle.cast(
          (
              paddle.matmul(
                  attn_bias, 1.0 / attn_bias, transpose_y=True
              )
              >= 1.0
          ),
          "float32",
      )  # [1, decoderlen, decoderlen]
      encoder_bias = paddle.unsqueeze(
          paddle.cast(paddle.ones_like(encoder_inputs), "float32"), [1]
      )  # [bsz, 1, encoderlen]
      encoder_bias = paddle.expand(
          encoder_bias, [encoder_bsz, decoder_seqlen, encoder_seqlen]
      )  # [bsz,decoderlen, encoderlen]
      decoder_bias = paddle.expand(
          decoder_bias, [decoder_bsz, decoder_seqlen, decoder_seqlen]
      )  # [bsz, decoderlen, decoderlen]
      if step > 0:
          bias = paddle.concat(
              [
                  encoder_bias,
                  paddle.ones(
                      [decoder_bsz, decoder_seqlen, step], "float32"
                  ),
                  decoder_bias,
              ],
              -1,
          )
      else:
          bias = paddle.concat([encoder_bias, decoder_bias], -1)
      return bias
  
imports: from __future__ import division
  from __future__ import absolute_import
  from __future__ import print_function
  from __future__ import unicode_literals
  import sys
  import re
  import argparse
  import logging
  import json
  import numpy
  from collections import namedtuple
  import paddle
  import paddle.nn
  import numpy
  from paddlenlp.utils.log import logger
label_desc: Use image node_id 1 for calling a global function with example usage: gen_bias(encoder_inputs, decoder_inputs, step) and returns: bias