Why am I getting this error

循环训练、测试

torch.manual_seed(42)

torch.cuda.manual_seed(42)

#循环次数
epochs = 100

将数据发送至设备

X_blob_train,X_blob_test = X_blob_train.to(device),X_blob_test.to(device)
y_blob_train,y_blob_test = y_blob_train.to(device),y_blob_test.to(device)

循环

for epoch in range(epochs):
# 训练
model_4.train()

# 概率
y_logits = model_4(X_blob_train)
y_pred = torch.softmax(y_logits,dim=1).argmax(dim=1)

# 计算损失(交叉熵)(X为训练,y为测试)    
loss = loss_fn(y_pred,y_blob_test)
# 准确性
acc = acccracy_fn(y_true=y_blob_train,y_pred=y_pred)

# 优化器清零
optimizer.zero_grad()

# 反向传播
loss.backward()

# 梯度停止
optimizer.step()

### 测试
model_4.eval()
with torch.inference_mode():
    test_logits = model_4(X_blob_test)
    test_pred = torch.softmax(test_logits,dim=0).argmax(dim=1)  # 预测出最大值的索引值
    
    test_loss = loss_fn(test_logits,test_pred)
    test_acc = acccracy_fn(y_true=y_blob_test,y_pred=test_pred) 
    
    
if epoch % 10 == 0:      
    print(f"Epoch:{epoch} | Loss:{loss:.5f},Acc:{acc:.2f}%, Test_Loss:{test_loss:.5f},Test_Acc:{test_acc:2f}%")

TypeError Traceback (most recent call last) Cell In[70], line 19 17 # 概率 18 y_logits = model_4(X_blob_train) —> 19 y_pred = torch.softmax(y_logits,dim=1).argmax(dim=1) 21 # 计算损失(交叉熵)(X为训练,y为测试) 22 loss = loss_fn(y_pred,y_blob_test) TypeError: softmax() received an invalid combination of arguments - got (NoneType, dim=int), but expected one of: * (Tensor input, int dim, torch.dtype dtype, *, Tensor out) * (Tensor input, name dim, *, torch.dtype dtype)

Your model doesn’t se to return anything. Its output is thus None.

I need it to output what should be done

Add a return statement to the forward method of your model.