Skip to content

Commit

Permalink
add test for export_model (nyu-mll#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswan committed Jan 6, 2021
1 parent 9cfe644 commit 9a45712
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/proj/main/test_export_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import pytest
from transformers import BertPreTrainedModel, BertTokenizer, RobertaForMaskedLM, RobertaTokenizer

import jiant.utils.python.io as py_io
from jiant.proj.main.export_model import export_model


@pytest.mark.parametrize(
"model_type, model_class, tokenizer_class, hf_model_name",
[
("bert-base-cased", BertPreTrainedModel, BertTokenizer, "bert-base-cased"),
(
"roberta-med-small-1M-1",
RobertaForMaskedLM,
RobertaTokenizer,
"nyu-mll/roberta-med-small-1M-1",
),
],
)
def test_export_model(tmp_path, model_type, model_class, tokenizer_class, hf_model_name):
export_model(
model_type=model_type,
output_base_path=tmp_path,
model_class=model_class,
tokenizer_class=tokenizer_class,
hf_model_name=hf_model_name,
)
read_config = py_io.read_json(os.path.join(tmp_path, f"config.json"))
assert read_config["model_type"] == model_type
assert read_config["model_path"] == os.path.join(tmp_path, "model", f"{model_type}.p")
assert read_config["model_config_path"] == os.path.join(tmp_path, "model", f"{model_type}.json")
assert read_config["model_tokenizer_path"] == os.path.join(tmp_path, "tokenizer")

0 comments on commit 9a45712

Please sign in to comment.