flashinfer.quantization.packbits

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

Pack the elements of a binary-valued array into bits in a uint8 array.

The semantics of this function is the same as numpy.packbits.

Parameters:
  • x (torch.Tensor) – The 1D binary-valued array to pack.

  • bitorder (str) – The bit-order (“bit”/”little”) of the output. Default is “big”.

Returns:

y – An uint8 packed array, shape ((x.size(0) + 7) / 8),).

Return type:

torch.Tensor

Examples

>>> 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']

See also

segment_packbits