Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
fix tests for new overrides functionality (#302)
Browse files Browse the repository at this point in the history
* fix tests for new overrides functionality

* fix
  • Loading branch information
epwalsh authored Sep 21, 2021
1 parent 25e2b1a commit c57b931
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
) -> None:
super().__init__()

overrides = {"model": {"contextualizer": {"return_all_layers": True}}}
overrides = {"model.contextualizer.return_all_layers": True}

# Import here to avoid circular dependency.
from allennlp.models.archival import load_archive
Expand Down
11 changes: 5 additions & 6 deletions tests/generation/models/composed_seq2seq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,23 @@ def test_bidirectional_model_can_train_save_and_load(self):

param_overrides = json.dumps(
{
"model": {
"encoder": {"bidirectional": True},
"decoder": {"decoder_net": {"decoding_dim": 20, "bidirectional_input": True}},
}
"model.encoder.bidirectional": True,
"model.decoder.decoder_net.decoding_dim": 20,
"model.decoder.decoder_net.bidirectional_input": True,
}
)
self.ensure_model_can_train_save_and_load(
self.param_file, tolerance=1e-2, overrides=param_overrides
)

def test_no_attention_model_can_train_save_and_load(self):
param_overrides = json.dumps({"model": {"decoder": {"decoder_net": {"attention": None}}}})
param_overrides = json.dumps({"model.decoder.decoder_net.attention": None})
self.ensure_model_can_train_save_and_load(
self.param_file, tolerance=1e-2, overrides=param_overrides
)

def test_greedy_model_can_train_save_and_load(self):
param_overrides = json.dumps({"model": {"decoder": {"beam_search": {"beam_size": 1}}}})
param_overrides = json.dumps({"model.decoder.beam_search.beam_size": 1})
self.ensure_model_can_train_save_and_load(
self.param_file, tolerance=1e-2, overrides=param_overrides
)
Expand Down
8 changes: 4 additions & 4 deletions tests/generation/models/simple_seq2seq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ def test_model_can_train_with_amp(self):
)

def test_bidirectional_model_can_train_save_and_load(self):
param_overrides = json.dumps({"model": {"encoder": {"bidirectional": True}}})
param_overrides = json.dumps({"model.encoder.bidirectional": True})
self.ensure_model_can_train_save_and_load(
self.param_file, tolerance=1e-2, overrides=param_overrides
)

def test_multi_layer_decoder_model_can_train_save_and_load(self):
param_overrides = json.dumps({"model": {"target_decoder_layers": 2}})
param_overrides = json.dumps({"model.target_decoder_layers": 2})
self.ensure_model_can_train_save_and_load(
self.param_file, tolerance=1e-2, overrides=param_overrides
)

def test_no_attention_model_can_train_save_and_load(self):
param_overrides = json.dumps({"model": {"attention": None}})
param_overrides = json.dumps({"model.attention": None})
self.ensure_model_can_train_save_and_load(
self.param_file, tolerance=1e-2, overrides=param_overrides
)

def test_greedy_model_can_train_save_and_load(self):
param_overrides = json.dumps({"model": {"beam_search": {"beam_size": 1}}})
param_overrides = json.dumps({"model.beam_search.beam_size": 1})
self.ensure_model_can_train_save_and_load(
self.param_file, tolerance=1e-2, overrides=param_overrides
)
Expand Down
2 changes: 1 addition & 1 deletion tests/vision/models/vilbert_ir_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_model_can_train_save_and_load_with_cache(self):
import tempfile

with tempfile.TemporaryDirectory(prefix=self.__class__.__name__) as d:
overrides = {"dataset_reader": {"feature_cache_dir": str(d)}}
overrides = {"dataset_reader.feature_cache_dir": str(d)}
import json

overrides = json.dumps(overrides)
Expand Down
2 changes: 1 addition & 1 deletion tests/vision/models/vilbert_nlvr2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_model_can_train_save_and_load_with_cache(self):
import tempfile

with tempfile.TemporaryDirectory(prefix=self.__class__.__name__) as d:
overrides = {"dataset_reader": {"feature_cache_dir": str(d)}}
overrides = {"dataset_reader.feature_cache_dir": str(d)}
import json

overrides = json.dumps(overrides)
Expand Down
2 changes: 1 addition & 1 deletion tests/vision/models/vilbert_vqa_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_model_can_train_save_and_load_with_cache(self):
import tempfile

with tempfile.TemporaryDirectory(prefix=self.__class__.__name__) as d:
overrides = {"dataset_reader": {"feature_cache_dir": str(d)}}
overrides = {"dataset_reader.feature_cache_dir": str(d)}
import json

overrides = json.dumps(overrides)
Expand Down
2 changes: 1 addition & 1 deletion tests/vision/models/visual_entailment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_model_can_train_save_and_load_with_cache(self):
import tempfile

with tempfile.TemporaryDirectory(prefix=self.__class__.__name__) as d:
overrides = {"dataset_reader": {"feature_cache_dir": str(d)}}
overrides = {"dataset_reader.feature_cache_dir": str(d)}
import json

overrides = json.dumps(overrides)
Expand Down

0 comments on commit c57b931

Please sign in to comment.