bits.config
Configuration dataclasses.
DotGeneral
dataclass
Configuration of quantization of dot_general and its gradients.
Source code in src/fjformer/bits/config.py
101 102 103 104 105 106 107 108 109 110 111 | |
DotGeneralRaw
dataclass
Configuration of quantization of one dot_general without gradient.
Source code in src/fjformer/bits/config.py
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 | |
make(*args, **kwargs)
classmethod
The make function is a factory function that creates an instance of the DotGeneralRaw class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls |
Create a new instance of the class |
required | |
args |
Send a non-keyworded variable length argument list to the function |
()
|
|
kwargs |
Pass a variable number of keyword arguments to the function |
{}
|
Returns:
| Type | Description |
|---|---|
DotGeneralRaw
|
A dotgeneralraw object |
Source code in src/fjformer/bits/config.py
73 74 75 76 77 78 79 80 81 82 83 | |
make_conv_general_dilated(*args, **kwargs)
classmethod
The make_conv_general_dilated function is a wrapper for the conv_general_dilated_make function. It allows us to use the make function in our DotGeneralRaw class, which we can then use as a component of our network. The make function takes in arguments that are used by the conv_general_dilated_make function to create an instance of DotGeneralRaw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls |
Create a new instance of the class |
required | |
args |
Send a non-keyworded variable length argument list to the function |
()
|
|
kwargs |
Pass a variable number of keyword arguments to a function |
{}
|
Returns:
| Type | Description |
|---|---|
DotGeneralRaw
|
A dotgeneralraw object |
Source code in src/fjformer/bits/config.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
Tensor
dataclass
Configuration of quantization of one tensor or one side of tensor op.
Source code in src/fjformer/bits/config.py
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 | |
config_v3(*, fwd_bits=8, dlhs_bits=8, drhs_bits=None, use_dummy_static_bound=False, rng_type='jax.uniform', dlhs_local_aqt=None, drhs_local_aqt=None, fwd_accumulator_dtype=jnp.int32, dlhs_accumulator_dtype=jnp.int32, drhs_accumulator_dtype=None)
The config_v3 function is a helper function that configures the DotGeneral object. It takes in keyword arguments and returns a configured DotGeneral object. The following are the keyword arguments:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
* |
Indicate that all the following parameters are keyword-only |
required | |
fwd_bits |
Optional[int]
|
Optional[int]: Set the number of bits used for forward pass |
8
|
dlhs_bits |
Optional[int]
|
Optional[int]: Set the number of bits for the |
8
|
drhs_bits |
Optional[int]
|
Optional[int]: Specify the number of bits |
None
|
use_dummy_static_bound |
bool
|
bool: Set the static bound to 1 |
False
|
rng_type |
str
|
str: Specify the random number generator |
'jax.uniform'
|
dlhs_local_aqt |
Optional[LocalQ]
|
Optional[LocalQ]: Set the local quantization of the dlhs |
None
|
drhs_local_aqt |
Optional[LocalQ]
|
Optional[LocalQ]: Set the local quantization |
None
|
fwd_accumulator_dtype |
...
|
...: Specify the accumulator dtype for the forward pass |
int32
|
dlhs_accumulator_dtype |
...
|
...: Specify the accumulator dtype for the gradient |
int32
|
drhs_accumulator_dtype |
...
|
...: Specify the data type of the accumulator in drhs |
None
|
|
Specify the number of bits used for quantization |
required |
Returns:
| Type | Description |
|---|---|
DotGeneral
|
A dotgeneral object |
Source code in src/fjformer/bits/config.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
conv_general_dilated_make(spatial_dimensions=2, lhs_bits=None, rhs_bits=None)
Create quantization config conv_general_dilated.
Source code in src/fjformer/bits/config.py
270 271 272 273 274 275 276 277 278 279 280 281 282 | |
dot_general_make(lhs_bits=None, rhs_bits=None, bwd_bits=None, use_fwd_quant=True, dlhs_local_aqt=None, drhs_local_aqt=None)
Create quantization configs for input matrices to a matmul.
Source code in src/fjformer/bits/config.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
dot_general_raw_make(lhs_bits=None, rhs_bits=None, local_aqt=None)
The dot_general_raw_make function is a helper function that creates a DotGeneralRaw object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs_bits |
Determine the dtype of the lhs tensor |
None
|
|
rhs_bits |
Determine the dtype of the accumulator |
None
|
|
local_aqt |
Determine the type of accumulator used |
None
|
|
|
Determine the dtype of the accumulator |
required |
Returns:
| Type | Description |
|---|---|
DotGeneralRaw
|
A dotgeneralraw object |
Source code in src/fjformer/bits/config.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
fully_quantized(*, fwd_bits=8, bwd_bits=8, use_fwd_quant=True, use_stochastic_rounding=True, vjp_lhs_stochastic_rounding=None, vjp_rhs_stochastic_rounding=None, use_dummy_static_bound=False, dlhs_local_aqt=None, drhs_local_aqt=None)
The fully_quantized function is a helper function that allows you to quickly configure the dot_general primitive with all of its quantization parameters. It takes in keyword arguments for each of the quantization parameters, and returns a DotGeneral configuration object. The following table shows what each parameter does:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
* |
Indicate that all the parameters are keyword-only |
required | |
fwd_bits |
Optional[int]
|
Optional[int]: Specify the number of bits used for forward quantization |
8
|
bwd_bits |
Optional[int]
|
Optional[int]: Set the number of bits used for backpropagation |
8
|
use_fwd_quant |
bool
|
bool: Control whether to quantize the |
True
|
use_stochastic_rounding |
Optional[bool]
|
Optional[bool]: Enable stochastic rounding |
True
|
vjp_lhs_stochastic_rounding |
Optional[bool]
|
Optional[bool]: Ensure that we don't mix |
None
|
vjp_rhs_stochastic_rounding |
Optional[bool]
|
Optional[bool]: |
None
|
use_dummy_static_bound |
bool
|
bool: Set the static bound to 1 |
False
|
dlhs_local_aqt |
Optional[LocalQ]
|
Optional[LocalQ]: Specify the quantization scheme for the left-hand side of a matrix multiplication |
None
|
drhs_local_aqt |
Optional[LocalQ]
|
Optional[LocalQ]: Specify the quantization scheme for the right hand side of a matrix multiplication |
None
|
|
Set the number of bits used for forward and backward pass |
required |
Returns:
| Type | Description |
|---|---|
DotGeneral
|
A dotgeneral object, which is a |
Source code in src/fjformer/bits/config.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
set_accumulator_dtype(cfg, fwd_dtype, dlhs_dtype, drhs_dtype)
The set_accumulator_dtype function sets the accumulator dtype for each of the three differentiable functions. The accumulator dtype is used to store intermediate results during forward and backward passes. It is also used to store gradients during backward pass. The default value for this parameter is None, which means that it will be set automatically by the library based on other parameters such as input data types and output data type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg |
DotGeneral
|
DotGeneral: Set the accumulator dtype for all three |
required |
fwd_dtype |
Optional[DType]
|
Optional[DType]: Set the dtype of the forward pass |
required |
dlhs_dtype |
Optional[DType]
|
Optional[DType]: Set the data type of the left hand side |
required |
drhs_dtype |
Optional[DType]
|
Optional[DType]: Set the data type for the drhs accumulator |
required |
|
Set the dtype of the accumulator |
required |
Source code in src/fjformer/bits/config.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
set_fwd_numerics(cfg, fwd_numerics)
The set_fwd_numerics function sets the numerics of the forward problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg |
Store the configuration of the simulation |
required | |
fwd_numerics |
QNumerics
|
numerics.QNumerics: Set the numerical |
required |
Returns:
| Type | Description |
|---|---|
|
The configuration object with the numerics for the forward problem set |
Source code in src/fjformer/bits/config.py
114 115 116 117 118 119 120 121 122 123 | |
set_static_bound(cfg, bound=1.0)
The set_static_bound function sets the calibration of all the forward and backward differentiation operators to a constant value. This is useful for testing purposes, as it allows us to check that our implementation is correct by comparing against known values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg |
DotGeneral
|
DotGeneral: Set the bounds for each of the six functions in a dotgeneral object |
required |
bound |
float
|
float: Set the bound of the calibration |
1.0
|
Source code in src/fjformer/bits/config.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
set_stochastic_rounding(cfg, vjp_lhs_stochastic_rounding, vjp_rhs_stochastic_rounding, implementation)
Configure stochastic rounding implementation.
Source code in src/fjformer/bits/config.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
tensor_make(bits)
The tensor_make function is a helper function that creates a Tensor object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bits |
Optional[int]
|
Optional[int]: Set the number of bits for quantization |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
A tensor object |
Source code in src/fjformer/bits/config.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |