RuntimeError: multi-target not supported at /pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu:15____
I face that error
RuntimeError: multi-target not supported at /pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu:15____
My input is binary vector of 340, target is binary vector of 8, For '&quot;
loss = criterion(outputs, stat_batch), I got outputs.shape= [64,8] and stat_batch.shape=[64,8]
Here is the model
class MMP(nn.Module):

    def __init__(self, M=1):
        super(MMP, self).__init__()
        # input layer
        self.layer1 = nn.Sequential(
            nn.Conv1d(340, 256,  kernel_size=1, stride=1, padding=0),
            nn.ReLU())
        self.layer2 = nn.Sequential(
            nn.Conv1d(256, 128, kernel_size=1, stride=1, padding=0),
            nn.ReLU())
        self.layer3 = nn.Sequential(
            nn.Conv1d(128, 64, kernel_size=1, stride=1, padding=0),
            nn.ReLU())
        self.drop1 = nn.Sequential(nn.Dropout())
        self.batch1 = nn.BatchNorm1d(128)
        # LSTM
        self.lstm1=nn.Sequential(nn.LSTM(
        input_size=64,
        hidden_size=128,
        num_layers=2,
        bidirectional=True,
        batch_first= True))
        self.fc1 = nn.Linear(128*2,8)
        self.sof = nn.Softmax(dim=-1)

    def forward(self, x):
        out = self.layer1(x)
        out = self.layer2(out)
        out = self.layer3(out)
        out = self.drop1(out)
        out = out.squeeze()
        out = out.unsqueeze(0)
        #out = out.batch1(out)
        out,_ = self.lstm1(out)
        print(&quot;lstm&quot;,out.shape)
        out = self.fc1(out)
        out =out.squeeze()
        #out = out.squeeze()
        out = self.sof(out)
        return out

#traiin_model
criterion = nn.CrossEntropyLoss()
if CUDA:
    criterion = criterion.cuda()
optimizer = optim.SGD(model.parameters(), lr=LEARNING_RATE, momentum=0.9)

for epoch in range(N_EPOCHES):
    tot_loss=0
    # Training
    for i, (seq_batch, stat_batch) in enumerate(training_generator):
        # Transfer to GPU
        seq_batch, stat_batch = seq_batch.to(device), stat_batch.to(device)
        print(i)
        print(seq_batch)
        print(stat_batch)
        optimizer.zero_grad()
        # Model computation
        seq_batch = seq_batch.unsqueeze(-1)
        outputs = model(seq_batch)
        if CUDA:
            loss = criterion(outputs, stat_batch).float().cuda()
        else:
            loss = criterion(outputs.view(-1), stat_batch.view(-1))
        print(f&quot;Epoch: {epoch},number: {i}, loss:{loss.item()}...\n\n&quot;)

        tot_loss += loss.item(print(f&quot;Epoch: {epoch},file_number: {i}, loss:{loss.item()}...\n\n&quot;))
        loss.backward()
        optimizer.step()


Your target stat_batch must have a shape of (64,) because nn.CrossEntropyLoss takes in class indices, not one-hot-encoding.
Either construct your label tensor appropriately or use stat_batch.argmax(axis=1) instead.
