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
gamma, lgamma, digamma work with GPU #294
Conversation
in order to pass tests, we should:
. |
How should I "define the derivative of trigamma(x) as poligamma(2,x)" in Knet.jl? I think that's in AutoGrad.jl isn't it? |
hmhm, looks like J=broadcast_func("polygamma")
for S in (32,64)
T = Symbol("Float$S")
F = "polygamma_impl_$S"
@eval begin
function $J(n::Int, x::KnetArray{$T})
y = similar(x)
@knet8($F,(Cint, Cint,Ptr{$T},Ptr{$T}), n, length(y), x, y)
return y
end
end
end |
We can make SpecialFunctions a requirement for AutoGrad.
…On Tue, Apr 3, 2018, 07:32 Carlo Lucibello ***@***.***> wrote:
hmhm, looks like trigamma derivative is already defined in autograd, but
poligamma(2,x) has to be defined for KnetArray
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvNpn8-AMG11-bcNUjzy7KwmRMSw6ANks5tkvtYgaJpZM4TCosn>
.
|
@xukai92 if you don't need @testset "unary" begin
broken_grads = [trigamma]
for f in unary_fns
f in broken_grads && continue
.... |
@CarloLucibello Just come back to work on this PR. I merged with master and it seems everything passes (even I didn't exclude the test as suggested by you long time ago). |
I tried this pr locally and it works fine for |
I get these errors when I include("test/unary.jl"), is this expected? Some seem to be gradcheck errors, some isapprox errors comparing with cpu for digamma and trigamma. |
I didn't get errors when I run the complete test on my local. Looking at you gist, it seems that some outputs seem to correct but still reported? E.g. (f, t, n) = (SpecialFunctions.digamma, Float64, (2, 1))
unary: Test Failed at /home/ec2-user/.julia/dev/Knet/test/unary.jl:39
Expression: isapprox(cy, Array(gy))
Evaluated: isapprox([-1.8009; -1.25649], [-1.8009; -1.25649])
Stacktrace:
[1] macro expansion at /home/ec2-user/.julia/dev/Knet/test/unary.jl:36 [inlined]
[2] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Test/src/Test.jl:1083 [inlined]
[3] top-level scope at /home/ec2-user/.julia/dev/Knet/test/unary.jl:6 PS: I'm not very familiar with Knet's test scripts. |
The isapprox errors may be due to small floating differences between the
cpu and gpu, the number of digits displayed probably does not reflect the
difference. This is not a big deal, we can call isapprox with a larger
rtol. Did include("test/unary.jl") pass on your side with all gradients
etc? (You can uncomment the @show lines to see what it is testing)
…On Sun, Sep 2, 2018 at 6:08 PM Kai Xu ***@***.***> wrote:
I didn't get errors when I run the complete test on my local. Looking at
you gist, it seems that some outputs seem to correct but still reported?
E.g.
(f, t, n) = (SpecialFunctions.digamma, Float64, (2, 1))
unary: Test Failed at /home/ec2-user/.julia/dev/Knet/test/unary.jl:39
Expression: isapprox(cy, Array(gy))
Evaluated: isapprox([-1.8009; -1.25649], [-1.8009; -1.25649])
Stacktrace:
[1] macro expansion at /home/ec2-user/.julia/dev/Knet/test/unary.jl:36 [inlined]
[2] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Test/src/Test.jl:1083 [inlined]
[3] top-level scope at /home/ec2-user/.julia/dev/Knet/test/unary.jl:6
PS: I'm not very familiar with Knet's test scripts.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvNpkLEv-Bb9C6EcTiMXMflxz3X17e4ks5uXFbHgaJpZM4TCosn>
.
|
Oh yes - I also have these errors. We should I do? |
Should I set separate |
We can fix rtol, but what about the gradient errors? They look more
serious, or do you not get them?
…On Sun, Sep 2, 2018 at 7:08 PM Kai Xu ***@***.***> wrote:
Should I set separate rtol for these functions or something?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvNphT1eKgqSqIzwHISC6w_9tMnX0mSks5uXGTmgaJpZM4TCosn>
.
|
In particular Float32 gradients for digamma/trigamma do not work for me:
|
Thanks for pointing this out. I found that I didn't implement the float and double version in two separate functions correctly. I know how to fix that in C but I don't know how to link them to the same Julia function in Suppose I have |
Seems that simply using the double version can handle both. julia> f(x) = sum(digamma.(x))
f (generic function with 1 method)
julia> rs_32 = rand(Float32, 1)
1-element Array{Float32,1}:
0.35235214
julia> grad(f)(rs_32)
1-element Array{Float32,1}:
9.129284
julia> grad(f)(ka(rs_32))
1-element KnetArray{Float32,1}:
9.129284
julia> rs_64 = rand(Float64, 1)
1-element Array{Float64,1}:
0.6063909020012128
julia> grad(f)(rs_64)
1-element Array{Float64,1}:
3.573492967407559
julia> grad(f)(ka(rs_64))
1-element KnetArray{Float64,1}:
3.573492967407558 Is it OK to do so? |
@CarloLucibello Can we merge this? |
Where is the code for the kernels coming from? We should credit the author and avoid issues with licenses. Also, it's not clear what is happening here with the 32/64 issue. Is the kernel being executed at 64 bit precision also when using float 32 knet arrays? If so, we should fix this |
It's based on https://github.com/rachtsingh/lgamma, which is again ported from https://bitbucket.org/eigen/eigen/overview. How should I cite it?
Let me try to solve this |
@@ -0,0 +1,242 @@ | |||
# Gamma family | |||
# Acknowledgement: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CarloLucibello I added a comment to acknowledge the original files. Is it OK?
include("gamma.jl") | ||
print(fp,cuda1gammafamily()) | ||
|
||
function cuda1src(f, j=f, ex="$f(xi)"; seperate_impl=false, BLK=256, THR=256) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@denizyuret I amended the cuda1src
function to support functions which have different CUDA kernel implementation for float and double. Before the kernel is assumed to be same. Does it look good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CarloLucibello This float v.s. double issues is solved by this.
@CarloLucibello I resolved the comments we had before. Please see my notes on changes. |
factorial *= (i + 1); | ||
} | ||
|
||
$T s = n % 2 == 0 ? -$one_str : $one_str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for people who wonder why we had numerical errors before: this line was coded as s = powf(-1.0, n + 1)
in the original code for float. This causes numerical errors somehow. I changed it to avoid using unnecessary power function to avoid this.
@CarloLucibello Can you take a look at the my updates and see if it's good now? Thanks! |
test/REQUIRE
Outdated
@@ -0,0 +1 @@ | |||
SpecialFunctions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need this, since SpecialFunctions is already in the REQUIRE of the package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
thanks for your patience and for the good work! |
Many thanks for your suggestions on improving codes in this PR! |
Related issues:
#290
#292
Related PR:
#291