File tree Expand file tree Collapse file tree
transformer_engine/plugin/core/backends/vendor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -166,6 +166,17 @@ def quantize(
166166 noop : Optional [torch .Tensor ] = None ,
167167 ) -> Any :
168168 tex = self ._get_tex ()
169+ # Quantizer.dtype may originate from a different TE extension module
170+ # (e.g. transformer_engine_torch vs transformer_engine_torch_nv) which leads
171+ # to a pybind enum cast failure. Normalize it to this backend's `tex.DType`.
172+ try :
173+ if quantizer is not None and hasattr (quantizer , "dtype" ) and hasattr (tex , "DType" ):
174+ qdtype = quantizer .dtype
175+ if qdtype is not None :
176+ quantizer .dtype = tex .DType (int (qdtype ))
177+ except Exception :
178+ pass
179+
169180 return tex .quantize (tensor , quantizer , output , noop )
170181
171182 def dequantize (
Original file line number Diff line number Diff line change @@ -145,6 +145,14 @@ def quantize(
145145 noop : Optional [torch .Tensor ] = None ,
146146 ) -> Any :
147147 tex = self ._get_tex ()
148+ try :
149+ if quantizer is not None and hasattr (quantizer , "dtype" ) and hasattr (tex , "DType" ):
150+ qdtype = quantizer .dtype
151+ if qdtype is not None :
152+ if qdtype .__class__ is not tex .DType :
153+ quantizer .dtype = tex .DType (int (qdtype ))
154+ except Exception :
155+ pass
148156 return tex .quantize (tensor , quantizer , output , noop )
149157
150158 def dequantize (
Original file line number Diff line number Diff line change @@ -171,6 +171,14 @@ def quantize(
171171 noop : Optional [torch .Tensor ] = None ,
172172 ) -> Any :
173173 tex = self ._get_tex ()
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+ if qdtype .__class__ is not tex .DType :
179+ quantizer .dtype = tex .DType (int (qdtype ))
180+ except Exception :
181+ pass
174182 return tex .quantize (tensor , quantizer , output , noop )
175183
176184 def dequantize (
Original file line number Diff line number Diff line change @@ -126,6 +126,14 @@ def quantize(
126126 noop : Optional [torch .Tensor ] = None ,
127127 ) -> Any :
128128 tex = self ._get_tex ()
129+ try :
130+ if quantizer is not None and hasattr (quantizer , "dtype" ) and hasattr (tex , "DType" ):
131+ qdtype = quantizer .dtype
132+ if qdtype is not None :
133+ if qdtype .__class__ is not tex .DType :
134+ quantizer .dtype = tex .DType (int (qdtype ))
135+ except Exception :
136+ pass
129137 return tex .quantize (tensor , quantizer , output , noop )
130138
131139 def dequantize (
Original file line number Diff line number Diff line change @@ -138,6 +138,14 @@ def quantize(
138138 noop : Optional [torch .Tensor ] = None ,
139139 ) -> Any :
140140 tex = self ._get_tex ()
141+ try :
142+ if quantizer is not None and hasattr (quantizer , "dtype" ) and hasattr (tex , "DType" ):
143+ qdtype = quantizer .dtype
144+ if qdtype is not None :
145+ if qdtype .__class__ is not tex .DType :
146+ quantizer .dtype = tex .DType (int (qdtype ))
147+ except Exception :
148+ pass
141149 return tex .quantize (tensor , quantizer , output , noop )
142150
143151 def dequantize (
You can’t perform that action at this time.
0 commit comments