def _fused_bias_act_ref(x, b, axis, act, alpha, gain, clamp):
    """Slow reference implementation of `fused_bias_act()` using standard TensorFlow ops."""

    # Validate arguments.
    x = tf.convert_to_tensor(x)
    b = tf.convert_to_tensor(b) if b is not None else tf.constant([], dtype=x.dtype)
    act_spec = activation_funcs[act]
    assert b.shape.rank == 1 and (b.shape[0] == 0 or b.shape[0] == x.shape[axis])
    assert b.shape[0] == 0 or 0 <= axis < x.shape.rank
    if alpha is None:
        alpha = act_spec.def_alpha
    if gain is None:
        gain = act_spec.def_gain

    # Add bias.
    if b.shape[0] != 0:
        x += tf.reshape(b, [-1 if i == axis else 1 for i in range(x.shape.rank)])

    # Evaluate activation function.
    x = act_spec.func(x, alpha=alpha)

    # Scale by gain.
    if gain != 1:
        x *= gain

    # Clamp.
    if clamp is not None:
        clamp = np.asarray(clamp, dtype=x.dtype.name)
        assert clamp.shape == () and clamp >= 0
        x = tf.clip_by_value(x, -clamp, clamp)
    return x
Slow reference implementation of `fused_bias_act()` using standard TensorFlow ops.
converters/stylegan2ada_tf_official/dnnlib/tflib/ops/fused_bias_act.py