コード例 #1
0
def main(arg_list=None):
    run_args, remaining_args = parse_args(arg_list)
    remaining_args += ["--checkpoint-dir", run_args.checkpoint_dir]

    # If no config is supplied, try to load the config that should have been saved with the ckpts.
    if "--config" not in remaining_args:
        config_path = find_checkpoint_config(run_args.checkpoint_dir)
        remaining_args += ["--config", config_path]

    bert_args = utils.parse_bert_args(remaining_args)
    if not run_args.no_logger_setup:
        setup_logger(logging.getLevelName('INFO'))

    # Force variable weights in inference mode - otherwise we can't override the model weights for
    # validating each new checkpoint.
    bert_args.variable_weights_inference = True
    # Required to allow squeezed models to fit.
    bert_args.max_copy_merge_size = 32000

    logger.info("Program Start")

    # `parse_bert_args` will suffix the user-supplied checkpoint path with the current date/time.
    # To avoid modifying core Bert code, we'll just remove the suffix (we don't need the created
    # config).
    shutil.rmtree(bert_args.checkpoint_dir)
    bert_args.checkpoint_dir = os.path.dirname(bert_args.checkpoint_dir)

    logger.info(
        f"Validating over checkpoints in directory {bert_args.checkpoint_dir}")
    return validate_checkpoints(run_args, utils.get_validation_args(bert_args))
コード例 #2
0
def test_run_inference_extract_result(monkeypatch, multiple_log_lines,
                                      correct_output, expectation):
    """Mock the output of the infer loop, and check the response against known-good values"""
    random.seed(1984)
    setup_logger(logging.getLevelName('INFO'))

    f1 = 100 * random.random()
    em = 100 * random.random()

    mock_func = partial(mock_infer_loop, f1, em, multiple_log_lines,
                        correct_output)
    monkeypatch.setattr(validation, "bert_infer_loop", mock_func)

    # Actual arguments passed in don't actually matter here as they're all passed straight down into run_infer_loop
    mock_args = [None] * 7

    with expectation:
        j = validation.run_inference_extract_result(*mock_args)
        assert j["F1"] == f1
        assert j["exact_match"] == em
コード例 #3
0
def main(arg_list=None):
    run_args, remaining_args = parse_args(arg_list)
    remaining_args += ["--checkpoint-dir", run_args.checkpoint_dir]

    bert_args = utils.parse_bert_args(remaining_args)
    print(bert_args)
    if not run_args.no_logger_setup:
        setup_logger(logging.getLevelName('INFO'))

    logger.info("Program Start")

    # `parse_bert_args` will suffix the user-supplied checkpoint path with the current date/time.
    # To avoid modifying core Bert code, we'll just remove the suffix (we don't need the created
    # config).
    shutil.rmtree(bert_args.checkpoint_dir)
    bert_args.checkpoint_dir = os.path.dirname(bert_args.checkpoint_dir)

    logger.info(
        f"Fine-Tuning over checkpoints in directory {bert_args.checkpoint_dir}"
    )
    finetune_checkpoints(run_args, bert_args)