Hsyshasuzh's picture
download
raw
1.14 kB
import unittest
import torch
from training.detection_trainer import freeze_detector_backbone,DetectorTrainConfig
class HeadOnlyTests(unittest.TestCase):
def test_only_head_parameters_receive_updates(self):
class Detector(torch.nn.Module):
def __init__(self):
super().__init__();self.model=torch.nn.ModuleList([torch.nn.Linear(3,4),torch.nn.Linear(4,2)])
def forward(self,x):return self.model[1](self.model[0](x))
model=Detector();before={n:p.detach().clone() for n,p in model.named_parameters()}
freeze_detector_backbone(model)
optimizer=torch.optim.AdamW((p for p in model.parameters() if p.requires_grad),lr=.01)
model(torch.ones(2,3)).square().sum().backward();optimizer.step()
self.assertTrue(all(torch.equal(p,before[n]) for n,p in model.named_parameters() if n.startswith('model.0.')))
self.assertTrue(any(not torch.equal(p,before[n]) for n,p in model.named_parameters() if n.startswith('model.1.')))
def test_freeze_flag_rejects_non_boolean(self):
with self.assertRaises(ValueError):DetectorTrainConfig(freeze_backbone=1)

Xet Storage Details

Size:
1.14 kB
·
Xet hash:
ee729fc0787e68ea35eea18a438b29720001d64143cd4e5b16e7022c0fca1169

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.