How to change the module from order dict to Module dict

I want to know how to change the model modules from storing them in Orderdict to Moduledict.
I want to know how to convert the model if it is already in Orderdict.

Thanks

I tried to do that

for k,val in model.state_dict().items():
torch.nn.ModuleDict(OrderedDict({key:val}))

error → torch.FloatTensor is not a Module subclass

The state_dict will return the parameters and buffers, so you could try to use an nn.ParameterDict.
nn.ModuleDict is for nn.Modules and works fine:

# plain dict
d = {'a': nn.Linear(1, 1),
     'b': nn.Linear(2, 2)}
m = nn.ModuleDict(d)
print(m)

# OrderedDict
d = {'a': nn.Linear(3, 3),
     'b': nn.Linear(4, 4)}
o = OrderedDict(d)
print(o)
m = nn.ModuleDict(o)
print(m)

It works perfectly, thank u!