microsoft / nni

An open source AutoML toolkit for automate machine learning lifecycle, including feature engineering, neural architecture search, model compression and hyper-parameter tuning.
https://nni.readthedocs.io
MIT License
14k stars 1.81k forks source link

如何获得QAT后的模型参数? #5673

Open kucher-web opened 1 year ago

kucher-web commented 1 year ago

Describe the issue: 在pytroch中,可以通过conv2d.weight的方式获得卷积层的权重值 请问,通过nni的QAT之后,应该如何获得再训练后的权重值?

quantizer = QAT_Quantizer(model, config_list, optimizer, dummy_input)
quantizer.compress()
for epoch in range(1, epochs + 1):
    train(model, device, train_loader, optimizer, epoch)
    scheduler.step()

通过model.conv1.module.weight,可以获得FP32的权重。

  1. 通过该方法获得的权重是否即为当前网络中用来计算output=model(input)的权重了?
  2. 如何获得量化为int8的权重值,是否只能通过model.conv1.module.weight_scale以及model.conv1.module.zero_point自己计算?
  3. 为什么在训练过程中,model.conv1.module.old_weight也会不停迭代?我以为这个属性是用来存放量化之前的权重的

Environment: