Thanks.
The example is a simplified code from my work. Changing tensor to numpy array can truly solve the problem above. Hope there is some way to work with pytorch in another thread.
I will try figure it out also.