Help: cannot pickle 'weakref' object

I tried to set spawn mode in the beginning of my program by

    torch.multiprocessing.set_start_method('spawn')

But when I ran my program, there came an error about ’ cannot pickle ‘weakref’ object’. And it arose at the place where I tried to start multiprocessing function. I thought maybe because the function or args I sent to multiprocessing can’t be pickled. But how can I solve this problem. Thanks!