You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PaddleSpeech/Linear_test.py

11 lines
596 B

import paddle,torch,numpy
torch_linear = torch.load("q.pt").cpu()
paddle_linear_state = paddle.load("q.pdparams")
paddle_linear = paddle.nn.Linear(896,896,bias_attr=True)
hidden_states = paddle.load("hidden_states.pdparams")
paddle_linear.set_state_dict(paddle_linear_state)
torch_forward_res = torch_linear(torch.tensor(hidden_states.numpy()))
paddle_forward_res = paddle_linear(hidden_states)
print("torch_forward_res:",torch_forward_res)
print("paddle_forward_res:",paddle_forward_res)
print('allclose_res:',numpy.testing.assert_allclose(torch_forward_res.detach().numpy(),paddle_forward_res))