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

Hide FunctionNode classes from chainer.functions namespace #4421

Merged
merged 27 commits into from Jun 29, 2018

Conversation

hvy
Copy link
Member

@hvy hvy commented Feb 28, 2018

This PR hides all FunctionNode implementations from functions/__init__.py since these are considered implementation details and should not "be visible" to the user.

Some exceptions are FunctionNodes with states that are exposed through APIs such as the indices for the max pooling classes and the random states in dropout and gaussian noise.

Tests are modified accordingly to not rely on these classes directly. There are few exceptions including the the ones above.

  • Remove FunctionNode imports from functions/__init__
  • Do not use FunctionNodes classes directly in tests if possible
  • [ ] Remove FunctionNode's __init__'s default arguments (Maybe better done in a separate PR)

Note: Reviewing commit by commit is probably much easier than looking at the total diff.

@hvy hvy added the no-compat Change that disrupts backward compatibility. label Feb 28, 2018
@hvy
Copy link
Member Author

hvy commented Mar 6, 2018

Rebased on the current master. Need to fix newly introduced FunctionNodes.

  • functions.activations.Softplus
  • functions.arrays.Permutate
  • functions.math.exponential_m1.Expm1

@hvy
Copy link
Member Author

hvy commented Mar 6, 2018

Fixed the above mentioned 3 FunctionNodes.

@hvy hvy changed the title [WIP] FunctionNodes as implementation details FunctionNodes as implementation details Mar 6, 2018
@hvy
Copy link
Member Author

hvy commented Mar 6, 2018

Ready for review, and very open for discussions.

@hvy
Copy link
Member Author

hvy commented May 28, 2018

I'll fix the broken commit history.

@hvy
Copy link
Member Author

hvy commented May 29, 2018

@kmaehashi Rebased and fixed the commit history. Could you please take at a look?

Copy link
Member

@kmaehashi kmaehashi left a comment

Choose a reason for hiding this comment

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

Please check comments.
Could you add this to the upgrade guide?

from chainer.functions.math.trigonometric import tan # NOQA
from chainer.functions.math.trigonometric import Tan # NOQA

from chainer.functions.noise.dropout import dropout # NOQA
from chainer.functions.noise.dropout import Dropout # NOQA
Copy link
Member

Choose a reason for hiding this comment

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

Should it be removed? (Dropout, Gaussian, MaxPooling2D, MaxPoolingND are left)

Copy link
Member Author

Choose a reason for hiding this comment

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

Those are left on purpose, as they're stateful. For Dropout and Gaussian we sometimes want to reuse their random state/noise. As for the pooling functions, we similarly want to extract the resulting indices.

@@ -188,7 +188,8 @@ def backward(self, indexes, grad_outputs):
def average_pooling_2d(x, ksize, stride=None, pad=0):
"""Spatial average pooling function.

This function acts similarly to :class:`~functions.Convolution2D`, but
This function acts similarly to
:class:`~functions.connection.convolution_2d.Convolution2D`, but
Copy link
Member

Choose a reason for hiding this comment

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

It should point :func:~chainer.functions.convolution_2d.
Same for other pooling functions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed.

It is because :attr:`~chainer.functions.MaxPooling2D.indexes` is never
created and stored in the :attr:`~chainer.functions.MaxPooling2D`
It is because
:attr:`~chainer.functions.pooling.max_pooling_2d.MaxPooling2D.indexes`
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I didn't know this fact. So users should directly work with MaxPooling2D to use F.upsampling_2d...

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 unfortunately... PyTorch's max_pool**, takes a boolean flag by the way and returns either the output or a pair of (output, indices) depending on the flag. That'd be another way to do it.

@@ -246,19 +246,19 @@ def test_double_backward_negative_multi_axis_invert_gpu(self):

def test_invalid_axis_type(self):
with self.assertRaises(TypeError):
functions.Sum([0])
functions.logsumexp(self.x, [0])
Copy link
Member

Choose a reason for hiding this comment

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

😅

@@ -190,11 +190,6 @@ def check_invalid_poolings(self):
with self.assertRaises(ValueError):
functions.spatial_pyramid_pooling_2d(self.v, 3, pooling='avg')

with testing.assert_warns(DeprecationWarning), \
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense to leave this test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the test back.

@kmaehashi kmaehashi added this to the v5.0.0b2 milestone Jun 6, 2018
@hvy
Copy link
Member Author

hvy commented Jun 14, 2018

Hm that's what I thought. I don't think it makes a significant difference whether we remove it in this major release or in the next in that case. Please correct me if I am wrong.

@kmaehashi
Copy link
Member

kmaehashi commented Jun 14, 2018

After v5 release, users of v4 may feel "F.MaxPooling2D suddenly disappeared although I was using documented API."

How about updating documents here in separate PR and then backporting it to v4?
https://github.com/chainer/chainer/pull/4421/files#r193370068
In that case, I think it's OK to remove MaxPooling2D in this PR.

@hvy
Copy link
Member Author

hvy commented Jun 15, 2018

Thanks for the suggestion, but this PR is not going to be backported?

@kmaehashi
Copy link
Member

I mean:

  • Do not fix documentation of chainer/functions/pooling/upsampling_2d.py in this PR. Do not backport this PR.
  • Create new PR to fix the documentation (to suggest use of F.max_pooling_2d(return_indices=True). Then backport the PR.

@hvy
Copy link
Member Author

hvy commented Jun 18, 2018

Sorry I now see what you mean. I think that's an acceptable solution. I'll create a PR to fix the documentation once #4890 is merged.

@beam2d beam2d modified the milestones: v5.0.0b2, v5.0.0b3 Jun 21, 2018
@hvy hvy removed the st:blocked-by-another-pr State indicating that another ticket is preventing this ticket from being closed/merged. label Jun 23, 2018
@hvy
Copy link
Member Author

hvy commented Jun 23, 2018

jenkins, test this please.

@hvy
Copy link
Member Author

hvy commented Jun 23, 2018

jenkins, test this please.

@chainer-ci
Copy link
Member

Jenkins CI test (for commit 67c49aa) failed with status FAILURE.
(For contributors, please wait until the reviewer confirms the details of the error.)

@hvy
Copy link
Member Author

hvy commented Jun 23, 2018

jenkins, test this please.

@chainer-ci
Copy link
Member

Jenkins CI test (for commit aeded94) succeeded without errors!

@kmaehashi
Copy link
Member

@hvy Could you resolve conflict? (Sorry I had to merge this quickly...)

@hvy
Copy link
Member Author

hvy commented Jun 29, 2018

@kmaehashi Done!

@hvy
Copy link
Member Author

hvy commented Jun 29, 2018

jenkins, test this please.

@kmaehashi
Copy link
Member

Thanks! Travis failure seems not related to this PR.
I'll merge this after Jenkins pass.

@kmaehashi kmaehashi added the st:test-and-merge State indicating that pull request is approved by a reviewer and can be merged after CI passes. label Jun 29, 2018
@chainer-ci
Copy link
Member

Jenkins CI test (for commit 4caca0c) failed with status FAILURE.
(For contributors, please wait until the reviewer confirms the details of the error.)

@kmaehashi
Copy link
Member

LGTM! Test failures are not related to this PR.

@kmaehashi kmaehashi merged commit 000181f into chainer:master Jun 29, 2018
@hvy hvy deleted the functionnodes-impl branch June 29, 2018 10:10
@kmaehashi kmaehashi changed the title FunctionNodes as implementation details Hide FunctionNode classes from chainer.functions namespace Jul 18, 2018
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. no-compat Change that disrupts backward compatibility. st:test-and-merge State indicating that pull request is approved by a reviewer and can be merged after CI passes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants