flashinfer.quantization.packbits

flashinfer.quantization.packbits(x: Tensor, bitorder: str = 'big') Tensor

将一个二进制值的数组的元素打包到 uint8 数组中的比特位。

此函数语义与 numpy.packbits 相同。

参数:
  • x (torch.Tensor) – 要打包的 1D 二进制值数组。

  • bitorder (str) – 输出的比特顺序(“bit”/”little”)。默认值为“big”。

返回值:

y – 一个 uint8 打包数组,形状为 ((x.size(0) + 7) / 8),)

返回值类型:

torch.Tensor

示例

>>> import torch
>>> from flashinfer import packbits
>>> x = torch.tensor([1, 0, 1, 1, 0, 0, 1, 1], dtype=torch.bool, device="cuda")
>>> x_packed = packbits(x)
>>> list(map(bin, x_packed.tolist()))
['0b10110011']