target_var should be a Variable wrapping a 1-D tensor of size n_batch. Each element t of target_var should be in [0, num_classes). If it isn’t, the assertion that you’re seeing is triggered.
One thing you can do to debug this is insert the following before your criterion call (pseudocode):
if torch.sum( (target_var.data >= num_classes).long() + (target_var.data < 0).long()) > 0:
    import pdb; pdb.set_trace()