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

Commit 9b01d4c

Browse files
DeNeutoyjoelgrus
authored andcommitted
fix params duplicate bug (#2421)
1 parent c1aace7 commit 9b01d4c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

allennlp/common/params.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def duplicate(self) -> 'Params':
372372
Uses ``copy.deepcopy()`` to create a duplicate (but fully distinct)
373373
copy of these Params.
374374
"""
375-
return Params(copy.deepcopy(self.params))
375+
return copy.deepcopy(self)
376376

377377
def assert_empty(self, class_name: str):
378378
"""

allennlp/tests/common/params_test.py

+11
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,14 @@ def test_infer_and_cast(self):
345345

346346
assert params.as_dict() == lots_of_strings
347347
assert params.as_dict(infer_type_and_cast=True) == casted
348+
349+
def test_duplicate_copies_all_params_state(self):
350+
351+
params = Params({},
352+
loading_from_archive=True,
353+
files_to_archive={"hey": "this is a path"})
354+
355+
new_params = params.duplicate()
356+
357+
assert new_params.loading_from_archive
358+
assert new_params.files_to_archive == {"hey": "this is a path"}

0 commit comments

Comments
 (0)