I think the NllLoss should be:
loss = 0.
for i, target_i in enumerate(target.long()):
	for j, target_j in enumerate(target_i):
		loss = loss - logp[i][target_j.item()][j]
print('My Loss', loss / (4*3*1))

high dim NLLLoss calcucation is abstract, but it’s always the same idea that selecting the value according to target in dim 1(starting from dim 0).
logsoftmax is implemented correct, and I can’t figure out a better way to implement NllLoss of arbitary dimension now.