This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
[bug fix] Torch Classifier agent should call self.backward(loss) #4270
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Patch description
The current torch classifier agent uses
loss.backward
instead ofself.backward(loss)
. A lot of optimizer behaviors depend on the backward function. While the backward function was ignored in the previous version.For example:
SafeFP16Optimizer
, the fp32 gradient will be zeros as no synchronizing flag is set. The model doesn't train.ParlAI/parlai/utils/fp16.py
Line 200 in 66c71e0
MemoryEfficientFP16Optimizer
the loss loss_scale multiplier is omitted. We should improve performance with this fix.ParlAI/parlai/utils/fp16.py
Line 521 in 66c71e0
Testing steps
Train any classifier agent. Verified with a classifier agent training with SafeFP16Optimizer.
In our case, we retrained a safety classifier and compared its performance with the model in the zoo.
FP32 matched the performance, and FP16 performance worse. The performance shifted a bit between the tasks, we are comparing the average class_notok__ f1, it is the validation metric used for all the trainings.