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

Added deprecation warning to Dense(in,out,act,initW,initb) #722

Closed

Conversation

shreyas-kowshik
Copy link
Contributor

Addresses issue #671 .
@MikeInnes is this what was needed?

@@ -72,6 +74,7 @@ Dense(W, b) = Dense(W, b, identity)

function Dense(in::Integer, out::Integer, σ = identity;
initW = glorot_uniform, initb = zeros)
depwarn("Dense(in,out,σ,initW,initb) is deprecated; use Dense(W,b) instead",:Dense)
Copy link
Contributor

@johnnychen94 johnnychen94 Mar 31, 2019

Choose a reason for hiding this comment

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

we can't just deprecate the whole method here. The tricky part is that keyword arguments are not counted in multiple dispatch.

One possible solution (not sure if it works)

  1. change initW = glorot_uniform to initW = nothing
  2. manual check before initialization
if initW is nothing
  initW = glorot_uniform;
else
  depwarn
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see...My bad...I'll fix this accordingly...

@johnnychen94
Copy link
Contributor

Looks like this strategy works.

Now you need to have a look at the codebase and deprecate other functions such as Diagonal, ConvTranspose. And don't forget to modify the testcases.

BTW, it might be useful to provide a link to #671 as a comment alongside your depwarn.

@shreyas-kowshik
Copy link
Contributor Author

I suppose that the other layers do not have this issue and this mostly pertained to the Dense layer.
Conv and ConvTranspose only have a single init in them. So I don't think that they should need deprecation.
At least this was what I could infer from #671 .
Is this all or am I getting it wrong? @MikeInnes

@johnnychen94
Copy link
Contributor

It's not about single init keyword, it's about consistency. If you deprecate init as a keyword argument, deprecate them all.

@MikeInnes
Copy link
Member

Let's get the Dense deprecation done and then do a review of other layers. I think we probably will want to get rid of all of them though.

I think the kwargs method could be defined separately. You should be able to do something like

@deprecate Dense(in::Integer, out::Integer; initW = ...) = Dense(initW(out, in), ...)

which separates the deprecated code from the new code nicely, and gives a clearer instruction to the user.

@johnnychen94
Copy link
Contributor

@MikeInnes @deprecate might not work well for keyword arguments. They don't participate in dispatch.

julia> foo(a,b;k=1) = println()
foo (generic function with 1 method)

julia> @deprecate foo(a,b;k=1) foo(a,b)
foo (generic function with 1 method)

julia> foo(1,2)
┌ Warning: `foo(a, b; k=1)` is deprecated, use `foo(a, b)` instead.
│   caller = top-level scope at none:0
└ @ Core none:0

https://github.com/JuliaDocs/Documenter.jl/blob/c59fe92f880e7acfbf2610fed0c70dc364e4c3a0/src/Documenter.jl#L473-L513 is an example of such deprecation work.

@MikeInnes
Copy link
Member

MikeInnes commented Apr 4, 2019

It actually works if you do it the other way around:

julia> @deprecate foo(a,b;k=1) foo(a,b)
foo (generic function with 1 method)

julia> foo(a,b;k=1) = println()
foo (generic function with 1 method)

julia> foo(1, 2)

But to be fair this probably still results in a method warning. Another option is to use a more specific signature for the non-deprecated method. It might be best just to stick with the if-then approach though.

@johnnychen94
Copy link
Contributor

johnnychen94 commented Apr 9, 2019

If it's all about deprecating Dense, then I think this PR is ready to merge. @MikeInnes
And it's better to add some comment to guide the future work. @shreyas-kowshik The content might be why we need to deprecate this or perhaps a single url link.

initW = glorot_uniform, initb = zeros)
initW = nothing, initb = nothing)
if initW != nothing || initb != nothing
depwarn("Dense(in,out,σ,initW,initb) is deprecated; use Dense(W,b) instead",:Dense)
Copy link
Contributor

@johnnychen94 johnnychen94 Apr 9, 2019

Choose a reason for hiding this comment

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

I think "keyword argument `initW` is deprecated; use `Dense(W,b)` to initialize" is more descriptive to the current one.

@CarloLucibello
Copy link
Member

closing as we are going in a different direction with #1440

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.

4 participants