I want to update the classifier’s weights twice with the two outputs of the classifier.
To update, I wrote a code.
But, the code gives me the error that ’ enable anomaly detection to find the operation that failed to compute its gradient,’
I saw the answer that this code works with the previous version of pytorch. But it seems weird.
Can you tell me where I should fix it?
I don’t want to backward with (foreProb + backProb).backward()
foreData = data * mask
backData = data * (1-mask)

foreOutput = myClassifier(foreData)
backOutput = myClassifier(backData)                

foreProb = nn.CrossEntropyLoss(foreOutput, target)
backProb = nn.CrossEntropyLoss(backOutput, target)

self.optimizer['classifier'].zero_grad()
foreProb.backward()
self.optimizer['classifier'].step()
                
self.optimizer['classifier'].zero_grad()
backProb.backward()
self.optimizer['classifier'].step()