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

"polish activation" #9740

Merged
merged 11 commits into from
Apr 20, 2018
Merged

"polish activation" #9740

merged 11 commits into from
Apr 20, 2018

Conversation

dzhwinter
Copy link
Contributor

fix #9416

Copy link
Contributor

@panyx0718 panyx0718 left a comment

Choose a reason for hiding this comment

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

LG overall
It would be great if we have a single source of truth of the in-place activation op list.

functor(*place, x, out, dout, dx);
} else {
framework::Tensor X;
auto x = framework::EigenVector<T>::Flatten(X);
Copy link
Contributor

Choose a reason for hiding this comment

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

can this flatten been avoided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -101,6 +118,7 @@ struct SigmoidFunctor : public BaseActivationFunctor<T> {

template <typename T>
struct SigmoidGradFunctor : public BaseActivationFunctor<T> {
bool Inplace() const { return true; }
Copy link
Contributor

@panyx0718 panyx0718 Apr 8, 2018

Choose a reason for hiding this comment

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

Can we have this in C++
static char* inplace_acts = ["sigmoid", "exp", ...]
bool IsInPlaceAct(const string& n) {
return n in inplace_acts;
}
Inplace() { IsInPlaceAct("exp") }

in Python, we expose IsInPlaceAct() as core._is_in_place_act()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -511,6 +512,9 @@ All parameter, weight, gradient are variables in Paddle.
self.back().set_lod(t.lod());
});

m.def("IsInplace",
Copy link
Contributor

Choose a reason for hiding this comment

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

You can do that as a follow up, it seems the python style is is_in_place().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function bind c++ and Python, I thought that we should follow the c++ style where it been defined.

return
self.check_grad(['X'], 'Out', max_relative_error=0.007)
# the gradient on floor, ceil, round is undefined.
# we return zero as gradient, but the numpy return nan
Copy link
Contributor

Choose a reason for hiding this comment

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

Something to consider in the future
returning None or Nan might be preferred since it avoids constructing a large zero tensor, saving some time and space.

Just curious, why it works before this PR?

@@ -163,7 +163,12 @@ function(op_library TARGET)

# pybind USE_OP
if (${pybind_flag} EQUAL 0)
# NOTE(*): activation use macro to regist the kernels, set use_op manually.
if(${TARGET} STREQUAL "activation")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hopefully, we can remove this hard-coded "activation" and "relu" strings in the cmake files the future.

Add a TODO to clean up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. The CMakeLists in operators need a clean up, will file a PR do this later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In-place Operations
3 participants