I have an already pretrained language model available in pytorch which I would like to export to onnx format so that i can use it in another framework.
However I am unable to do so.
The model is a language model available at https://www.salesforce.com/products/einstein/ai-research/the-wikitext-dependency-language-modeling-dataset/
here is the code i have used.
PRE_PATH = PATH/‘models’/‘wt103’
PRE_LM_PATH = PRE_PATH/‘fwd_wt103.h5’
model = torch.load(PRE_LM_PATH, map_location=lambda storage, loc: storage)
enc_wgts = to_np(model[‘0.encoder.weight’])
row_m = enc_wgts.mean(0)
the last line is resulting in the below error
AttributeError Traceback (most recent call last)
3 pytorch_model = PRE_LM_PATH
----> 4 torch.onnx.export(wgts,row_m,‘onnxmodel.onnx’)
~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/onnx/init.py in export(model, args, f, export_params, verbose, training)
73 only, so you will generally not need to set this to True.
—> 75 _export(model, args, f, export_params, verbose, training)
~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/onnx/init.py in _export(model, args, f, export_params, verbose, training)
106 # A basic sanity check: make sure the state_dict keys are the same
107 # before and after running the model. Fail fast!
–> 108 orig_state_dict_keys = model.state_dict().keys()
110 # By default, training=False, which is good because running a model in
AttributeError: ‘collections.OrderedDict’ object has no attribute ‘state_dict’