-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ERROR: BoundsError: attempt to access 1-element Vector{Core.LineInfoNode} at index [0] #379
Comments
I need more information to replicate this: julia> @descend gradient((m, x)->sum(sin.(m(x))), d, x)
ERROR: UndefVarError: `d` not defined
Stacktrace:
[1] top-level scope
@ REPL[5]:1 |
Ah sorry, I forgot to paste it. The complete code should be using Flux, Cthulhu
d = Dense(10, 10)
x = randn(Float32, 10, 5)
@descend gradient((m, x)->sum(sin.(m(x))), d, x) tested with julia-1.9-rc1 |
Fixes #379 It's possible that the warning will be triggered spuriously, but for now it seems better to have it.
If you Keep in mind that type-annotations will be missing in the cases where this bug was triggered. The root cause is that there's code that's missing any kind of line number annotation, and having good line numbers is crucial for this new Cthulhu mode to work. I'd guess that something in Zygote, perhaps, is generating code and not adding line info? Fixing that might help both the quality of backtraces and Cthulhu. |
The gradient code is generated with IRTools, that's probably the reason why it miss the line info. But I'm not sure if it's possible to add any kind of line info. Maybe @ToucheSir have any thought? |
Line info tracking in IRTools is a mess and trips up other tools as well (Debugger.jl notably). Since nobody around understands the logic it uses, I'm not sure what we can do short of getting rid of IRTools itself. |
If it's generating code by manually creating new julia> eval(Expr(:(=), Expr(:call, :f), Expr(:block, 1)))
f (generic function with 1 method)
julia> f()
1
julia> methods(f)
# 1 method for generic function "f" from Main:
[1] f()
@ none:0 which lacks line/file info, vs julia> eval(Expr(:(=), Expr(:call, :f), Expr(:block, LineNumberNode(55, Symbol("somefile.jl")), 1)))
f (generic function with 1 method)
julia> f()
1
julia> methods(f)
# 1 method for generic function "f" from Main:
[1] f()
@ somefile.jl:55 which has the line/file info I supplied. You need one For things that are essentially macros, it can get a little more involved (is it the location of the macro or its "caller"?). mauro3/SimpleTraits.jl#6 has an example of how you can pull this off. |
I'm afraid the answer is that it does all of the above and none of the above simultaneously! That's how we get the classic stacktraces with alternating line #0 and line numbers from the source (i.e. non transformed) function. The IRTools line handling logic is scattered all over https://github.com/FluxML/IRTools.jl/blob/8a6971e4a594d540a491cafa059942472dc86a26/src/ir/ir.jl and https://github.com/FluxML/IRTools.jl/blob/8a6971e4a594d540a491cafa059942472dc86a26/src/ir/wrap.jl, so tracking it all down would be a pain. What's more, troubleshooting line number placement or tracking provenance of |
Wow, that is a bit of a mess. I'll wish for a miracle for you, then 😉 . |
MWE:
The text was updated successfully, but these errors were encountered: