Python chainer.__version__() Examples

The following are 17 code examples of chainer.__version__(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module chainer , or try the search function .
Example #1
Source File: test_trpo.py    From chainerrl with MIT License 6 votes vote down vote up
def test_second_order(self):
        # Second order, so its Hessian will be non-zero
        params, y = self._generate_params_and_second_order_output()

        old_style_funcs = trpo._find_old_style_function([y])
        if old_style_funcs:
            self.skipTest("\
Chainer v{} does not support double backprop of these functions: {}.".format(
                chainer.__version__, old_style_funcs))

        def test_hessian_vector_product_nonzero(vec):
            hvp = compute_hessian_vector_product(y, params, vec)
            hessian = compute_hessian(y, params)
            self.assertGreater(np.count_nonzero(hvp), 0)
            self.assertGreater(np.count_nonzero(hessian), 0)
            np.testing.assert_allclose(hvp, hessian.dot(vec), atol=1e-3)

        # Test with two different random vectors, reusing y
        test_hessian_vector_product_nonzero(
            np.random.rand(4).astype(np.float32))
        test_hessian_vector_product_nonzero(
            np.random.rand(4).astype(np.float32)) 
Example #2
Source File: train_utils.py    From chainer-segnet with MIT License 6 votes vote down vote up
def create_logger(args, result_dir):
    root = logging.getLogger()
    root.setLevel(logging.DEBUG)
    msg_format = '%(asctime)s [%(levelname)s] %(message)s'
    formatter = logging.Formatter(msg_format)
    ch = logging.StreamHandler(sys.stdout)
    ch.setLevel(logging.DEBUG)
    ch.setFormatter(formatter)
    root.addHandler(ch)
    fileHandler = logging.FileHandler("{}/stdout.log".format(result_dir))
    fileHandler.setFormatter(formatter)
    root.addHandler(fileHandler)
    logging.info(sys.version_info)
    logging.info('chainer version: {}'.format(chainer.__version__))
    logging.info('cuda: {}, cudnn: {}'.format(
        chainer.cuda.available, chainer.cuda.cudnn_enabled))
    logging.info(args) 
Example #3
Source File: versioning_tools.py    From knmt with GNU General Public License v3.0 6 votes vote down vote up
def get_version_dict():
    import nmt_chainer._version
    result = OrderedDict({"package_version": nmt_chainer._version.__version__})
    current_git_hash = get_current_git_hash()
    if current_git_hash is not None:
        result["git"] = current_git_hash
        current_git_status = is_current_git_dirty()
        result["dirty_status"] = current_git_status
        if current_git_status == "dirty":
            result["diff"] = get_current_git_diff()
        result["version_from"] = "git call"
    else:
        package_git_hash = get_package_git_hash()
        if package_git_hash is not None:
            result["git"] = package_git_hash
            current_git_status = get_package_dirty_status()
            result["dirty_status"] = current_git_status
            if current_git_status == "dirty":
                result["diff"] = get_package_git_diff()
            result["version_from"] = "setup info"
        else:
            result["git"] = "unavailable"

    result["chainer"] = get_chainer_infos()
    return result 
Example #4
Source File: helpers.py    From chainer_computational_cost with MIT License 5 votes vote down vote up
def require_chainer_version(ver_oldest, ver_newest=None):
    """Decorator to turn on/off a test case by Chainer version

    Test case with this decorator is automatically activated for testing
    if the current Chainer version is between `ver_oldest` and `ver_newest`.
    In case `ver_newest` is not specified it is ignored.

    This is useful when the version of Chainer the current environment has does
    not suppor the operator that the test case tests.
    For example, Chaienr v3 doesn't have `groups` argument in Convolution2D.
    It cannot be checked by @require_import decorator so in this case
    this making use of this decorator like `@require_chainer_version('4.0.0')`
    would be appropriate.

    Args:
        ver_oldest: Version string of lower bound (inclusive).
          For example, '3.0.0'.
        ver_newest: Version string of upper bound (inclusive). Can be omitted.
    """
    def nothing(tester_func):
        def nothing_body(*args):
            ver_msg = "newer than or equals to {}".format(ver_oldest)
            if ver_newest is not None:
                ver_msg += " and older than or equal to {}".format(ver_newest)
            msg = "The test case \"{}\" requires Chainer version to be {}. "\
                  "Actual version is {}. Skipping."\
                  .format(tester_func.__name__, ver_msg, chainer.__version__)
            warnings.warn(msg)
            return None
        return nothing_body

    def run_test(tester_func):
        def f(*args):
            return tester_func(*args)
        return f

    ver_current = LooseVersion(chainer.__version__)
    if LooseVersion(ver_oldest) <= ver_current:
        if ver_newest is None or ver_current <= LooseVersion(ver_newest):
            return run_test
    return nothing 
Example #5
Source File: test_trpo.py    From chainerrl with MIT License 5 votes vote down vote up
def test_first_order(self):
        # First order, so its Hessian will contain None
        params, y = self._generate_params_and_first_order_output()

        old_style_funcs = trpo._find_old_style_function([y])
        if old_style_funcs:
            self.skipTest("\
Chainer v{} does not support double backprop of these functions: {}.".format(
                chainer.__version__, old_style_funcs))

        vec = np.random.rand(4).astype(np.float32)
        # Hessian-vector product computation should raise an error due to None
        with self.assertRaises(AssertionError):
            compute_hessian_vector_product(y, params, vec) 
Example #6
Source File: nnbase.py    From chainer-libDNN with MIT License 5 votes vote down vote up
def __init__(self, model, gpu=-1):
        self.model = model
        self.gpu = gpu

        if self.gpu >= 0:
            # if using pyCUDA version (v1.2.0 earlier)
            if chainer.__version__ <= '1.2.0':
                chainer.cuda.init(self.gpu)
            # CuPy (1.3.0 later) version
            else:
                chainer.cuda.get_device(self.gpu).use()

            self.model = self.model.to_gpu() 
Example #7
Source File: test_rsgcn.py    From chainer-chemistry with MIT License 5 votes vote down vote up
def test_backward_cpu_with_nfp(model_with_nfp_no_dropout, data):
    atom_data, adj_data, y_grad = data
    if int(chainer.__version__[0]) <= 2:
        params = ()
    else:
        params = tuple(model_with_nfp_no_dropout.params())
    gradient_check.check_backward(
        model_with_nfp_no_dropout, (atom_data, adj_data), y_grad,
        params=params,
        atol=1e-4, rtol=1e-4, no_grads=[True, True]) 
Example #8
Source File: test_rsgcn.py    From chainer-chemistry with MIT License 5 votes vote down vote up
def test_backward_gpu(model_no_dropout, data):
    atom_data, adj_data, y_grad = [cuda.to_gpu(d) for d in data]
    model_no_dropout.to_gpu()
    if int(chainer.__version__[0]) <= 2:
        # somehow the test fails with `params` when using chainer version 2...
        # TODO(nakago): investigate why the test fails.
        params = ()
    else:
        params = tuple(model_no_dropout.params())
    # TODO(nakago): check why tolerance is high
    gradient_check.check_backward(
        model_no_dropout, (atom_data, adj_data), y_grad,
        params=params,
        atol=1e-1, rtol=1e-1, no_grads=[True, True]) 
Example #9
Source File: test_rsgcn.py    From chainer-chemistry with MIT License 5 votes vote down vote up
def test_backward_cpu(model_no_dropout, data):
    atom_data, adj_data, y_grad = data
    if int(chainer.__version__[0]) <= 2:
        # somehow the test fails with `params` when using chainer version 2...
        # TODO(nakago): investigate why the test fails.
        params = ()
    else:
        params = tuple(model_no_dropout.params())
    # TODO(nakago): check why tolerance is high
    gradient_check.check_backward(
        model_no_dropout, (atom_data, adj_data), y_grad,
        params=params,
        atol=1e-1, rtol=1e-1, no_grads=[True, True]) 
Example #10
Source File: train.py    From deeppose with GNU General Public License v2.0 5 votes vote down vote up
def create_logger(args, result_dir):
    logging.basicConfig(filename='{}/log.txt'.format(result_dir))
    root = logging.getLogger()
    root.setLevel(logging.DEBUG)
    ch = logging.StreamHandler(sys.stdout)
    ch.setLevel(logging.DEBUG)
    msg_format = '%(asctime)s [%(levelname)s] %(message)s'
    formatter = logging.Formatter(msg_format)
    ch.setFormatter(formatter)
    root.addHandler(ch)
    logging.info(sys.version_info)
    logging.info('chainer version: {}'.format(chainer.__version__))
    logging.info('cuda: {}, cudnn: {}'.format(
        chainer.cuda.available, chainer.cuda.cudnn_enabled))
    logging.info(args) 
Example #11
Source File: _runtime_info.py    From chainer with MIT License 5 votes vote down vote up
def __init__(self):
        self.chainer_version = chainer.__version__
        self.chainerx_available = chainerx.is_available()
        self.numpy_version = numpy.__version__
        self.platform_version = platform.platform()
        if cuda.available:
            self.cuda_info = cuda.cupyx.get_runtime_info()
        else:
            self.cuda_info = None
        if intel64.is_ideep_available():
            self.ideep_version = intel64.ideep.__version__
        else:
            self.ideep_version = None 
Example #12
Source File: test_runtime_info.py    From chainer with MIT License 5 votes vote down vote up
def test_get_runtime_info(self):
        info = _runtime_info._get_runtime_info()
        assert chainer.__version__ in str(info) 
Example #13
Source File: system_info.py    From EEND with MIT License 5 votes vote down vote up
def print_system_info():
    pyver = sys.version.replace('\n', ' ')
    print(f"python version: {pyver}")
    print(f"chainer version: {chainer.__version__}")
    print(f"cupy version: {cupy.__version__}")
    print(f"cuda version: {cupy.cuda.runtime.runtimeGetVersion()}")
    print(f"cudnn version: {cudnn.getVersion()}") 
Example #14
Source File: versioning_tools.py    From knmt with GNU General Public License v3.0 5 votes vote down vote up
def main(options=None):
    import nmt_chainer._version
    print("package version:", nmt_chainer._version.__version__)
    print("installed in:", get_installed_path())

    print("\n*********** chainer version ***********")
    chainer_infos = get_chainer_infos()
    for keyword in "version cuda cudnn cuda_version cudnn_version".split():
        print(keyword, chainer_infos[keyword])

    print("\n\n********** package build info ***********")
    print("package build (git hash):", get_package_git_hash())
    package_dirty_status = get_package_dirty_status()
    if package_dirty_status == "clean":
        print("  - package git index is clean")
    elif package_dirty_status == "dirty":
        print("  - package git index is dirty")
        print("\npackage build diff (git diff):\n", get_package_git_diff())

    print("\n\n********** current version info ***********")
    print("git hash:", get_current_git_hash())

    current_dirty_status = is_current_git_dirty()

    if current_dirty_status == "clean":
        print("  - git index is clean")
    elif current_dirty_status == "dirty":
        print("  - git index is dirty")
        print("\ngit diff:\n")
        print(get_current_git_diff()) 
Example #15
Source File: versioning_tools.py    From knmt with GNU General Public License v3.0 5 votes vote down vote up
def get_chainer_infos():
    try:
        import chainer
        result = OrderedDict([
            ("version", chainer.__version__),
            ("cuda", chainer.cuda.available),
            ("cudnn", chainer.cuda.cudnn_enabled),
        ])
        if chainer.cuda.available:
            try:
                import cupy
                cuda_version = cupy.cuda.runtime.driverGetVersion()
            except BaseException:
                cuda_version = "unavailable"
            result["cuda_version"] = cuda_version
        else:
            result["cuda_version"] = "unavailable"

        if chainer.cuda.cudnn_enabled:
            try:
                cudnn_version = chainer.cuda.cudnn.cudnn.getVersion()
            except BaseException:
                cudnn_version = "unavailable"
            result["cudnn_version"] = cudnn_version
        else:
            result["cudnn_version"] = "unavailable"

    except ImportError:
        result = OrderedDict([
            ("version", "unavailable"),
            ("cuda", "unavailable"),
            ("cudnn", "unavailable"),
            ("cuda_version", "unavailable"),
            ("cudnn_version", "unavailable")
        ])

    return result 
Example #16
Source File: test_trpo.py    From chainerrl with MIT License 4 votes vote down vote up
def _test_abc_batch(
            self, steps=100000,
            require_success=True, gpu=-1, load_model=False, num_envs=4):

        if self.recurrent and gpu >= 0:
            self.skipTest(
                'NStepLSTM does not support double backprop with GPU.')
        if self.recurrent and chainer.__version__ == '7.0.0b3':
            self.skipTest(
                'chainer==7.0.0b3 has a bug in double backrop of LSTM.'
                ' See https://github.com/chainer/chainer/pull/8037')

        env, _ = self.make_vec_env_and_successful_return(
            test=False, num_envs=num_envs)
        test_env, successful_return = self.make_vec_env_and_successful_return(
            test=True, num_envs=num_envs)
        agent = self.make_agent(env, gpu)
        max_episode_len = None if self.episodic else 2

        if load_model:
            print('Load agent from', self.agent_dirname)
            agent.load(self.agent_dirname)

        # Train
        train_agent_batch_with_evaluation(
            agent=agent,
            env=env,
            steps=steps,
            outdir=self.tmpdir,
            eval_interval=200,
            eval_n_steps=None,
            eval_n_episodes=40,
            successful_score=successful_return,
            eval_env=test_env,
            log_interval=100,
            max_episode_len=max_episode_len,
        )
        env.close()

        # Test
        n_test_runs = 10
        eval_returns = batch_run_evaluation_episodes(
            test_env,
            agent,
            n_steps=None,
            n_episodes=n_test_runs,
            max_episode_len=max_episode_len,
        )
        test_env.close()
        if require_success:
            n_succeeded = np.sum(np.asarray(eval_returns) >= successful_return)
            self.assertEqual(n_succeeded, n_test_runs)

        # Save
        agent.save(self.agent_dirname) 
Example #17
Source File: test_trpo.py    From chainerrl with MIT License 4 votes vote down vote up
def _test_abc(self, steps=100000,
                  require_success=True, gpu=-1, load_model=False):

        if self.recurrent and gpu >= 0:
            self.skipTest(
                'NStepLSTM does not support double backprop with GPU.')
        if self.recurrent and chainer.__version__ == '7.0.0b3':
            self.skipTest(
                'chainer==7.0.0b3 has a bug in double backrop of LSTM.'
                ' See https://github.com/chainer/chainer/pull/8037')

        env, _ = self.make_env_and_successful_return(test=False)
        test_env, successful_return = self.make_env_and_successful_return(
            test=True)

        agent = self.make_agent(env, gpu)

        if load_model:
            print('Load agent from', self.agent_dirname)
            agent.load(self.agent_dirname)

        max_episode_len = None if self.episodic else 2

        # Train
        train_agent_with_evaluation(
            agent=agent,
            env=env,
            eval_env=test_env,
            steps=steps,
            outdir=self.tmpdir,
            eval_interval=200,
            eval_n_steps=None,
            eval_n_episodes=5,
            successful_score=successful_return,
            train_max_episode_len=max_episode_len,
        )

        agent.stop_episode()

        # Test
        n_test_runs = 10
        eval_returns = run_evaluation_episodes(
            test_env,
            agent,
            n_steps=None,
            n_episodes=n_test_runs,
            max_episode_len=max_episode_len,
        )
        if require_success:
            n_succeeded = np.sum(np.asarray(eval_returns) >= successful_return)
            self.assertEqual(n_succeeded, n_test_runs)

        # Save
        agent.save(self.agent_dirname)