PARL
PARL copied to clipboard
[dygraph] set weights with wrong params shape should report an error
When loading parameters, paddle2.0 will skip the parameters of the wrong shape and just throw a warning. PARL will add patchs to prevent this kind of situation and report an error
Please note that this patch should be removed after paddle2.0 fixed it.
pip install paddlepaddle==2.0.0rc0
import numpy as np
import paddle
import paddle.nn as nn
import paddle.optimizer as opt
class LinearNet(nn.Layer):
def __init__(self):
super(LinearNet, self).__init__()
self.fc1 = nn.Linear(4, 3)
self.fc2 = nn.Linear(3, 2)
def forward(self, x):
out = self.fc1(x)
out = self.fc2(out)
return out
mylayer = LinearNet()
print(mylayer)
params = mylayer.state_dict()
print(params)
print('------------')
params['fc1.weight'] = params['fc1.bias'] # wrong shape
params['fc2.bias'] += 1 # other param modified
mylayer.set_state_dict(params)
params = mylayer.state_dict()
print(params)
print('------------')