sxjscience commented on issue #19472:
URL: 
https://github.com/apache/incubator-mxnet/issues/19472#issuecomment-721883569


   Removed the amp-related code:
   
   ```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_fp16 = BartModel.from_cfg(cfg)
       model_fp16.share_parameters(model.collect_params())
       model_fp16.cast('float16')
       model_fp16.hybridize()
       model_fp16(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]

Reply via email to