def METHOD_NAME(x_float: torch.Tensor,
                    maxval: torch.Tensor,
                    mantissa_bits: torch.Tensor,
                    per_channel_axis: int = 0,
                    ) -> torch.Tensor:
    """
    FP8 quantizer that exploits the fact that FP quantization is just INT quantization with
    scales that depend on the input.
    """
    # For learning: ensure that the number of mantissa bits is rounded and clamped to
    # allowed values. NB: torch.round should be replaced by ste_round_func (not included
    # here yet)
    # TODO for learning we need this as well:
    # mantissa_bits = torch.clamp(torch.round(mantissa_bits), 1, 7)
    # Compute exponent bits from the (learned) number of exponent bits. NB: assumes FP8
    exponent_bits = 7 - mantissa_bits
    # Tensorized per-channel quantization: ensure that maxval has the same number of
    # dimensions as x, where the channel that is individually quantized has size C,
    # and all other channels have size 1. E.g. for a conv tensor with C output channels,
    # maxval will have shape [C, 1, 1, 1]. This allows broadcasting maxval over the
    # input tensor in steps below.
    if maxval.shape and maxval.shape[0] != 1 and len(maxval.shape) != len(x_float.shape):
        new_shape = [1] * len(x_float.shape)
        new_shape[per_channel_axis] = -1
        maxval = maxval.view(new_shape)
    # Math explanation of what happens here:
    # Bias is computed from maxval: $B=2^E - \log_2(M) + \log_2(2 - 2^{-M}) - 1$
    # This follows from maxval $M=(2 - 2^{-M}) \cdot 2^{2^E-1-B}$.
    bias = 2 ** exponent_bits - torch.log2(maxval) + torch.log2(2 - 2 ** (-mantissa_bits)) - 1
    # Ensure no values are greater than the maximum value represented by an 8 bit float system
    # with M mantissa and E exponent bits. torch.min/torch.max are used to allow gradients to
    # flow to maxval
    x_clipped = torch.min(torch.max(x_float, -maxval), maxval)
    # FP quantization scale is determined per-element, and is computed as
    # \log_2 s = \left\lfloor \log_2 |x_c| + B \right\rfloor - M - B
    # the addition of bias inside the floor and subtraction outside ensures that a
    # tensor scaling $\alpha \neq 1$ is correctly incorporated
    log_scales = torch.floor(torch.log2(torch.abs(x_clipped)) + bias).detach()
    # This ensures scales are never smaller than the subnormal scale
    log_scales = torch.clamp(log_scales, 1.)
    # Second step of computing scale $s$
    scales = 2. ** (log_scales - mantissa_bits - bias)
    # Using the per-element scale we can quantize the clipped input tensor to the FP grid
    return torch.round(x_clipped / scales) * scales