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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into vision
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkgr committed Nov 4, 2020
2 parents b48347b + b4f1a7a commit 63f61f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ data loaders. Those are coming soon.

## Unreleased (1.x branch)

### Added

- Added an optional `seed` parameter to `ModelTestCase.set_up_model` which sets the random
seed for `random`, `numpy`, and `torch`.

### Fixed

- Fixed the computation of saliency maps in the Interpret code when using mismatched indexing.
Expand Down
16 changes: 14 additions & 2 deletions allennlp/common/testing/model_test_case.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import copy
import json
from os import PathLike
import random
from typing import Any, Dict, Iterable, Set, Union

import torch
import numpy
from numpy.testing import assert_allclose

from allennlp.commands.train import train_model_from_file
Expand All @@ -22,9 +24,19 @@ class ModelTestCase(AllenNlpTestCase):
with added methods for testing [`Model`](../../models/model.md) subclasses.
"""

def set_up_model(self, param_file, dataset_file, serialization_dir=None):
def set_up_model(
self,
param_file: PathLike,
dataset_file: PathLike,
serialization_dir: PathLike = None,
seed: int = None,
):
if seed is not None:
random.seed(seed)
numpy.random.seed(seed)
torch.manual_seed(seed)

self.param_file = param_file
self.param_file = str(param_file)
params = Params.from_file(self.param_file)

reader = DatasetReader.from_params(
Expand Down

0 comments on commit 63f61f0

Please sign in to comment.