快捷方式

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[源代码]

将张量转换为归一化浮点权重格式

static dequantize(value: Tensor, nf4: Tensor) Tensor[源代码]

将 nf4 值反量化为 bfloat16 格式

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)

返回类型:

torch.Tensor

get_original_weight() Tensor[源代码]

从归一化浮点权重格式获取原始权重

static quantize_tensor_nearest(value: Tensor, nf4: Tensor) Tensor[源代码]

将 float16 张量量化为 nf4 格式,采用最近邻方法,而不是向上舍入

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并获得问题解答

查看资源