Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions vit_pytorch/distill.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def __init__(
super().__init__()
assert (isinstance(student, (DistillableViT, DistillableT2TViT, DistillableEfficientViT))) , 'student must be a vision transformer'

device = 'cuda' if torch.cuda.is_available() else 'cpu'
self.teacher = teacher
self.student = student

Expand All @@ -125,12 +126,12 @@ def __init__(
self.alpha = alpha
self.hard = hard

self.distillation_token = nn.Parameter(torch.randn(1, 1, dim))
self.distillation_token = nn.Parameter(torch.randn(1, 1, dim,device=device))

self.distill_mlp = nn.Sequential(
nn.LayerNorm(dim) if mlp_layernorm else nn.Identity(),
nn.Linear(dim, num_classes)
)
).to(device)

def forward(self, img, labels, temperature = None, alpha = None, **kwargs):

Expand Down