Skip to content

Commit

Permalink
[BUG] Fix bug in cast in quantization (#480)
Browse files Browse the repository at this point in the history
[BUG] Fix bug in `cast` in quantization
  • Loading branch information
vadiklyutiy authored Dec 21, 2024
1 parent a0fff01 commit 04332b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 4 additions & 2 deletions python/hidet/graph/ops/quant/symmetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# limitations under the License.
from typing import Union, List
from hidet import ir
from hidet.ir.type import DataType
from hidet.ir.type import DataType, int32
from hidet.ir.expr import cast, if_then_else
from hidet.ir.compute.primitives import TensorNode, compute
from hidet.ir import primitives as prim
Expand All @@ -36,7 +36,9 @@ def __init__(self, w: TensorNode, quant_type: DataType, dims: Union[int, List[in

def scale_weight(*indices):
scale_indices = [indices[i] for i in range(len(indices)) if not i in dims]
return cast(prim.round(w[indices] / scale[scale_indices]), quant_type)
# Have to cast to int32 first because there are several ways convert bf16 to int8
cast_to_int = cast(prim.round(w[indices] / scale[scale_indices]), int32)
return cast(cast_to_int, quant_type)

wq = compute(name='quantize', shape=w.shape, fcompute=scale_weight)
super().__init__(
Expand Down
1 change: 0 additions & 1 deletion python/hidet/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "0.5.0"

0 comments on commit 04332b7

Please sign in to comment.