@@ -29,14 +29,14 @@ def test_length_penalty_default():
2929 lengths = pt .tensor ([[1 ], [2 ], [3 ]])
3030 length_penalty = sockeye .beam_search .LengthPenalty (1.0 , 0.0 )
3131 expected_lp = pt .tensor ([[1.0 ], [2. ], [3. ]])
32- pt .testing .assert_allclose (length_penalty (lengths ), expected_lp )
32+ pt .testing .assert_close (length_penalty (lengths ), expected_lp )
3333
3434
3535def test_length_penalty ():
3636 lengths = pt .tensor ([[1 ], [2 ], [3 ]])
3737 length_penalty = sockeye .beam_search .LengthPenalty (.2 , 5.0 )
3838 expected_lp = pt .tensor ([[6 ** 0.2 / 6 ** 0.2 ], [7 ** 0.2 / 6 ** 0.2 ], [8 ** 0.2 / 6 ** 0.2 ]])
39- pt .testing .assert_allclose (length_penalty (lengths ), expected_lp )
39+ pt .testing .assert_close (length_penalty (lengths ), expected_lp )
4040
4141
4242def test_length_penalty_int_input ():
@@ -51,15 +51,15 @@ def test_brevity_penalty_default():
5151 ref_lengths = pt .tensor ([[2 ], [3 ], [2 ]])
5252 brevity_penalty = sockeye .beam_search .BrevityPenalty (0.0 )
5353 expected_bp = pt .tensor ([[0 ], [0 ], [0 ]], dtype = pt .long )
54- pt .testing .assert_allclose (brevity_penalty (hyp_lengths , ref_lengths ), expected_bp )
54+ pt .testing .assert_close (brevity_penalty (hyp_lengths , ref_lengths ), expected_bp )
5555
5656
5757def test_brevity_penalty ():
5858 hyp_lengths = pt .tensor ([[1 ], [2 ], [3 ]])
5959 ref_lengths = pt .tensor ([[7 ], [2 ], [91 ]])
6060 brevity_penalty = sockeye .beam_search .BrevityPenalty (3.5 )
6161 expected_bp = pt .tensor ([[3.5 * (1 - 7 / 1 )], [0.0 ], [3.5 * (1 - 91 / 3 )]])
62- pt .testing .assert_allclose (brevity_penalty (hyp_lengths , ref_lengths ), expected_bp )
62+ pt .testing .assert_close (brevity_penalty (hyp_lengths , ref_lengths ), expected_bp )
6363
6464
6565def test_brevity_penalty_int_input ():
@@ -82,7 +82,7 @@ def test_candidate_scorer():
8282
8383 scores = scorer (raw_scores , lengths , reference_lengths )
8484 unnormalized_scores = scorer .unnormalize (scores , lengths , reference_lengths )
85- pt .testing .assert_allclose (unnormalized_scores , raw_scores )
85+ pt .testing .assert_close (unnormalized_scores , raw_scores )
8686
8787 # int/float input
8888 raw_scores = 5.6
@@ -228,7 +228,7 @@ def test_update_scores(use_unk_dist):
228228 pt .tensor (pad_dist ), pt .tensor (eos_dist ))
229229 scores = scores .detach ().numpy ()
230230 lengths = lengths
231- pt .testing .assert_allclose (lengths , pt .tensor ([1 , 1 , 1 ])) # all lengths but finished updated + 1
231+ pt .testing .assert_close (lengths , pt .tensor ([1 , 1 , 1 ], dtype = pt . int32 )) # all lengths but finished updated + 1
232232 assert (scores [0 ] == (1. + target_dists [0 ] + eos_dist )).all () # 1 reached max length, force eos
233233 assert (scores [1 ] == (1. + pad_dist [0 ]).tolist ()).all () # 2 finished, force pad, keep score
234234 if use_unk_dist :
@@ -341,7 +341,7 @@ def test_beam_search():
341341
342342 print ('beam search lengths' , r .lengths )
343343 print ('internal lengths' , inference .states [0 ])
344- pt .testing .assert_allclose (r .lengths , inference .states [0 ].squeeze (1 ))
344+ pt .testing .assert_close (r .lengths , inference .states [0 ].squeeze (1 ))
345345 assert inference .states [1 ] == max_length
346346
347347
@@ -355,7 +355,7 @@ def test_get_nvs_vocab_slice_ids():
355355 bow , output_vocab_size = sockeye .beam_search ._get_nvs_vocab_slice_ids (nvs_thresh = 0.5 ,
356356 nvs_prediction = nvs_prediction )
357357 assert output_vocab_size == expected_bow .shape [0 ]
358- pt .testing .assert_allclose (bow , expected_bow )
358+ pt .testing .assert_close (bow , expected_bow )
359359
360360 # Batch size 1
361361 # 0 1 2 3 4 5 6 7 8 9
@@ -364,7 +364,7 @@ def test_get_nvs_vocab_slice_ids():
364364 bow , output_vocab_size = sockeye .beam_search ._get_nvs_vocab_slice_ids (nvs_thresh = 0.5 ,
365365 nvs_prediction = nvs_prediction )
366366 assert output_vocab_size == expected_bow .shape [0 ]
367- pt .testing .assert_allclose (bow , expected_bow )
367+ pt .testing .assert_close (bow , expected_bow )
368368
369369 # Batch size 1 + higher thresh
370370 # 0 1 2 3 4 5 6 7 8 9
@@ -373,7 +373,7 @@ def test_get_nvs_vocab_slice_ids():
373373 bow , output_vocab_size = sockeye .beam_search ._get_nvs_vocab_slice_ids (nvs_thresh = 0.9 ,
374374 nvs_prediction = nvs_prediction )
375375 assert output_vocab_size == expected_bow .shape [0 ]
376- pt .testing .assert_allclose (bow , expected_bow )
376+ pt .testing .assert_close (bow , expected_bow )
377377
378378 # Batch size 2 + target prefix
379379 # Note: the first 4 tokens are special tokens (PAD, UNK etc.)
@@ -386,7 +386,7 @@ def test_get_nvs_vocab_slice_ids():
386386 nvs_prediction = nvs_prediction ,
387387 target_prefix = target_prefix )
388388 assert output_vocab_size == expected_bow .shape [0 ]
389- pt .testing .assert_allclose (bow , expected_bow )
389+ pt .testing .assert_close (bow , expected_bow )
390390
391391 # Batch size 2 + blocking lexicon
392392 # Note: the first 4 tokens are special tokens (PAD, UNK etc.)
@@ -401,7 +401,7 @@ def test_get_nvs_vocab_slice_ids():
401401 nvs_prediction = nvs_prediction ,
402402 restrict_lexicon = restrict_lexicon )
403403 assert output_vocab_size == expected_bow .shape [0 ]
404- pt .testing .assert_allclose (bow , expected_bow )
404+ pt .testing .assert_close (bow , expected_bow )
405405
406406
407407def test_get_vocab_slice_ids_blocking ():
@@ -419,4 +419,4 @@ def test_get_vocab_slice_ids_blocking():
419419 output_vocab_size = 6
420420 )
421421 expected_vocab_slice_ids = pt .tensor ([0 , 1 , 2 , 4 , 5 , C .EOS_ID , C .EOS_ID , C .EOS_ID ])
422- pt .testing .assert_allclose (vocab_slice_ids , expected_vocab_slice_ids )
422+ pt .testing .assert_close (vocab_slice_ids , expected_vocab_slice_ids )
0 commit comments