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

Infiltrating package functions. #80

Closed
fpartl opened this issue Jul 26, 2022 · 14 comments
Closed

Infiltrating package functions. #80

fpartl opened this issue Jul 26, 2022 · 14 comments

Comments

@fpartl
Copy link

fpartl commented Jul 26, 2022

Hello,

I am trying to debug one of the function from my VAEs package. I have Infiltrator.jl and Revise.jl added to my main environment @v1.7. For debugging purposes I am running this code in VAEs environment (default active environment in VS Code). What does the message "Cannot infiltrate while the REPL is idle. This typically..." means?

(VAEs) pkg> st
     Project VAEs v0.1.0
      Status `~/.julia/dev/VAEs/Project.toml`
  [052768ef] CUDA v3.12.0
  [587475ba] Flux v0.13.4

julia> using Revise

julia> using Infiltrator

julia> using VAEs
[ Info: Precompiling VAEs [986d28bc-f63f-40d7-9091-9de846b66fef]
┌ Warning: Package VAEs does not have Infiltrator in its dependencies:- If you have VAEs checked out for development and have
│   added Infiltrator as a dependency but haven't updated your primary
│   environment's manifest file, try `Pkg.resolve()`.
│ - Otherwise you may need to report an issue with VAEs
└ Loading Infiltrator into VAEs from project dependency, future warnings for VAEs are suppressed.

julia> using Flux

julia> xsize, ysize, seqsize, batch = 10, 20, 3, 6
(10, 20, 3, 6)

julia> bilstm = BiRecur(Flux.LSTM, xsize, ysize)
WARNING: both Losses and NNlib export "ctc_loss"; uses of it in module Flux must be qualified
BiRecur(Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, 10, 20)

julia> x₁ = rand(Float32, xsize, seqsize, batch); size(x₁)
(10, 3, 6)

julia> ŷ₁ = bilstm(x₁);
Running Union version of BiRecur(Array{Float32, 3}) with size(x) = (10, 3, 6)
Running Vector version of BiRecur(Vector{SubArray{Float32, 2, Array{Float32, 3}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64, Base.Slice{Base.OneTo{Int64}}}, false}}) with size(x[begin]) = (10, 6)
Cannot infiltrate while the REPL is idle. This typically happens when an async task is running in the background.
Disabling infiltration point at (::BiRecur{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}})(x::Vector{SubArray{Float32, 2, Array{Float32, 3}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64, Base.Slice{Base.OneTo{Int64}}}, false}}) at BiRecur.jl:56.

Here is the status of my @v1.7 environment.

(VAEs) pkg> activate
  Activating project at `~/.julia/environments/v1.7`

(@v1.7) pkg> st
      Status `~/.julia/environments/v1.7/Project.toml`
  [6e4b80f9] BenchmarkTools v1.3.1
  [31a5f54b] Debugger v0.7.6
  [5903a43b] Infiltrator v1.5.0
  [295af30f] Revise v3.3.4
  [986d28bc] VAEs v0.1.0 `~/.julia/dev/VAEs`

And here is the debug function.

using Infiltrator

...

function (b::BiRecur)(x::AbstractVector{T}) where {T <: AbstractVecOrMat{Float32}}
    println("Running Vector version of BiRecur($(typeof(x))) with size(x[begin]) = $(size(x[begin]))")

    fw = [b.fw(s) for s  x]
    bw = Flux.flip(b.bw, x)
    result = cat.(fw, bw, dims=1)

    @infiltrate # Cannot infiltrate while the REPL is idle.

    return result
end

Basically I do not know the right workflow for package development (debugging). I can use debugger built in the VS Code but in my case I need the only sizes of my tensors and debugger gives me too much irrelevant and confusing informations.

@pfitzseb
Copy link
Member

pfitzseb commented Jul 27, 2022

Impossible to say what's going on without a MWE. This does look like a false positive though.

Technically, I'm only checking whether Base.active_repl_backend.in_eval is true or not; you can circumvent that check by setting Infiltrator.CHECK_TASK[] = false and see if that works.

Aside: I'd recommend not loading Infiltrator in your package; instead load it at the REPL and use Main.@infiltrate in your package via Revise.

@fpartl
Copy link
Author

fpartl commented Jul 27, 2022

It works with Infiltrator.CHECK_TASK[] = false. I'll try to create some MWE. ;-)

Aside: When I use just Main.@infiltrate without using Infiltrator my package can't be precompiled. With this solution it works but it is a little bit chatty for my taste. :-)

if isdefined(Main, :Infiltrator)
    Main.infiltrate(@__MODULE__, Base.@locals, @__FILE__, @__LINE__)
end

@pfitzseb
Copy link
Member

Right, that's why I suggested only adding @infiltrate after the package is already loaded :)

@pfitzseb
Copy link
Member

Re MWE: If you can share VAEs.jl then I can work with that :)

@fpartl
Copy link
Author

fpartl commented Jul 27, 2022

VAEs.jl is total mess... rather try this. Run the ./test/mwe.jl file. ;-)

@pfitzseb
Copy link
Member

julia> using Revise

julia> using Infiltrator

julia> using InfiltratorMWE

julia> using Flux

julia> # Infiltrator.CHECK_TASK[] = false

       xsize, ysize, batch = 10, 20, 6
(10, 20, 6)

julia> cell = CrazyRNNCell(Flux.LSTM, xsize, ysize)
WARNING: both Losses and NNlib export "ctc_loss"; uses of it in module Flux must be qualified
CrazyRNNCell(Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, 10, 40)

julia> x = rand(Float32, xsize, batch)
10×6 Matrix{Float32}:
 0.528503   0.00164235  0.0748651  0.0936595  0.482486  0.000504434
 0.339793   0.768868    0.658447   0.585099   0.136515  0.73854
 0.0926465  0.869227    0.870997   0.675454   0.147139  0.164868
 0.507805   0.950567    0.935592   0.675728   0.967071  0.576838
 0.47404    0.298015    0.784961   0.479873   0.443843  0.421045
 0.102862   0.196318    0.700858   0.908191   0.323899  0.230969
 0.167544   0.41923     0.261201   0.649286   0.79906   0.243012
 0.282973   0.282155    0.306425   0.797724   0.366297  0.112101
 0.512463   0.466117    0.0114826  0.289244   0.402586  0.0258904
 0.759036   0.627821    0.601763   0.883049   0.605143  0.870425

julia> y = cell(x); # And voilà!
Infiltrating (::CrazyRNNCell{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}})(x::Matrix{Float32})
  at /home/pfitzseb/.julia/dev/InfiltratorMWE/src/CrazyRNNCell.jl:31

infil> @trace
[1] (::CrazyRNNCell{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}})(x::Matrix{Float32})
    at /home/pfitzseb/.julia/dev/InfiltratorMWE/src/CrazyRNNCell.jl:31
[2] top-level scope

infil>

works fine for me. What Julia version/OS are you on?

@fpartl
Copy link
Author

fpartl commented Jul 27, 2022

Oh... come on! :-D

julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_PKG_USE_CLI_GIT = true
  JULIA_NUM_THREADS = 8

obrazek

@pfitzseb
Copy link
Member

Do you have anything in your startup.jl (like e.g. OhMyREPL)?

@fpartl
Copy link
Author

fpartl commented Jul 28, 2022

No, it is empty.

@pfitzseb
Copy link
Member

Just to confirm. Did you use inline evaluation (Ctrl+Enter) for that or copy-paste it into the REPL?

@fpartl
Copy link
Author

fpartl commented Jul 28, 2022

Inline, is it a problem?

Oh I see... copy-paste works.

@pfitzseb
Copy link
Member

Yes, as per the readme:

Running code that ends up triggering the @infiltrate REPL mode via inline evaluation in VSCode or Juno can cause issues, so it's recommended to always use the REPL directly.

I'll add some more info to the error message :)

@fpartl
Copy link
Author

fpartl commented Jul 28, 2022

My bad. Sorry and thank you! 👍

@pfitzseb
Copy link
Member

1.6 will have an updated error message:
image

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

No branches or pull requests

2 participants