コード例 #1
0
def inject_backend_tests_batch_renormalization():
    return testing.inject_backend_tests(
        None,
        # CPU tests
        [
            {},
            {'use_ideep': 'always'},
        ]
        # GPU tests
        + [
            {'use_cuda': True, 'cuda_device': 0},
            {'use_cuda': True, 'cuda_device': 1},
        ]
        # ChainerX tests
        + [
            {'use_chainerx': True, 'chainerx_device': 'native:0'},
            {'use_chainerx': True, 'chainerx_device': 'cuda:0'},
            {'use_chainerx': True, 'chainerx_device': 'cuda:1'},
        ])
コード例 #2
0
def inject_backend_tests_batch_renormalization():
    return testing.inject_backend_tests(
        None,
        # CPU tests
        [
            {},
            {
                'use_ideep': 'always'
            },
        ]
        # GPU tests
        + [
            {
                'use_cuda': True,
                'cuda_device': 0
            },
            {
                'use_cuda': True,
                'cuda_device': 1
            },
        ]
        # ChainerX tests
        + [
            {
                'use_chainerx': True,
                'chainerx_device': 'native:0'
            },
            {
                'use_chainerx': True,
                'chainerx_device': 'cuda:0'
            },
            {
                'use_chainerx': True,
                'chainerx_device': 'cuda:1'
            },
        ])
コード例 #3
0
_inject_backend_tests = testing.inject_backend_tests(
    None,
    [
        # CPU tests
        {},
        {
            'use_ideep': 'always'
        },
        # GPU tests
        {
            'use_cuda': True
        },
        {
            'use_cuda': True,
            'cuda_device': 1
        },
        # ChainerX tests
        {
            'use_chainerx': True,
            'chainerx_device': 'native:0'
        },
        {
            'use_chainerx': True,
            'chainerx_device': 'cuda:0'
        },
        {
            'use_chainerx': True,
            'chainerx_device': 'cuda:1'
        },
    ])
コード例 #4
0
ファイル: test_function.py プロジェクト: hvy/chainer
import numpy
import pytest

import chainer
from chainer import testing
from chainer import utils
import chainerx


_inject_backend_tests = testing.inject_backend_tests(
    None,
    [
        # CPU tests
        {},
        {'use_ideep': 'always'},
        # GPU tests
        {'use_cuda': True},
        {'use_cuda': True, 'cuda_device': 1},
        # ChainerX tests
        {'use_chainerx': True, 'chainerx_device': 'native:0'},
        {'use_chainerx': True, 'chainerx_device': 'cuda:0'},
        {'use_chainerx': True, 'chainerx_device': 'cuda:1'},
    ])


def _forward_correct(x1, x2):
    dt = x1.dtype.type
    y1 = (x1 + x2) ** dt(2)
    y2 = (x1 ** dt(2)) * (x2 ** dt(2))
    return utils.force_array(y1), utils.force_array(y2)

コード例 #5
0
_inject_backend_tests = testing.inject_backend_tests(
    None,
    # CPU tests
    [
        {},
        {
            'use_ideep': 'always'
        },
    ]
    # GPU tests
    + testing.product({
        'use_cuda': [True],
        'use_cudnn': ['never', 'always'],
        'cuda_device': [0, 1],
    })
    # ChainerX tests
    + [
        {
            'use_chainerx': True,
            'chainerx_device': 'native:0'
        },
        {
            'use_chainerx': True,
            'chainerx_device': 'cuda:0'
        },
        {
            'use_chainerx': True,
            'chainerx_device': 'cuda:1'
        },
    ])
コード例 #6
0
    def test_serialization(self, backend_config):
        if not self.lazy_init:
            self.check_serialization(backend_config)


_inject_backend_tests = testing.inject_backend_tests(
    [
        'test_weight_is_parameter', 'test_in_recomputing', 'test_deleted',
        'test_u_updated_in_train', 'test_u_not_updated_in_test',
        'test_serialization'
    ],
    # CPU tests
    testing.product({
        'use_ideep': ['always', 'never'],
    })
    # GPU tests
    + testing.product({
        'use_cuda': [True],
    })
    # ChainerX tests
    + testing.product({
        'use_chainerx': [True],
        'chainerx_device': ['native:0', 'cuda:0'],
    }))


@testing.parameterize(*testing.product({
    'use_gamma': [True, False],
}))
@_inject_backend_tests
コード例 #7
0
        {'input_shape': (5, 4), 'axis': 0},
        {'input_shape': (5, 4, 3), 'axis': (0, 1)},
    ]
)))


_inject_backend_tests = testing.inject_backend_tests(
    None,
    # CPU tests
    [
        {},
        {'use_ideep': 'always'},
    ]
    # GPU tests
    + testing.product({
        'use_cuda': [True],
        'use_cudnn': ['never', 'always'],
        'cuda_device': [0, 1],
    })
    # ChainerX tests
    + [
        {'use_chainerx': True, 'chainerx_device': 'native:0'},
        {'use_chainerx': True, 'chainerx_device': 'cuda:0'},
        {'use_chainerx': True, 'chainerx_device': 'cuda:1'},
    ])


def _batch_normalization(expander, gamma, beta, x, mean, var, eps, test):
    mean = mean[expander]
    if test:
        std = numpy.sqrt(var[expander])
コード例 #8
0
            testing.assert_allclose(y1.array, y2.array)

    def test_serialization(self, backend_config):
        if not self.lazy_init:
            self.check_serialization(backend_config)


_inject_backend_tests = testing.inject_backend_tests(
    ['test_weight_is_parameter', 'test_in_recomputing', 'test_deleted',
     'test_u_updated_in_train', 'test_u_not_updated_in_test',
     'test_serialization'],
    # CPU tests
    testing.product({
        'use_ideep': ['always', 'never'],
    })
    # GPU tests
    + testing.product({
        'use_cuda': [True],
    })
    # ChainerX tests
    + testing.product({
        'use_chainerx': [True],
        'chainerx_device': ['native:0', 'cuda:0'],
    })
)


@testing.parameterize(*testing.product({
    'use_gamma': [True, False],
}))
@_inject_backend_tests
class TestEmbedID(unittest.TestCase, BaseTest):