rongzha1 commented on a change in pull request #17265: Add bfloat16
floating-point format support based on AMP
URL: https://github.com/apache/incubator-mxnet/pull/17265#discussion_r368886511
##########
File path: python/mxnet/gluon/parameter.py
##########
@@ -289,11 +289,18 @@ def _load_init(self, data, ctx, cast_dtype=False,
dtype_source='current'):
elif dtype_source == 'saved':
self.dtype = data.dtype
else:
- assert np.dtype(self.dtype).type == data.dtype, \
- "Failed loading Parameter '%s' from saved params: " \
- "dtype incompatible expected %s vs saved %s. " \
- "Set cast_dtype=True to cast the dtype of saved params."%(
- self.name, str(self.dtype), str(data.dtype))
+ if data.dtype == np.dtype([('bfloat16', np.uint16)]):
+ assert np.dtype(self.dtype) == data.dtype, \
+ "Failed loading Parameter '%s' from saved params: " \
+ "dtype incompatible expected %s vs saved %s. " \
+ "Set cast_dtype=True to cast the dtype of saved params."%(
+ self.name, str(self.dtype), str(data.dtype))
+ else:
+ assert np.dtype(self.dtype).type == data.dtype, \
+ "Failed loading Parameter '%s' from saved params: " \
+ "dtype incompatible expected %s vs saved %s. " \
+ "Set cast_dtype=True to cast the dtype of saved params."%(
+ self.name, str(self.dtype), str(data.dtype))
Review comment:
np.dtype(self.dtype) is different from np.dtype(self.dtype).type
https://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.type.html
https://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html#numpy.dtype
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services