def test_onnx_quantize_acc(cfg, rec_val, batch_size=1, original=False):
    qconfig = qtz.qconfig(
        skip_conv_layers=[0],
        skip_dense_layer=False,
        nbit_input=cfg.nbit_input,
        nbit_weight=cfg.nbit_input,
        dtype_input=cfg.dtype_input,
        dtype_weight=cfg.dtype_input,
        dtype_activation=cfg.dtype_output,
        debug_enabled_ops=None,
        calibrate_mode="percentile",
        calibrate_chunk_by=8,
    )

    dataset = list(calibrate_dataset(cfg.model, rec_val, batch_size, 64))
    model, logfile = get_onnx_model(cfg.model,
                                    batch_size,
                                    qconfig,
                                    tvm.target.cuda(),
                                    original=original,
                                    dataset=dataset)
    val_data, batch_fn = get_val_data(cfg.model,
                                      rec_val=rec_val,
                                      batch_size=batch_size)

    with tvm.autotvm.apply_history_best(logfile):
        acc = eval_acc(model, val_data, batch_fn, log_interval=1000)
    assert acc > cfg.expected_acc
    return acc
def calibrate_dataset(model_name, rec_val, batch_size, calibration_samples):
    val_data, _ = get_val_data(model_name, rec_val=rec_val, batch_size=batch_size)
    val_data.reset()
    for i, batch in enumerate(val_data):
        if i * batch_size >= calibration_samples:
            break
        data = batch.data[0].asnumpy()
        yield {"data": data}