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.

Fallbacks of ChainerX on GetItem fail when indices contains chainerx.ndarray

See original GitHub issue

When chainerx with native backend falls back to numpy:

>>> chainer.Variable(chainerx.zeros(3, device='native'))[numpy.arange(3)]
variable([0., 0., 0.])
>>> chainer.Variable(chainerx.zeros(3, device='native'))[chainerx.arange(3, device='native')]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fujita/.local/share/virtualenvs/chainerrl_20180827-9TPAa4mI/lib/python3.5/site-packages/chainer/functions/array/get_item.py", line 143, in get_item
    return GetItem(slices).apply((x,))[0]
  File "/home/fujita/.local/share/virtualenvs/chainerrl_20180827-9TPAa4mI/lib/python3.5/site-packages/chainer/function_node.py", line 315, in apply
    outputs = self.forward(in_data)
  File "/home/fujita/.local/share/virtualenvs/chainerrl_20180827-9TPAa4mI/lib/python3.5/site-packages/chainer/functions/array/get_item.py", line 41, in forward
    return utils.force_array(xs[0][self.slices]),
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

When chainerx with cuda:0 backend falls back to cupy:

>>> chainer.Variable(chainerx.zeros(3, device='cuda:0'))[cupy.arange(3)]
variable([0., 0., 0.])
>>> chainer.Variable(chainerx.zeros(3, device='cuda:0'))[chainerx.arange(3, device='cuda:0')]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fujita/.local/share/virtualenvs/chainerrl_20180827-9TPAa4mI/lib/python3.5/site-packages/chainer/functions/array/get_item.py", line 143, in get_item
    return GetItem(slices).apply((x,))[0]
  File "/home/fujita/.local/share/virtualenvs/chainerrl_20180827-9TPAa4mI/lib/python3.5/site-packages/chainer/function_node.py", line 315, in apply
    outputs = self.forward(in_data)
  File "/home/fujita/.local/share/virtualenvs/chainerrl_20180827-9TPAa4mI/lib/python3.5/site-packages/chainer/functions/array/get_item.py", line 41, in forward
    return utils.force_array(xs[0][self.slices]),
  File "cupy/core/core.pyx", line 1650, in cupy.core.core.ndarray.__getitem__
  File "cupy/core/core.pyx", line 3255, in cupy.core.core._simple_getitem
TypeError: Invalid index type: <class 'chainerx.ndarray'>

I want these to work so I can write numpy/cupy/chainerx-agnostic code.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
beam2dcommented, Apr 15, 2019

It looks https://github.com/chainer/chainer/pull/6769 contains the fallback fix for this issue.

0reactions
muupancommented, Apr 23, 2019

Thank you so much for fixing the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

chainer/_fallback_workarounds.py at master · chainer/chainer · GitHub
This file defines workaround implementation for. # NumPy-compatibility functions that fall back to NumPy/CuPy functions.
Read more >
ChainerX Tutorial — Chainer 7.8.1 documentation
Graph construction and backpropagation is built into the array, meaning that any function, including the NumPy-like functions, can be backpropagated through. In ...
Read more >
Chainer Documentation - Read the Docs
It contains a sorted indices of the input variables w.r.t. which the gradients are ... held by the Variable object is not a...
Read more >
Chainer and ChainerX - Nvidia
W2.array -= lr * W2.grad. Write forward prop as a plain Python script. Variables hold how they were computed. Use it to compute...
Read more >
A flexible framework of neural networks for deep learning
import numpy as np import cupy import chainer import chainerx as chx ... of ChainerX on GetItem fail when indices contains chainerx.ndarray ......
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