Build
Browse filesFiles changed (24)
- build/torch24-cxx11-cu118-x86_64-linux/quantization/__init__.py+107-1
- build/torch24-cxx11-cu118-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch24-cxx11-cu121-x86_64-linux/quantization/__init__.py+107-1
- build/torch24-cxx11-cu121-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch24-cxx11-cu124-x86_64-linux/quantization/__init__.py+107-1
- build/torch24-cxx11-cu124-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch24-cxx98-cu118-x86_64-linux/quantization/__init__.py+107-1
- build/torch24-cxx98-cu118-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch24-cxx98-cu121-x86_64-linux/quantization/__init__.py+107-1
- build/torch24-cxx98-cu121-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch24-cxx98-cu124-x86_64-linux/quantization/__init__.py+107-1
- build/torch24-cxx98-cu124-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch25-cxx11-cu118-x86_64-linux/quantization/__init__.py+107-1
- build/torch25-cxx11-cu118-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch25-cxx11-cu121-x86_64-linux/quantization/__init__.py+107-1
- build/torch25-cxx11-cu121-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch25-cxx11-cu124-x86_64-linux/quantization/__init__.py+107-1
- build/torch25-cxx11-cu124-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch25-cxx98-cu118-x86_64-linux/quantization/__init__.py+107-1
- build/torch25-cxx98-cu118-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch25-cxx98-cu121-x86_64-linux/quantization/__init__.py+107-1
- build/torch25-cxx98-cu121-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
- build/torch25-cxx98-cu124-x86_64-linux/quantization/__init__.py+107-1
- build/torch25-cxx98-cu124-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
1123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:c9343c97509a78e62cf1f87abbf3bc426f8f85e0c95694b3b2b80740d3cbf280size 30943736oid sha256:1ff4df94b3de0caab5c2c7584f21eb3898d495bcf92a731fb1fd9a46ba0dff50size 391788961123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:626d8e62d5801cdca8869b45e4f79893de3ee6637b86f2647e2b1d1bb1452020size 36253328oid sha256:0dd82ba302527185d214e508371d75778524c412934d0f2399bd3d00402b89c5size 465400641123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:1b1e9f1b5beb9f5de558dcfcf2d61ecc4e207a723ba810605d70d9aa31e65df5size 37028144oid sha256:0cac14195f6181d145e9f1cc0c1e532f8cfa2914fe7ff59fdf3194c85fd28b9csize 474135921123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:6d5fa1dba02499bec6e2225c83e460ae0d8e7ca396763d2851f7e000be88e675size 30940256oid sha256:0054660979a4c0a273f32b6293294d02048b14a90af3b1f3e5cb226504cffe15size 391662481123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:1bd3556b97cd85c7282ded2057e59207575b92107e0a7e17fcffa82d27f42d26size 36256840oid sha256:735a3a1fe3aea0065a7378f11611378923331d7633000441fa5d0d5e03d0d481size 465346081123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:f7aa8e42070dfb49e64cfa204bbb81ab2750c2cfafacac6f8d4ae303285a735asize 37027640oid sha256:0b30e0d4e60669a253ed18f92b5219fdc3b40c2f0e792bf275c62a058998ebadsize 474040401123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:2a9874fefa371528c54a12851771476c3baf9356536b88c960d7ec3dcf293469size 30943736oid sha256:cd1b0623532cab4059a48c8e8e7417df9ba309968adcd03705012fa79b04776dsize 391788961123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:554ac8e33120544e28fb91abab1f03b29e6665256c5acfec69137072575b7945size 36253328oid sha256:c129629d41aedd275b5a5545f86d968f0e9cc63085e54b09f0daff930af8f48csize 465400641123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:373d2248e3ffc236b6b86521dabe2604609e8646107eb3c2d74a9378490a8878size 37028144oid sha256:d691489858bbbac2d9031f49378d34d6c1ec3ed9592c933916cdb0fd470b4e54size 474135921123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:7bf3ca9934fb5cf098acbd3e41eab1004f358b49c7c459b01649753dca258d97size 30940256oid sha256:bc0a49e4a96613598d16cb392b3e5580c1461e2cb6ca291876aeeb4c1afeabf7size 391662481123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:5582e29a80ea71e618ccdeb9ad49456d3ebf130ee4c3001b1904e73094460455size 36256840oid sha256:c8b055cc65c6680f15caf698d12f7e0b87332132e7489b689381643873a518a0size 465346081123437 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150from typing import Optionalfrom typing import Optional, Tuple
import torch
37 unmodified lines
return out
# fp8def scaled_fp8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, num_token_padding: Optional[int] = None, scale_ub: Optional[torch.Tensor] = None, use_per_token_if_dynamic: bool = False,) -> Tuple[torch.Tensor, torch.Tensor]: """ Quantize input tensor to FP8 and return quantized tensor and scale.
This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensors for downstream kernels that will benefit from padding.
Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case.
Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor. """ # This code assumes batch_dim and num_tokens are flattened assert (input.ndim == 2) shape: Union[Tuple[int, int], torch.Size] = input.shape # For rocm, the output fp8 dtype is torch.float_e3m3fnuz #out_dtype: torch.dtype = torch.float8_e4m3fnuz \ # if current_platform.is_rocm() else torch.float8_e4m3fn out_dtype = torch.float8_e4m3fn if num_token_padding: shape = (max(num_token_padding, input.shape[0]), shape[1]) output = torch.empty(shape, device=input.device, dtype=out_dtype)
if scale is None: if use_per_token_if_dynamic: scale = torch.empty((shape[0], 1), device=input.device, dtype=torch.float32) ops.dynamic_per_token_scaled_fp8_quant( output, input, scale, scale_ub) else: scale = torch.zeros(1, device=input.device, dtype=torch.float32) ops.dynamic_scaled_fp8_quant(output, input, scale) else: # num_token_padding not implemented for this case assert (scale.numel() == 1 or num_token_padding is None) ops.static_scaled_fp8_quant(output, input, scale)
return output, scale
# int8def scaled_int8_quant( input: torch.Tensor, scale: Optional[torch.Tensor] = None, azp: Optional[torch.Tensor] = None, symmetric: bool = True) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]: """ Quantize the input tensor to int8 and return the quantized tensor and scale, and maybe azp.
Args: input: The input tensor to be quantized to int8. scale: Optional scaling factor for the int8 quantization. When not provided, we invoke dynamic-per-token quantization. azp: Optional zero-point for the int8 quantization. Must be provided for asymmetric quantization if `scale` is provided. symmetric: Whether to use symmetric quantization (scale only, azp ignored).
Returns: Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]] : Output int8 tensor, scales, and optionally azp. """ output = torch.empty_like(input, dtype=torch.int8) if scale is not None: # static-per-tensor quantization. assert symmetric == ( azp is None), "azp must only be provided for asymmetric quantization." ops.static_scaled_int8_quant(output, input, scale, azp) return output, scale, azp
# dynamic-per-token quantization. input_scales = torch.empty((input.numel() // input.shape[-1], 1), device=input.device, dtype=torch.float32) input_azp = None if symmetric else torch.empty_like(input_scales, dtype=torch.int32) ops.dynamic_scaled_int8_quant(output, input, input_scales, input_azp) return output, input_scales, input_azp
# fp8 marlindef fp8_marlin_gemm(a: torch.Tensor, b_q_weight: torch.Tensor, b_scales: torch.Tensor, workspace: torch.Tensor, num_bits: int, size_m: int, size_n: int, size_k: int) -> torch.Tensor: return ops.fp8_marlin_gemm(a, b_q_weight, b_scales, workspace, num_bits, size_m, size_n, size_k)12323version https://git-lfs.github.com/spec/v1oid sha256:0d16013abe29e9d3914a19078bf6195bf6a9402222fe48dd75e5a3827e081f49size 37027640oid sha256:5e9f624b3f8585ca9c688a08b7191f1a2212cd1b64701ba9b0075deedd3fe3d4size 47404040build/torch24-cxx11-cu118-x86_64-linux/quantization/__init__.py+107-1
build/torch24-cxx11-cu118-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch24-cxx11-cu121-x86_64-linux/quantization/__init__.py+107-1
build/torch24-cxx11-cu121-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch24-cxx11-cu124-x86_64-linux/quantization/__init__.py+107-1
build/torch24-cxx11-cu124-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch24-cxx98-cu118-x86_64-linux/quantization/__init__.py+107-1
build/torch24-cxx98-cu118-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch24-cxx98-cu121-x86_64-linux/quantization/__init__.py+107-1
build/torch24-cxx98-cu121-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch24-cxx98-cu124-x86_64-linux/quantization/__init__.py+107-1
build/torch24-cxx98-cu124-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch25-cxx11-cu118-x86_64-linux/quantization/__init__.py+107-1
build/torch25-cxx11-cu118-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch25-cxx11-cu121-x86_64-linux/quantization/__init__.py+107-1
build/torch25-cxx11-cu121-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch25-cxx11-cu124-x86_64-linux/quantization/__init__.py+107-1
build/torch25-cxx11-cu124-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch25-cxx98-cu118-x86_64-linux/quantization/__init__.py+107-1
build/torch25-cxx98-cu118-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch25-cxx98-cu121-x86_64-linux/quantization/__init__.py+107-1
build/torch25-cxx98-cu121-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2
build/torch25-cxx98-cu124-x86_64-linux/quantization/__init__.py+107-1
build/torch25-cxx98-cu124-x86_64-linux/quantization/_quantization_0_0_1.abi3.so+2-2