Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about distill_loss #289

Open
haoren55555 opened this issue Nov 11, 2023 · 3 comments
Open

Questions about distill_loss #289

haoren55555 opened this issue Nov 11, 2023 · 3 comments

Comments

@haoren55555
Copy link

sorry to bother, I see the distill_loss in distill.py as :
distill_loss = F.kl_div(
F.log_softmax(distill_logits / T, dim=-1),
F.softmax(teacher_logits / T, dim=-1).detach(),
reduction='batchmean')
I wonder why the teacher part uses the softmax function rather than log_softmax one, thanks.

@lucidrains
Copy link
Owner

@haoren55555 yeah, you could do log softmax for teacher too by setting log_target = True https://pytorch.org/docs/stable/generated/torch.nn.KLDivLoss.html . i'm just rolling with what pytorch offers

@vivekh2000
Copy link

vivekh2000 commented Jun 8, 2024

That was insightful. However, in your implementation of class DistillMixin, you are passing the cls token from the MLP lead.

The MLP head of the distillation token is implemented using LayerNorm, whereas the cls token MLP head is implemented in vit.py without LayerNorm. Why is it so? What am I missing? Please correct me if I am wrong.
image

image

image

@vivekh2000
Copy link

@lucidrains
I have also noticed that in the paper, the authors mentioned that at test time, they fused the two heads, i.e., MLP heads for cls token and distilled token.

for which we add the softmax output by the two classifiers to make the prediction. (p.8, paragraph 3)

This fusion of two heads is not implemented in the forward method of the DistillMixin class. Please let me know if it is implemented elsewhere or if I am missing something. Thanks for the excellent codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants