Batch size mismatch problem when using cunn

criterion = nn.CrossEntropyLoss().cuda()
optimizer = optim.SGD(model.parameters(), lr=0.1, momentum=.9, nesterov = True,weight_decay=5e-4)

modelp=torch.nn.DataParallel(model, device_ids=[0,1,2]).cuda()
modelp = train_model(modelp, criterion, optimizer,num_epochs=1)

batch_size=5

RuntimeError: invalid argument 2: mismatch between the batch size of input (500) and that of target (5) at /opt/conda/conda-bld/pytorch_1503970438496/work/torch/lib/THCUNN/generic/ClassNLLCriterion.cu:41

to your criterion, you are giving an input of size 500 x something, while target is of size 5.
See why your output is not what you expect it to be.

aready solved…thankyou :slight_smile: