Skip to content

Commit

Permalink
Addressed comments on placement of default values in the specification
Browse files Browse the repository at this point in the history
  • Loading branch information
sdasgup3 committed Apr 6, 2023
1 parent 83c006c commit e74d3cf
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ values of type `tensor<T>`).
`f = (i - zero_point) * scale`, where `scale` and `zero_point` are called
**quantization parameters**. The `storage_min` and `storage_max`, being
optional, have default values which should satisfy the associated constraints
as laid out in this document.
as laid out in this document. The `storage_min` and `storage_max` are optional
in the grammar, but have default values of `min_value(storage_type)` and
`max_value(storage_type)` respectively.

Quantization can be **per-tensor**, meaning, having one `scale` and/or
`zero_point` for the entire tensor or can be **per-axis**, meaning, having
Expand All @@ -213,33 +215,25 @@ Quantized types satisfy the following constraints:
* (C1) `num_bits(storage_type) < num_bits(expressed_type)`.
* (C2) `type(storage_min) = storage_type`.
* (C3) `type(storage_max) = storage_type`.
* (C4) If `storage_min` is empty and `d = num_bits(storage_type)`:
* `storage_min = is_signed(storage_type) ? -2^(d-1) : 0`.
* (C5) If `storage_max` is empty:
* `storage_max = is_signed(storage_type) ? 2^(d-1) : 2^d - 1`.
* (C6) If `storage_min` is not empty:
* If `is_signed(storage_type)`, `storage_min >= -2^(d-1)`.
* If `is_unsigned(storage_type)`, `storage_min >= 0`.
* (C7) If `storage_max` is not empty:
* If `is_signed(storage_type)`, `storage_max <= 2^(d-1)-1`
* If `is_unsigned(storage_type)`, `storage_max <= 2^d - 1`.
* (C8) `storage_max - storage_min > 0`.
* (C9) For all `i`, `type(scales[i]) = expressed_type`.
* (C10) For all `i`, `scales[i] > 0`.
* (C11) For all `i`, `storage_min <= zero_points[i] <= storage_max`.
* (C12) For all `i`, `type(zero_points[i]) = storage_type`.
* (C13) `size(scales) = size(zero_points)`.
* (C14) If `quantization_dimension` is empty, then `size(scales) = 1`.
* (C15) If `quantization_dimension` is not empty, then
* (C4) `storage_min >= min_value(storage_type)`.
* (C5) `storage_max <= max_value(storage_type)`.
* (C6) `storage_max - storage_min > 0`.
* (C7) For all `i`, `type(scales[i]) = expressed_type`.
* (C8) For all `i`, `scales[i] > 0`.
* (C9) For all `i`, `storage_min <= zero_points[i] <= storage_max`.
* (C10) For all `i`, `type(zero_points[i]) = storage_type`.
* (C11) `size(scales) = size(zero_points)`.
* (C12) If `quantization_dimension` is empty, then `size(scales) = 1`.
* (C13) If `quantization_dimension` is not empty, then
`0 <= quantization_dimension`.

Furthermore, tensors of quantized types satisfy the following constraints:

* For per-tensor quantization:
* No additional constraints.
* For per-axis quantization:
* (C16) `quantization_dimension < size(shape)`.
* (C17) `size(scales) = shape[quantization_dimension]`.
* (C14) `quantization_dimension < size(shape)`.
* (C15) `size(scales) = shape[quantization_dimension]`.

```ebnf
FunctionType ::= '(' [ValueType {',' ValueType}] ')' '->' '(' [ValueType {',' ValueType}] ')'
Expand Down

0 comments on commit e74d3cf

Please sign in to comment.