sandeep-krishnamurthy edited a comment on issue #11849: gluon.SymbolBlock 
cannot imports resnet trained with dtype="float16"
URL: 
https://github.com/apache/incubator-mxnet/issues/11849#issuecomment-417124700
 
 
   Using below snippet:
   ```
   import mxnet as mx
   
   ctx = mx.cpu(0)
   data = mx.nd.zeros((1,3,224,224), ctx=ctx, dtype='float64')
   net_fp32 = mx.gluon.model_zoo.vision.resnet34_v2(pretrained=True, ctx=ctx)
   net_fp32.cast('float64')
   net_fp32.hybridize()
   pred = net_fp32.forward(data)
   net_fp32.export('resnet34_fp16', 0)
   print('export fp16 model')
   
   sm = mx.sym.load('resnet34_fp16-symbol.json')
   inputs = mx.sym.var('data', dtype='float64')
   net_fp16 = mx.gluon.SymbolBlock(sm, inputs)
   net_fp16.collect_params().load('resnet34_fp16-0000.params', ctx)
   pred = net_fp16.forward(data)
   ```
   
   Below are my findings:
   1. Casting worked fine.
   2. Saved parameters are in the correct format (fp64 in my sample code)
   3. sym.load worked fine. If I infer symbol's type 
(sym.infer_type(data='float64') I get correct inferred type (float64) for all 
params.
   
   Below is the issue:
   1. When you create mx.gluon.SymbolBlock(sm, input). It creates the 
parameters in the Block. Type is not passed for creating the parameter.
   See here - 
https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/gluon/block.py#L1058
 and the behavior is "If there is not parameter to get, it creates one and uses 
default type (fp32) 
https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/gluon/parameter.py#L688
   
   I am working on the fix.
   
   @apeforest @ThomasDelteil  - FYI

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to