examples/research_projects/quantization-qdqbert/trainer_quant_qa.py/QuestionAnsweringTrainer/calibrate
class QuestionAnsweringTrainer:    def calibrate(self, calib_dataset=None):
        calib_dataset = self.train_dataset if calib_dataset is None else calib_dataset
        calib_dataloader = self.get_calib_dataloader(calib_dataset)

        model = self.model
        quant_trainer.configure_model(model, self.quant_trainer_args, calib=True)
        model.eval()
        quant_trainer.enable_calibration(model)

        logger.info("***** Running calibration *****")
        logger.info(f"  Num examples = {self.calib_num}")
        logger.info(f"  Batch size = {calib_dataloader.batch_size}")

        for step, inputs in enumerate(calib_dataloader):
            # Prediction step
            loss, logits, labels = self.prediction_step(model, inputs, prediction_loss_only=True)
            if (step + 1) * calib_dataloader.batch_size >= self.calib_num:
                break

        quant_trainer.finish_calibration(model, self.quant_trainer_args)
        self.model = model