Skip to content

Commit 597d757

Browse files
committed
fix bgrad_quantizer
1 parent 36129d6 commit 597d757

5 files changed

Lines changed: 50 additions & 0 deletions

File tree

transformer_engine/plugin/core/backends/vendor/cuda/cuda.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ def bgrad_quantize(
192192
quantizer: Any,
193193
) -> List[Any]:
194194
tex = self._get_tex()
195+
196+
# Normalize quantizer.dtype to this backend's `tex.DType`.
197+
try:
198+
if quantizer is not None and hasattr(quantizer, "dtype") and hasattr(tex, "DType"):
199+
qdtype = quantizer.dtype
200+
if qdtype is not None:
201+
quantizer.dtype = tex.DType(int(qdtype))
202+
except Exception:
203+
pass
204+
195205
return tex.bgrad_quantize(input, quantizer)
196206

197207
def generic_gemm(

transformer_engine/plugin/core/backends/vendor/hygon/hygon.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ def bgrad_quantize(
169169
quantizer: Any,
170170
) -> List[Any]:
171171
tex = self._get_tex()
172+
173+
# Normalize quantizer.dtype to this backend's `tex.DType`.
174+
try:
175+
if quantizer is not None and hasattr(quantizer, "dtype") and hasattr(tex, "DType"):
176+
qdtype = quantizer.dtype
177+
if qdtype is not None:
178+
quantizer.dtype = tex.DType(int(qdtype))
179+
except Exception:
180+
pass
181+
172182
return tex.bgrad_quantize(input, quantizer)
173183

174184
def generic_gemm(

transformer_engine/plugin/core/backends/vendor/iluvatar/iluvatar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ def bgrad_quantize(
195195
quantizer: Any,
196196
) -> List[Any]:
197197
tex = self._get_tex()
198+
199+
# Normalize quantizer.dtype to this backend's `tex.DType`.
200+
try:
201+
if quantizer is not None and hasattr(quantizer, "dtype") and hasattr(tex, "DType"):
202+
qdtype = quantizer.dtype
203+
if qdtype is not None:
204+
quantizer.dtype = tex.DType(int(qdtype))
205+
except Exception:
206+
pass
207+
198208
return tex.bgrad_quantize(input, quantizer)
199209

200210
def generic_gemm(

transformer_engine/plugin/core/backends/vendor/metax/metax.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ def bgrad_quantize(
150150
quantizer: Any,
151151
) -> List[Any]:
152152
tex = self._get_tex()
153+
154+
# Normalize quantizer.dtype to this backend's `tex.DType`.
155+
try:
156+
if quantizer is not None and hasattr(quantizer, "dtype") and hasattr(tex, "DType"):
157+
qdtype = quantizer.dtype
158+
if qdtype is not None:
159+
quantizer.dtype = tex.DType(int(qdtype))
160+
except Exception:
161+
pass
162+
153163
return tex.bgrad_quantize(input, quantizer)
154164

155165
def generic_gemm(

transformer_engine/plugin/core/backends/vendor/musa/musa.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ def bgrad_quantize(
162162
quantizer: Any,
163163
) -> List[Any]:
164164
tex = self._get_tex()
165+
166+
# Normalize quantizer.dtype to this backend's `tex.DType`.
167+
try:
168+
if quantizer is not None and hasattr(quantizer, "dtype") and hasattr(tex, "DType"):
169+
qdtype = quantizer.dtype
170+
if qdtype is not None:
171+
quantizer.dtype = tex.DType(int(qdtype))
172+
except Exception:
173+
pass
174+
165175
return tex.bgrad_quantize(input, quantizer)
166176

167177
def generic_gemm(

0 commit comments

Comments
 (0)