Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax int type restriction #3466

Merged
merged 5 commits into from Oct 27, 2017
Merged

Relax int type restriction #3466

merged 5 commits into from Oct 27, 2017

Conversation

okuta
Copy link
Member

@okuta okuta commented Sep 27, 2017

Current int type restriction is too strict.
This PR is relax it.

'''
if (x != ignore) {
int w_ind[] = {x, i % n_out};
ptrdiff_t w_ind[] = {x, i % n_out};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. (ptrdiff_t -> S)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

@@ -45,7 +43,7 @@ def binary_accuracy(y, t):

t (:class:`~chainer.Variable` or :class:`numpy.ndarray` or \
:class:`cupy.ndarray`):
Array holding an int32 vector of ground truth labels.
Array holding an signed integer vector of ground truth labels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an -> a

@@ -75,8 +75,8 @@ def sigmoid_cross_entropy(
x (Variable): A variable object holding a matrix whose (i, j)-th
element indicates the unnormalized log probability of the j-th unit
at the i-th example.
t (Variable): Variable holding an int32 vector of ground truth labels.
If ``t[i] == -1``, corresponding ``x[i]`` is ignored.
t (Variable): Variable holding an signed integer vector of ground truth
Copy link
Member

@niboshi niboshi Sep 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto. (an -> a)

@@ -294,7 +294,7 @@ def softmax_cross_entropy(
dimensions is greater than 2.
t (:class:`~chainer.Variable` or :class:`numpy.ndarray` or \
:class:`cupy.ndarray`):
Variable holding an :class:`numpy.int32` vector of ground truth
Variable holding an signed integer vector of ground truth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto. (an -> a)

{'shape': (3,), 'dtype': 'f', 'axis': -1, 'inv': True},
{'shape': (3, 4), 'dtype': 'd', 'axis': 1, 'inv': True},
{'shape': (3, 4, 5), 'dtype': 'f', 'axis': 2, 'inv': False}],
[{'label_dtype': numpy.int}, {'label_dtype': numpy.int32}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about other int types (int8, int16, int64)?

@testing.parameterize(*testing.product({
'reduce': ['no', 'mean'],
'norm': ['L1', 'L2'],
'label_dtype': [numpy.int, numpy.int32],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. (other int types)

# too large shape causes int32 -> float64 issue
{'shape': (65536, 1), 'normalize': False},
{'shape': (65536, 1), 'normalize': False, 'label_dtype': numpy.int32},
{'shape': (8, 7), 'normalize': True, 'label_dtype': numpy.int}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding some cases to test other int types?

@@ -21,6 +21,7 @@
'dtype': [numpy.float32],
'weight_apply': [False, True],
'enable_double_backprop': [False, True],
'label_dtype': [numpy.int32],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. (other int types)

@@ -29,6 +30,7 @@
'dtype': [numpy.float16, numpy.float32, numpy.float64],
'weight_apply': [False, True],
'enable_double_backprop': [False, True],
'label_dtype': [numpy.int, numpy.int32],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. (other int types)

'T gy, int32 x, int32 n_out', 'raw T gW',
'int w_ind[] = {x, i % n_out}; atomicAdd(&gW[w_ind], gy)',
'T gy, S x, S n_out', 'raw T gW',
'ptrdiff_t w_ind[] = {x, i % n_out};'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about ptrdiff_t -> S? It's guaranteed to be representable by S.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ptrdiff_t is better for CuPy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I agree with you because it's used as an index.

@niboshi niboshi self-assigned this Sep 28, 2017
@niboshi niboshi added cat:enhancement Implementation that does not break interfaces. to-be-backported Pull request that should be backported. st:awaiting-author State indicating that response is needed from contributors, often authors of pull request. labels Sep 28, 2017
@niboshi niboshi removed the st:awaiting-author State indicating that response is needed from contributors, often authors of pull request. label Oct 1, 2017
@niboshi
Copy link
Member

niboshi commented Oct 4, 2017

Please fix AppVeyor result.

@niboshi niboshi added the st:awaiting-author State indicating that response is needed from contributors, often authors of pull request. label Oct 4, 2017
@okuta
Copy link
Member Author

okuta commented Oct 14, 2017

I fixed.

@niboshi niboshi added st:ready-for-review and removed st:awaiting-author State indicating that response is needed from contributors, often authors of pull request. labels Oct 16, 2017
@okuta
Copy link
Member Author

okuta commented Oct 21, 2017

I resolved conflict.

@@ -43,6 +42,7 @@ def check_type_forward(self, in_types):
def forward(self, inputs):
xp = cuda.get_array_module(*inputs)
y, t = inputs
t = t.astype('i', copy=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this conversion necessary?
I think the actual type for 'i' is environment-dependent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Some Numpy functions require int32 on Windows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Can you write a brief comment on this line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@niboshi niboshi added st:test-and-merge State indicating that pull request is approved by a reviewer and can be merged after CI passes. and removed st:ready-for-review labels Oct 23, 2017
@niboshi
Copy link
Member

niboshi commented Oct 24, 2017

Please fix conflict.

@okuta
Copy link
Member Author

okuta commented Oct 24, 2017

I resolved conflict.

@niboshi
Copy link
Member

niboshi commented Oct 24, 2017

(Jenkins has passed. Waiting for travis)

@niboshi niboshi added this to the v4.0.0b1 milestone Oct 27, 2017
@niboshi
Copy link
Member

niboshi commented Oct 27, 2017

LGTM!

@niboshi niboshi merged commit 97ed424 into chainer:master Oct 27, 2017
niboshi added a commit to niboshi/chainer that referenced this pull request Oct 27, 2017
niboshi added a commit to niboshi/chainer that referenced this pull request Oct 27, 2017
@okuta okuta deleted the support-int-type branch February 13, 2018 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:enhancement Implementation that does not break interfaces. st:test-and-merge State indicating that pull request is approved by a reviewer and can be merged after CI passes. to-be-backported Pull request that should be backported.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants