Skip to content
Merged
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 references/classification/train_quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def main(args):
print("Creating model", args.model)
# when training quantized models, we always start from a pre-trained fp32 reference model
model = torchvision.models.quantization.__dict__[args.model](pretrained=True, quantize=args.test_only)
model.to(device)

if not (args.test_only or args.post_training_quantize):
model.fuse_model()
Expand All @@ -66,6 +65,8 @@ def main(args):
step_size=args.lr_step_size,
gamma=args.lr_gamma)

model.to(device)

criterion = nn.CrossEntropyLoss()
model_without_ddp = model
if args.distributed:
Expand Down Expand Up @@ -129,7 +130,7 @@ def main(args):
print('Evaluate QAT model')

evaluate(model, criterion, data_loader_test, device=device)
quantized_eval_model = copy.deepcopy(model)
quantized_eval_model = copy.deepcopy(model_without_ddp)
quantized_eval_model.eval()
quantized_eval_model.to(torch.device('cpu'))
torch.quantization.convert(quantized_eval_model, inplace=True)
Expand Down