Update distill.py to include device agnostic code for distill_mlp
head and distillation_token
#324
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.
Since in your code, the
distillation_token
anddistill_mlp
heads are defined in theDistillWrapper
class, sending the model instance of theDistillableViT
class to GPU does not send thedistillation_token
anddistill_mlp
head to GPU. Therefore, while training a model using this code, I got a device mismatch error, which made it hard to figure out the source of the error. Finally, thedistillation_token
anddistill_mlp
turned out to be the culprits as they are not defined in the model class but in theDistillWrapper
class, which is a wrapper of loss function. Therefore, I have suggested the following changes when training a model on GPU: the training code should set thedevice="cude" if torch.cuda.is_available() else "cpu"
, or the same can be incorporated into the constructor of theDistillWrapper
class.