question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

6.0.0b2 does not support to_cpu/to_gpu of inner links

See original GitHub issue

I found that chainer==6.0.0b2breaks my code.

I’m using a helper class that contains a numpy/cupy array and do something with it. The device of this array can be switched by to_cpu/to_gpu method. The link class that uses this helper class overrides to_cpu/to_gpu method to call the helper’s ones.

In chainer==6.0.0b2, a parent link does not call to_cpu/to_gpu of child links. So the following code does not work.

import chainer
from chainer.backends import cuda
import numpy as np


class Helper(object):

    def __init__(self):
        self._value = np.array((0, 1, 2))

    def meth(self, h2):
        # caluculate y from h2 and self._value.
        return y

    def to_cpu(self):
        self._value = cuda.to_cpu(self._value)

    def to_gpu(self, device=None):
        self._value = cuda.to_gpu(self._value, device=device)


class SubModel(chainer.Chain):

    def __init__(self):
        super().__init__()
        with self.init_scope():
            # add some child links

        self._helper = Helper()

    def __call__(self, h1):
        # caluculate h2 from h1 using own child links
        return h2

    def to_cpu(self):
        super().to_cpu()
        self._helper.to_cpu()

    def to_gpu(self, device=None):
        super().to_gpu(device)
        self._helper.to_gpu(device=device)

    def predict(self, h1):
        h2 = self(h1)
        y = self._helper.meth(h2.array)
        return y


class Model(chainer.Chain):

    def __init__(self):
        super().__init__()
        with self.init_scope():
            self.sub_model = SubModel()
            # add some child links

    def __call__(self, x):
        # caluculate h1 from x using own child links
        h2 = self.sub_model(h1)
        return h2

    def predict(self, x):
        # caluculate h1 from x using own child links
        y = self.sub_model.predict(h1)
        return y

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Hakuyumecommented, Apr 17, 2019

I confirmed this issue was fixed in the master branch. Thank you!

1reaction
toslunarcommented, Apr 11, 2019

The code in #6825 is a simplification (by @kmaehashi and me) of the code here to reproduce a specific error. Let’s keep this issue open until @Hakuyume confirms it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OBD-II Port Not Working? Check This Out! - YouTube
This video is showing you exactly how I would go about trouble shooting an OBD-II port that is not functioning. The same methodology...
Read more >
Internal links in Jupyter Notebook doesn't work #1330 - GitHub
When i try to create an internal link in the jupyter notebook it doesn't work. i used this code: [reference](#reference) some stuff ...
Read more >
chainer.functions.unpooling_2d
Inverse operation of pooling for 2d array. This function acts similarly to Deconvolution2DFunction , but it spreads input 2d array's value without any...
Read more >
Nexus 3500 Output Drops and Buffer QoS - Cisco
This document describes commands used in order to troubleshoot the type of traffic dropped on the Nexus 3500 platform and the output buffer ......
Read more >
Yoast not recognising internal links | WordPress.org
why is yoast saying there are no internal links on pages when there are serveral internal links. If I add another internal link...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found