no grad if frozen in forward pass

This commit is contained in:
YannAhlgrim
2026-04-25 11:00:14 +02:00
parent 417319457a
commit 02991a7eb5
+4
View File
@@ -13,6 +13,10 @@ class ViTClassifier(nn.Module):
def forward(self, x):
# ViT -> (B, N, D)
if any(p.requires_grad for p in self.encoder.parameters()):
features = self.encoder(x)
else:
with torch.no_grad():
features = self.encoder(x)
# Average Pool -> (B, D)