There is no problem when I run only the neural network part,but when i train it ,i meet the problem

class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv1d(in_channels=1, out_channels=10, kernel_size=1)
        self.max_pool1 = nn.MaxPool1d(kernel_size=1, stride=1)
        self.conv2 = nn.Conv1d(10, 20, 1, 1)
        self.max_pool2 = nn.MaxPool1d(1, 1)
        self.conv3 = nn.Conv1d(20, 40, 1, 1)
        self.liner1 = nn.Linear(20*10, 120)
        self.liner2 = nn.Linear(120, 84)
        self.liner3 = nn.Linear(84, 1)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        x = self.max_pool1(x)
        x = F.relu(self.conv2(x))
        x = self.max_pool2(x)
        x = F.relu(self.conv3(x))

        x = x.view(-1, 20*10)
        x = F.relu(self.liner1(x))
        x = F.relu(self.liner2(x))
        x = self.liner3(x)
        x = torch.unsqueeze(x, dim=1)
        x = torch.unsqueeze(x, dim=1)

        return x

criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)
for epoch in range(10):
    running_loss = 0
    for input_data in x_train:
        i = 0
        label = -1.989e-12
        optimizer.zero_grad()

        outputs = net(input_data)
        loss = criterion(outputs, label)
        loss.backward()
        optimizer.step()

        running_loss += loss.item()
        i += 1
        if i % 2000 == 1999:
             print('[%d,%5d] loss : %3f' % (epoch + 1, i + 1, running_loss / 2000))
             running_loss = 0.0

i meet the problem about:IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 2),if someone have idea to solve the problem, please tell me, thank you

Your setup looks wrong regarding the used criterion, the model output, and the target.
nn.CrossEntropyLoss is used for a multi-class classification or segmentation use case. The model outputs should thus have the shape [batch_size, nb_classes, *] and the target [batch_size, *] containing class indices in the range [0, nb_classes-1] where the * denotes additional dimensions.
In your example the model is returning an output in the shape [batch_size, 1, 1, 1] which would only represent a single class so that your model would only “learn” to output class0 for all samples.
However, the target is initialized as a negative Python float, which has the wrong shape, the wrong type, and doesn’t represent a class index.
After fixing this by using nn.MSELoss, the code works fine, so feel free to update your code with a minimal and executable code snippet which reproduces the error.

Thank you for your reply.My neural network is for regression prediction, so am I using the wrong loss function?

Yes, nn.CrossEntropyLoss is used for a multi-class classification or segmentation use case as mentioned before and will raise the expected error.
For a regression use case you might want to use e.g. nn.MSELoss.