pytorch

Форк
0
/
weight_scale_test.py 
51 строка · 2.0 Кб
1
# Copyright (c) 2016-present, Facebook, Inc.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
##############################################################################
15

16

17

18

19

20

21
from caffe2.python import core
22
import caffe2.python.hypothesis_test_util as hu
23
import functools
24
from hypothesis import given
25
import hypothesis.strategies as st
26
import numpy as np
27

28
class TestWeightScale(hu.HypothesisTestCase):
29
    @given(inputs=hu.tensors(n=1),
30
           ITER=st.integers(min_value=0, max_value=100),
31
           stepsize=st.integers(min_value=20, max_value=50),
32
           upper_bound_iter=st.integers(min_value=5, max_value=100),
33
           scale=st.floats(min_value=0.01, max_value=0.99, allow_nan=False, allow_infinity=False),
34
           **hu.gcs)
35
    def test_weight_scale(self, inputs, ITER, stepsize, upper_bound_iter, scale, gc, dc):
36
        ITER = np.array([ITER], dtype=np.int64)
37
        op = core.CreateOperator(
38
            "WeightScale", ["w", "iter"], ["nw"], stepsize=stepsize, upper_bound_iter=upper_bound_iter, scale=scale)
39

40
        def ref_weight_scale(w, iter, stepsize, upper_bound_iter, scale):
41
            iter = iter + 1
42
            return [w * scale if iter % stepsize == 0 and iter < upper_bound_iter else w]
43

44
        input_device_options = {'iter': hu.cpu_do}
45
        self.assertReferenceChecks(
46
            gc,
47
            op,
48
            [inputs[0], ITER],
49
            functools.partial(ref_weight_scale, stepsize=stepsize, upper_bound_iter=upper_bound_iter, scale=scale),
50
            input_device_options=input_device_options
51
        )
52

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.