NF4Tensor¶
- class torchao.dtypes.NF4Tensor(tensor_meta: SubclassTensorArgs, block_size: int, n_blocks: int, scaler_block_size: int, quantized_scalers: Tensor, quantization_factor: Tensor, scaler_mean: Tensor, quantized_data: Tensor, nf4: Tensor)[源代码]¶
用于将权重转换为 QLoRA NF4 格式的 NF4Tensor 类
- static convert_to_norm_float_weight(input_tensor: Tensor, n_blocks: int, block_size: int, nf4: Tensor) Tensor [源代码]¶
将张量转换为归一化浮点权重格式
- dequantize_scalers(input_tensor: Tensor, quantization_factor: Tensor, scaler_block_size: int) Tensor [源代码]¶
用于解包双重量化器
- Args;
input_tensor: 要转换为 QLoRA 格式的输入张量,这是 int8 格式的量化器 quantization_factor: 以 inpt_weight.dtype 存储的 per_scaler_block 量化因子的张量
size: (n_scaler_blocks)
scaler_block_size: 用于双重量化的量化器块大小。
- static double_quantize_scalers(input_tensor: Tensor, block_size: int, scaler_block_size: int) Tuple[Tensor, Tensor, Tensor] [源代码]¶
用于实现量化器的双重量化。我们首先获取输入张量,计算每个块的绝对值最大量化因子。然后,我们找到正绝对值最大量化器的均值。我们从量化器中减去此均值,然后再次计算每个块的绝对值最大量化因子。然后,我们将量化器量化为 int8。
- 参数:
input_tensor – 要转换为 QLoRA 格式的输入张量,通常是权重张量
- 返回值:
- 以 int8 格式存储的 per_block 量化因子的张量
size: (n_blocks)
- torch.Tensor: 以 int16 格式存储的 per_scaler_block 量化因子的张量
size: (n_scaler_blocks)
- 返回类型: