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 initializes 
parameters in the Block. By default, this uses Float32.
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

[ Full content available at: 
https://github.com/apache/incubator-mxnet/issues/11849 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to