sxjscience commented on issue #19472:
URL:
https://github.com/apache/incubator-mxnet/issues/19472#issuecomment-721884922
In fact, directly casting the original model to float16 does not work also:
```python
import mxnet as mx
import numpy as np
mx.npx.set_np()
from gluonnlp.models.bart import BartModel
cfg = BartModel.get_cfg()
cfg.defrost()
cfg.MODEL.vocab_size = 32
cfg.freeze()
ctx = mx.gpu()
batch_size = 4
src_length = 32
tgt_length = 16
with ctx:
src_data = mx.np.random.randint(0, cfg.MODEL.vocab_size, (batch_size,
src_length),
dtype=np.int32)
src_valid_length = mx.np.random.randint(src_length // 2, src_length,
(batch_size,),
dtype=np.int32)
tgt_data = mx.np.random.randint(0, cfg.MODEL.vocab_size, (batch_size,
tgt_length),
dtype=np.int32)
tgt_valid_length = mx.np.random.randint(tgt_length // 2, tgt_length,
(batch_size, ),
dtype=np.int32)
model = BartModel.from_cfg(cfg)
model.initialize(ctx=ctx)
model.hybridize()
model(src_data, src_valid_length, tgt_data, tgt_valid_length)
mx.npx.waitall()
model.cast('float16')
model.hybridize()
model(src_data, src_valid_length, tgt_data, tgt_valid_length)
mx.npx.waitall()
```
----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]