generated from aarnphm/bazix
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathparams_export_test.py
97 lines (71 loc) · 3.11 KB
/
params_export_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from __future__ import annotations
import pytest
import whispercpp as w
def test_sampling_greedy():
# test repr and init
assert repr(w.api.SamplingGreedyStrategy()) == "SamplingGreedy(best_of=1)"
assert repr(w.api.SamplingGreedyStrategy(2)) == "SamplingGreedy(best_of=2)"
# test with_best_of_construction
assert (
repr(w.api.SamplingGreedyStrategy().with_best_of(2))
== "SamplingGreedy(best_of=2)"
)
def test_sampling_strategy_deprecation():
with pytest.warns(DeprecationWarning, match=r"Setting 'best_of' as an *"):
ss = w.api.SamplingGreedyStrategy()
ss.best_of = 2
with pytest.warns(DeprecationWarning, match=r"Setting 'patience' as an *"):
ss = w.api.SamplingBeamSearchStrategy()
ss.patience = 2
with pytest.warns(DeprecationWarning, match=r"Setting 'beam_size' as an *"):
ss = w.api.SamplingBeamSearchStrategy()
ss.beam_size = 2
def test_sampling_beam_search():
# test repr and init
assert (
repr(w.api.SamplingBeamSearchStrategy())
== "SamplingBeamSearch(beam_size=-1, patience=-1)"
)
assert (
repr(w.api.SamplingBeamSearchStrategy(2, 2))
== "SamplingBeamSearch(beam_size=2, patience=2)"
)
assert (
repr(w.api.SamplingBeamSearchStrategy().with_patience(2))
== "SamplingBeamSearch(beam_size=-1, patience=2)"
)
assert (
repr(w.api.SamplingBeamSearchStrategy().with_beam_size(2))
== "SamplingBeamSearch(beam_size=2, patience=-1)"
)
assert (
repr(w.api.SamplingBeamSearchStrategy().with_beam_size(2).with_patience(2))
== "SamplingBeamSearch(beam_size=2, patience=2)"
)
def test_sampling_strategies_from_enum():
# test from_enum
assert w.api.SamplingStrategies.from_enum(w.api.SAMPLING_GREEDY).build()
assert w.api.SamplingStrategies.from_enum(w.api.SAMPLING_BEAM_SEARCH).build()
def test_sampling_strategy_from_strategy_type():
# test from_strategy_type
ss = w.api.SamplingGreedyStrategy()
assert w.api.SamplingStrategies.from_strategy_type(ss).build()
ss = w.api.SamplingBeamSearchStrategy()
assert w.api.SamplingStrategies.from_strategy_type(ss).build()
def test_sampling_strategy_build_copy():
ss = w.api.SamplingGreedyStrategy()
assert w.api.SamplingStrategies.from_strategy_type(ss).build() is not ss
def test_sampling_on_setattr_warning():
with pytest.warns(DeprecationWarning, match=r"Setting 'greedy' as an *"):
ss = w.api.SamplingStrategies.from_enum(w.api.SAMPLING_GREEDY)
ss.greedy = w.api.SamplingGreedyStrategy(2)
with pytest.warns(DeprecationWarning, match=r"Setting 'beam_search' as an *"):
ss = w.api.SamplingStrategies.from_enum(w.api.SAMPLING_BEAM_SEARCH)
ss.beam_search = w.api.SamplingBeamSearchStrategy(2, 2)
def test_set_language():
params = w.api.Params.from_enum(w.api.StrategyType.SAMPLING_GREEDY)
for lang in ["en", "de", "auto", ""]:
assert params.language != ""
params_with_lang = params.with_language(lang)
print(lang, params_with_lang.language)
assert params_with_lang.language == lang