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

Silent failure differentiating ClassicalOrthogonalPolynomials.jl #1440

Closed
lxvm opened this issue Jul 12, 2023 · 2 comments
Closed

Silent failure differentiating ClassicalOrthogonalPolynomials.jl #1440

lxvm opened this issue Jul 12, 2023 · 2 comments

Comments

@lxvm
Copy link
Contributor

lxvm commented Jul 12, 2023

Hi,

I was trying to differentiate the hermiteh polynomial from ClassicalOrthogonalPolynomials.jl using Zygote.gradient and I saw that Zygote hung, started consuming a lot of memory, and then the Julia instance was terminated by the OS. Since there was no error message I am not sure what to investigate. I am attaching my environment information:

pkg> status Zygote ClassicalOrthogonalPolynomials
Status `/tmp/jl_aeo7Zi/Project.toml`
  [b30e2e7b] ClassicalOrthogonalPolynomials v0.10.1
  [e88e6eb3] Zygote v0.6.62

julia> versioninfo()
Julia Version 1.9.2
Commit e4ee485e909 (2023-07-05 09:39 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
  Threads: 1 on 12 virtual cores
Environment:
  LD_PRELOAD = /usr/lib/x86_64-linux-gnu/libstdc++.so.6
  JULIA_IMAGE_THREADS = 1

This is the MWE

julia> using ClassicalOrthogonalPolynomials, Zygote
 
julia> gradient(x -> hermiteh(3, x), 0.5)
@ToucheSir
Copy link
Member

I have no understanding of anything related to that package, but calling hermiteh(1, x) doesn't run out of memory and still takes forever to run. The proximal Zygote code failing is https://github.com/FluxML/Zygote.jl/blob/master/src/lib/array.jl#L36, which looks innocent enough. But from Ctrl+C interrupting and profiling, I see it gets stuck on https://github.com/JuliaApproximation/ClassicalOrthogonalPolynomials.jl/blob/02fbe50d44d43d9634acd1151585d187277090c9/src/classical/hermite.jl#L47. I suspect it's trying to sum an infinite array, hence the hang.

Evidently the internals of ClassicalOrthogonalPolynomials are not that AD-friendly. I would recommend either trying different AD libraries or writing AD rules using ChainRulesCore for it. Asking Zygote to handle infinite-length arrays is probably too much!

@lxvm
Copy link
Contributor Author

lxvm commented Jul 12, 2023

I see! Thank you for finding the infinite-length array that can't be summed. I'll write a rrule using the recurrence relations described here

@lxvm lxvm closed this as completed Jul 12, 2023
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

No branches or pull requests

2 participants