def METHOD_NAME(dims: Sequence[Dim]):
    """Computes the number of input and output units for a weight shape.
    Args:
      dims: Integer shape tuple or TF tensor shape.
    Returns:
      A tuple of integer scalars (fan_in, fan_out).
    """
    dims = [dim.dimension for dim in dims]
    if len(dims) < 1:  # Just to avoid errors for constants.
        fan_in = fan_out = 1
    elif len(dims) == 1:
        fan_in = fan_out = dims[0]
    elif len(dims) == 2:
        fan_in = dims[0]
        fan_out = dims[1]
    else:
        # Assuming convolution kernels (2D, 3D, or more).
        # kernel shape: (..., input_depth, depth)
        receptive_field_size = 1
        for dim in dims[:-2]:
            receptive_field_size *= dim
        fan_in = dims[-2] * receptive_field_size
        fan_out = dims[-1] * receptive_field_size
    return fan_in, fan_out