快捷方式

量化运算符

量化是一种模型优化技术,用于减小大型模型的尺寸,以在精度略微下降的情况下实现更好的存储性能。

CUDA 运算符

at::Tensor _float_to_bfloat16_gpu(const at::Tensor &input)

将浮点 (float) 值张量转换为脑浮点 (bfloat16) 值张量。

参数:

input – 浮点 (float) 值张量

返回:

一个新张量,其中包含从输入张量转换为 bfloat16 的值。

at::Tensor _bfloat16_to_float_gpu(const at::Tensor &input)

将脑浮点 (bfloat16) 值张量转换为浮点 (float) 值张量。

参数:

input – 脑浮点 (bfloat16) 值张量

返回:

一个新张量,其中包含从输入张量转换为 float 的值。

Tensor _float_to_FP8rowwise_gpu(const Tensor &input, const bool forward)

将浮点 (float) 值张量转换为 fp8 值张量。

参数:
  • input – 浮点 (float) 值张量。dtype 可以是 SparseType::FP32SparseType::FP16SparseType::BF16

  • forward

抛出:

c10::Error – 如果 input.dtype 不是 (SparseType::FP32SparseType::FP16SparseType::BF16) 之一。

返回:

一个新张量,其中包含从输入张量转换为 fp8 的值。

at::Tensor _FP8rowwise_to_float_gpu(const at::Tensor &input, bool forward, const int64_t output_dtype)

fp8 值张量转换为浮点 (float) 值张量。

参数:
  • inputfp8 值张量

  • forward

  • output_dtype – 目标浮点类型,指定为 SparseType 枚举的整数表示

抛出:

c10::Error – 如果 output_dtype 不是 (SparseType::FP32SparseType::FP16SparseType::BF16) 之一。

返回:

一个新张量,其中包含从输入张量转换为 float 的值(dtypeSparseType::FP32SparseType::FP16SparseType::BF16 之一)。

Tensor _float_to_fused8bitrowwise_gpu(const Tensor &input)

将浮点 (float) 值张量转换为融合的 8 位行式值张量。

参数:

input – 浮点 (float) 值张量

返回:

一个新张量,其中包含从输入张量转换为融合 8 位行式的值。

Tensor _half_to_fused8bitrowwise_gpu(const Tensor &input)

at::Half 值张量转换为融合的 8 位行式值张量。

参数:

inputat::Half 值张量

返回:

一个新张量,其中包含从输入张量转换为融合 8 位行式的值。

Tensor _single_or_half_precision_to_fused8bitrowwise_gpu(const Tensor &input)

at::Singleat::Half 值张量转换为融合的 8 位行式值张量。

参数:

inputat::Singleat::Half 值张量

返回:

一个新张量,其中包含从输入张量转换为融合 8 位行式的值。

at::Tensor _fused8bitrowwise_to_float_gpu(const at::Tensor &input)

将融合的 8 位行式值张量转换为浮点 (float) 值张量。

参数:

input – 融合的 8 位行式值张量

返回:

一个新张量,其中包含从输入张量转换为 float 的值。

at::Tensor _fused8bitrowwise_to_half_gpu(const at::Tensor &input)

将融合的 8 位行式值张量转换为 at::Half 值张量。

参数:

input – 融合的 8 位行式值张量

返回:

一个新张量,其中包含从输入张量转换为 at::Half 的值。

at::Tensor _fused8bitrowwise_to_single_or_half_precision_gpu(const at::Tensor &input, const int64_t output_dtype, const bool scale_bias_last, const bool quant_padding_float_type)

将融合的 8 位行式值张量转换为 floatat::Halfat::BFloat16 值张量。

参数:
  • input – 融合的 8 位行式值张量

  • output_dtype – 目标浮点类型,指定为 SparseType 枚举的整数表示

抛出:

c10::Error – 如果 output_dtype 不是 (SparseType::FP32SparseType::FP16SparseType::BF16) 之一。

返回:

一个新张量,其中包含从输入张量转换为 floatat::Halfat::BFloat16 的值。

at::Tensor _fused8bitrowwise_to_float_mixed_dim_gpu(const at::Tensor &input, const at::Tensor &D_offsets, const int64_t output_dtype)

将融合的 8 位行式值张量转换为 at::kFloatat::kHalf 值张量。

参数:
  • input – 融合的 8 位行式值张量

  • D_offsets

  • output_dtype – 目标浮点类型,指定为 SparseType 枚举的整数表示

抛出:

c10::Error – 如果 output_dtype 不是 (SparseType::FP32SparseType::FP16) 之一

返回:

一个新张量,其中包含从输入张量转换为 at::kFloatat::kHalf 的值。

Tensor _float_to_fusednbitrowwise_gpu(const Tensor &input, const int64_t bit_rate)

将浮点 (float) 值张量转换为融合的 N 位行式值张量。

参数:
  • input – 浮点 (float) 值张量

  • bit_rate

返回:

一个新张量,其中包含从输入张量转换为融合 N 位行式的值。

at::Tensor _half_to_fusednbitrowwise_gpu(const at::Tensor &input, const int64_t bit_rate)

at::Half 值张量转换为融合的 N 位行式值张量。

参数:
  • inputat::Half 值张量

  • bit_rate

返回:

一个新张量,其中包含从输入张量转换为融合 N 位行式的值。

Tensor _single_or_half_precision_to_fusednbitrowwise_gpu(const Tensor &input, const int64_t bit_rate)

将浮点 (float) 或 at::Half 值张量转换为融合的 N 位行式值张量。

参数:
  • input – 浮点 (float) 或 at::Half 值张量

  • bit_rate

返回:

一个新张量,其中包含从输入张量转换为融合 N 位行式的值。

at::Tensor _fusednbitrowwise_to_float_gpu(const at::Tensor &input, const int64_t bit_rate)

将融合的 N 位行式值张量转换为浮点 (float) 值张量。

参数:
  • input – 融合的 N 位行式值张量

  • bit_rate

返回:

一个新张量,其中包含从输入张量转换为 float 的值。

at::Tensor _fusednbitrowwise_to_half_gpu(const at::Tensor &input, const int64_t bit_rate)

将融合的 N 位行式值张量转换为 at::Half 值张量。

参数:
  • input – 融合的 N 位行式值张量

  • bit_rate

返回:

一个新张量,其中包含从输入张量转换为 at::Half 的值。

at::Tensor _fusednbitrowwise_to_single_or_half_precision_gpu(const at::Tensor &input, const int64_t bit_rate, const int64_t output_dtype, const bool scale_bias_last)

将融合的 N 位行式值张量转换为 floatat::Halfat::Bf16 值张量。

参数:
  • input – 融合的 N 位行式值张量

  • bit_rate

  • output_dtype – 目标浮点类型,指定为 SparseType 枚举的整数表示

抛出:

c10::Error – 如果 output_dtype 不是 (SparseType::FP32SparseType::FP16SparseType::BF16) 之一。

返回:

一个新张量,其中包含从输入张量转换为 floatat::Halfat::Bf16 的值,具体取决于 output_dtype

at::Tensor _float_to_hfp8_gpu(const at::Tensor &input, const int64_t ebits, const int64_t exponent_bias, const double max_pos)

将浮点 (float) 值张量转换为混合 8 位浮点 (hfp8) 值张量。

参数:
  • input – 浮点 (float) 值张量

  • ebits

  • exponent_bias

  • max_pos

抛出:

c10::Error – 如果 ebits > 0exponent_bias > 0

返回:

一个新张量,其中包含从输入张量转换为 hfp8 的值。

at::Tensor _hfp8_to_float_gpu(const at::Tensor &input, const int64_t ebits, const int64_t exponent_bias)

将混合 8 位浮点 (hfp8) 值张量转换为浮点 (float) 值张量。

参数:
  • inputhfp8 值张量

  • ebits

  • exponent_bias

抛出:

c10::Error – 如果 ebits > 0exponent_bias > 0

返回:

一个新张量,其中包含从输入张量转换为 float 的值。

at::Tensor _float_to_msfp_gpu(const at::Tensor &input, const int64_t bounding_box_size, const int64_t ebits, const int64_t mbits, const int64_t bias, const double min_pos, const double max_pos)

将浮点 (float) 值张量转换为微软浮点 (msfp) 值张量。

参数:
  • input – 浮点 (float) 值张量

  • bounding_box_size

  • ebits

  • mbits

  • bias

  • min_pos

  • max_pos

返回:

一个新张量,其中包含从输入张量转换为 msfp 的值。

at::Tensor _msfp_to_float_gpu(const at::Tensor &input, const int64_t ebits, const int64_t mbits, const int64_t bias)

将微软浮点 (msfp) 值张量转换为浮点 (float) 值张量。

参数:
  • inputmsfp 值张量

  • ebits

  • mbits

  • bias

返回:

一个新张量,其中包含从输入张量转换为 float 的值。

Tensor _float_to_paddedFP8rowwise_gpu(const Tensor &input, const bool forward, const int64_t row_dim)

将浮点 (float) 值张量转换为填充的 fp8 行式值张量。

参数:
  • input – 浮点 (float) 值张量。dtype 可以是 SparseType::FP32SparseType::FP16SparseType::BF16

  • forward

  • row_dim

返回:

一个新张量,其中包含从输入张量转换为填充的 fp8 行式的值。

at::Tensor _paddedFP8rowwise_to_float_gpu(const at::Tensor &input, const bool forward, const int64_t row_dim, const int64_t output_last_dim, const int64_t output_dtype)

将填充的 fp8 行式值张量转换为浮点 (float / values) 值张量。

@param input A tensor of `float` values.  The dtype can be either
             `SparseType::FP32`, `SparseType::FP16`, or `SparseType::BF16`
@param forward
@param row_dim
@param output_last_dim
@param output_dtype The target floating point type, specified as integer
                    representation of `SparseType` enum

@return A new tensor with values from the input tensor converted to `float`.

@throw c10::Error if `output_dtype` is not one of (`SparseType::FP32`,
`SparseType::FP16`, `SparseType::BF16`).

CPU 运算符

Tensor &_fused8bitrowwise_to_float_cpu_out(Tensor &output, const Tensor &input)
Tensor &_float_to_fused8bitrowwise_cpu_out(Tensor &output, const Tensor &input)
Tensor float_to_fused8bitrowwise_cpu(const Tensor &input)
Tensor half_to_fused8bitrowwise_cpu(const Tensor &input)
Tensor float_or_half_to_fused8bitrowwise_cpu(const Tensor &input)
Tensor fused8bitrowwise_to_float_cpu(const Tensor &input)
Tensor fused8bitrowwise_to_half_cpu(const Tensor &input)
Tensor fused8bitrowwise_to_float_or_half_cpu(const Tensor &input, const int64_t output_dtype, const bool scale_bias_last, const bool quant_padding_float_type)
Tensor float_to_FP8rowwise_cpu(const Tensor &input, bool)
Tensor FP8rowwise_to_float_cpu(const Tensor &input, bool, const int64_t)
Tensor fusednbitrowwise_to_float_cpu(const Tensor &input, const int64_t bit_rate)
Tensor fusednbitrowwise_sbfront_to_float_cpu(const Tensor &input, const int64_t bit_rate, const int64_t output_dtype)

将 int4/int2 行及其前端存储的比例和偏差反量化为 float32/float16/Bfloat16。

将 int4/int2 行及其前端存储的比例和偏差反量化为 float32。输入张量应具有 torch.quint4x2 或 torch.quint2x4 dtype 和 QuantizedCPU 后端。此操作符仅推荐用于测试目的,因为其内核是参考实现且未优化。

参数:
  • input – 具有前端存储的比例和偏差的 int4/int2 行张量。

  • bit_rate – 每个元素的比特率。应为 4 或 2。

返回:

float32 张量,存储反量化后的数字。

Tensor fusednbitrowwise_to_half_cpu(const Tensor &input, const int64_t bit_rate)
Tensor fusednbitrowwise_to_float_or_half_cpu(const Tensor &input, const int64_t bit_rate, const int64_t output_dtype, const bool scale_bias_last)
void FloatToFP8Quantized_ref(const float *const input, const size_t nrows, const size_t ncols, uint8_t *const output, const int ebits, const int exponent_bias, const double max_pos)
void FP8QuantizedToFloat_ref(const uint8_t *const input, const size_t nrows, const size_t ncols, float *const output, const int ebits, const int exponent_bias)

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

查找开发资源并让您的问题得到解答

查看资源