The problem is solved.But I am still a little confused.The way I uesd before is:
#convert to pytorch tensor
train_data = torch.from_numpy(train_data)
train_label = torch.from_numpy(train_label)
val_data = torch.from_numpy(valid_data)
val_label = torch.from_numpy(valid_label)

After reading your words, I changed to these:
#convert to pytorch tensor
train_data = torch.from_numpy(train_data)..type(torch.FloatTensor)
train_label = torch.from_numpy(train_label).type(torch.LongTensor)
val_data = torch.from_numpy(valid_data).type(torch.FloatTensor)
val_label = torch.from_numpy(valid_label).type(torch.LongTensor)

The problem is solved.But The error info is RuntimeError: expected Long tensor (got Float tensor).Should it be RuntimeError: expected Float tensor (got Long tensor)
This is so weired that I can not understand.What is the reason of it?