bits.bits
matmul(a, b, *, precision=None, dot_general=lax.dot_general)
Quantized jax.numpy.matmul.
Args:
a: Left-hand side of the matmul.
b: Right-hand side of the matmul.
precision: Indicates precision of a and b.
dot_general: lax.dot_general by default. To use quantized matmul, the
wrapper of q_dot_general in which TQs and train flag are provided
should be passed into this function.
Returns: An array containing the result with the same dtype as 'a' and 'b'.
Source code in src/fjformer/bits/bits.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
matmul_true_int8(lhs, rhs)
The matmul_true_int8 function is a helper function that takes in two int8 arrays and returns the result of their matrix multiplication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs |
Specify the left hand side of the matrix multiplication |
required | |
rhs |
Specify the right-hand side of the matrix multiplication |
required |
Returns:
| Type | Description |
|---|---|
|
A matrix with elements of type int32 |
Source code in src/fjformer/bits/bits.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
q_matmul_int8(a, w)
The q_matmul_int8 function performs a quantized matrix multiplication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a |
Calibrate the input data |
required | |
w |
Store the weights of the neural network |
required |
Returns:
| Type | Description |
|---|---|
|
A float32 array, which is the result of an int8 matrix multiplication |
Source code in src/fjformer/bits/bits.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
quant_int8(x)
The quant_int8 function takes a floating point number and rounds it to the nearest integer. If the rounded value is outside the range [-127, 127], then it clips it to that range. Finally, we cast this clipped integer into an int8 type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x |
Pass the input to the function |
required |
Returns:
| Type | Description |
|---|---|
|
The rounded and clipped values |
Source code in src/fjformer/bits/bits.py
117 118 119 120 121 122 123 124 125 126 127 | |