Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for export_model #1259

Merged
merged 3 commits into from
Jan 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")