MCPcopy Create free account
hub / github.com/apache/tvm / dequantize

Method dequantize

tests/python/relax/backend/adreno/mod_utils.py:752–781  ·  view source on GitHub ↗
(weight: T.handle, scale: T.handle, var_dequantize: T.handle)

Source from the content-addressed store, hash-verified

750
751 @T.prim_func(s_tir=True)
752 def dequantize(weight: T.handle, scale: T.handle, var_dequantize: T.handle):
753 T.func_attr({"tirx.noalias": T.bool(True)})
754 lm_head_q_weight1 = T.match_buffer(weight, (T.int64(K // 8), T.int64(N)), "uint32")
755 lm_head_q_scale1 = T.match_buffer(scale, (T.int64(K // 32), T.int64(N)), "float16")
756 dequantize = T.match_buffer(var_dequantize, (T.int64(K), T.int64(N)), "float16")
757 # with T.sblock("root"):
758 compute = T.alloc_buffer((T.int64(K), T.int64(N)), "float16")
759 for i0, i1 in T.grid(T.int64(K), T.int64(N)):
760 with T.sblock("compute"):
761 v_i0, v_i1 = T.axis.remap("SS", [i0, i1])
762 T.reads(lm_head_q_weight1[v_i0 // T.int64(8), v_i1])
763 T.writes(compute[v_i0, v_i1])
764 compute[v_i0, v_i1] = T.Cast(
765 "float16",
766 T.bitwise_and(
767 T.shift_right(
768 lm_head_q_weight1[v_i0 // T.int64(8), v_i1],
769 T.Cast("uint32", v_i0 % T.int64(8) * T.int64(4)),
770 ),
771 T.uint32(15),
772 ),
773 )
774 for i0, i1 in T.grid(T.int64(K), T.int64(N)):
775 with T.sblock("dequantize"):
776 v_i0, v_i1 = T.axis.remap("SS", [i0, i1])
777 T.reads(compute[v_i0, v_i1], lm_head_q_scale1[v_i0 // T.int64(32), v_i1])
778 T.writes(dequantize[v_i0, v_i1])
779 dequantize[v_i0, v_i1] = (
780 compute[v_i0, v_i1] - T.float16(7.0)
781 ) * lm_head_q_scale1[v_i0 // T.int64(32), v_i1]
782
783 return DequantMatmul
784

Calls 1

remapMethod · 0.80