FilesLast commitLast update
17 days ago
2 months ago
2 months ago
28 days ago
1 month ago
25 days ago
1 month ago
25 days ago
2 months ago
1 month ago
9 days ago
README

SignBitsPack

English | 简体中文

Product Support Status

Product Supported
Ascend 950PR&950DT products √
Atlas A3 products √
Atlas A2 products √
Atlas 200I/500 A2 inference products ×
Atlas inference products √
Atlas training products ×

Function Description

  • Operator function: extracts the sign bits of floating-point numbers and packs them into uint8 bytes. The sign bits of every 8 floating-point numbers (0 indicates non-negative, and 1 indicates negative) are packed into 1 uint8 byte, where the sign bit of the 1st floating-point number corresponds to bit7 and that of the 8th corresponds to bit0. It is mainly used in the 1-bit Adam optimizer scenario to compress and store sign information.
  • Computation formula:

bi={0xi≥01xi<0b_i = \begin{cases} 0 & x_i \geq 0 \\ 1 & x_i < 0 \end{cases}

yj=∑k=07b8j+k⋅27−ky_j = \sum_{k=0}^{7} b_{8j+k} \cdot 2^{7-k}

out=reshape ⁣({yj},  (size,  L / size))\text{out} = \mathrm{reshape}\!\left(\{y_j\},\; (\text{size},\; L\,/\,\text{size})\right)

Here, L=⌈N/8⌉L = \lceil N / 8 \rceil, and NN is the number of input elements. When NN is not a multiple of 8, the tail is padded with −1.0-1.0 (the sign bit is 1).

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
x Input Floating-point tensor to be packed, 1D. The sign bit of each element is extracted. Non-contiguous tensors are automatically converted to contiguous. FLOAT16/FLOAT ND
size Required attribute
  • Size of the first dimension of the output.
  • The value must be a positive integer (size ≥ 1).
  • ceil(N/8) % size == 0 must be satisfied.
INT64 -
y Output Sign bit packing result, 2D. Its shape is [size, ceil(N/8)/size], and its dtype is always uint8. UINT8 ND

Constraint Description

  • Only the ND data format is supported.
  • The input x must be 1D (rank=1). Scalars or multi-dimensional tensors are not supported.
  • The type combination is fixed to FLOAT16→UINT8 or FLOAT→UINT8, and other dtype combinations are not supported.
  • The attribute size must be a positive integer (size ≥ 1), and ceil(N/8) must be integer-divisible by size.
  • Empty tensors (N=0) are supported, and an empty output with the shape [size, 0] is returned directly.
  • Non-contiguous tensors are supported, and the framework automatically converts them to contiguous before execution.
  • Both +0 and -0 are considered non-negative (the sign bit is 0). NaN is not supported, and its behavior is undefined.
  • Deterministic implementation by default. The same input always produces the same output.

Invocation Description

Invocation Method Invocation Sample Description
Single-operator invocation test_aclnn_sign_bits_pack Invokes the SignBitsPack operator through the aclnn API.
Graph-mode invocation test_geir_sign_bits_pack Invokes the SignBitsPack operator by building a graph through GE-IR.