EnzymeAD / EnzymeAD/Reactant.jl
Showing (in the REPL) a duplicated Flux model causes and error
- Dominant language
- Julia
- Stars
- 370
- Forks
- 74
- Avg merge
- 18h 47m
- Merged PRs (30d)
- 30
Description
Hello
Running the following code raises a REPL error. The duplicated model is made, but trying to show the model causes an error.
```
using cuDNN
using Reactant
using MLDataDevices
using CUDA
using Flux
using Enzyme
const gpu_dev = MLDataDevices.reactant_device()
model = Chain(Dense(28^2 => 32, sigmoid), Dense(32 => 10), softmax);
x1 = randn32(28 * 28, 1) |> gpu_dev;
y1 = [i == 3 for i in 0:9] |> gpu_dev;
dup_model = Duplicated(model)
dup_model = dup_model |> gpu_dev
```
The error :
```
julia> dup_model = dup_model |> gpu_dev
Error showing value of type Duplicated{Chain{Tuple{Dense{typeof(σ), ConcretePJRTArray{Float32, 2, 1, Reactant.Sharding.ShardInfo{Reactant.Sharding.NoSharding, Nothing}}, ConcretePJRTArray{Float32, 1, 1, Reactant.Sharding.ShardInfo{Reactant.Sharding.NoSharding, Nothing}}}, Dense{typeof(identity), ConcretePJRTArray{Float32, 2, 1, Reactant.Sharding.ShardInfo{Reactant.Sharding.NoSharding, Nothing}}, ConcretePJRTArray{Float32, 1, 1, Reactant.Sharding.ShardInfo{Reactant.Sharding.NoSharding, Nothing}}}, typeof(softmax)}}}:
SYSTEM (REPL): showing an error caused an error
ERROR: 1-element ExceptionStack:
Scalar indexing is disallowed.
Invocation of getindex(::ConcretePJRTArray, ::Vararg{Int, N}) resulted in scalar indexing of a GPU array.
This is typically caused by calling an iterating implementation of a method.
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore should be avoided.
If you want to allow scalar iteration, use `allowscalar` or `@allowscalar`
to enable scalar iteration globally or for the operations in question.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] errorscalar
@ ~/.julia/packages/GPUArraysCore/aNaXo/src/GPUArraysCore.jl:151
[3] _assertscalar(op::String, behavior::GPUArraysCore.ScalarIndexing)
@ GPUArraysCore ~/.julia/packages/GPUArraysCore/aNaXo/src/GPUArraysCore.jl:124
[4] assertscalar(op::String)
@ GPUArraysCore ~/.julia/packages/GPUArraysCore/aNaXo/src/GPUArraysCore.jl:112
[5] getindex(::ConcretePJRTArray{Float32, 2, 1, Reactant.Sharding.ShardInfo{Reactant.Sharding.NoSharding, Nothing}}, ::Int64, ::Int64)
@ Reactant ~/.julia/packages/Reactant/B1BXA/src/ConcreteRArray.jl:304
[6] _unsafe_getindex_rs
@ ./reshapedarray.jl:276 [inlined]
[7] _unsafe_getindex
@ ./reshapedarray.jl:273 [inlined]
[8] getindex
@ ./reshapedarray.jl:261 [inlined]
[9] macro expansion
@ ./multidimensional.jl:981 [inlined]
[10] macro expansion
@ ./cartesian.jl:64 [inlined]
[11] _unsafe_setindex!(::IndexCartesian, A::ConcretePJRTArray{…}, x::Base.ReshapedArray{…}, I::UnitRange{…})
@ Base ./multidimensional.jl:979
[12] _setindex!
@ ./multidimensional.jl:967 [inlined]
[13] setindex!
@ ./abstractarray.jl:1413 [inlined]
[14] _typed_vcat!(a::ConcretePJRTArray{Float32, 1, 1, Reactant.Sharding.ShardInfo{Reactant.Sharding.NoSharding, Nothing}}, V::Vector{AbstractVector})
@ Base ./abstractarray.jl:1664
[15] _typed_vcat(::Type{Float32}, V::Vector{AbstractVector})
@ Base ./abstractarray.jl:1656
[16] reduce(::typeof(vcat), A::Vector{AbstractVector})
@ Base ./abstractarray.jl:1742
[17] _flatten
@ ~/.julia/packages/Optimisers/W5seC/src/destructure.jl:76 [inlined]
[18] destructure(x::Chain{Tuple{Dense{typeof(σ), ConcretePJRTArray{…}, ConcretePJRTArray{…}}, Dense{typeof(identity), ConcretePJRTArray{…}, ConcretePJRTArray{…}}, typeof(softmax)}})
@ Optimisers ~/.julia/packages/Optimisers/W5seC/src/destructure.jl:30
[19] _show_pre_post(obj::Duplicated{Chain{Tuple{Dense{…}, Dense{…}, typeof(softmax)}}})
@ Flux ~/.julia/packages/Flux/uRn8o/src/layers/macro.jl:147
[20] _big_show(io::IO, obj::Any, indent::Int64, name::Any)
@ Flux ~/.julia/packages/Flux/uRn8o/src/layers/show.jl:29
[21] _big_show
@ ~/.julia/packages/Flux/uRn8o/src/layers/show.jl:23 [inlined]
[22] show(io::IOContext{Base.TTY}, m::MIME{Symbol("text/plain")}, x::Duplicated{Chain{Tuple{Dense{…}, Dense{…}, typeof(softmax)}}})
@ Flux ~/.julia/packages/Flux/uRn8o/src/layers/show.jl:9
[23] (::REPL.var"#68#69"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
@ REPL ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:394
[24] with_repl_linfo
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:678
[25] display
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:380
[26] display
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:399 [inlined]
[27] display
@ ./multimedia.jl:340
[28] #invokelatest#2
@ ./essentials.jl:1055 [inlined]
[29] invokelatest
@ ./essentials.jl:1052 [inlined]
[30] #72
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:437
[31] repl_backend_loop
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:361
[32] #start_repl_backend#59
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:343
[33] start_repl_backend
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:340
[34] #run_repl#76
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:500
[35] run_repl
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:486
[36] #1150
@ ./client.jl:446
[37] #invokelatest#2
@ ./essentials.jl:1055 [inlined]
[38] invokelatest
@ ./essentials.jl:1052 [inlined]
[39] run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool, color_set::Bool)
@ Base ./client.jl:430
[40] repl_main
@ ./client.jl:567 [inlined]
[41] _start()
@ Base ./client.jl:541
Stacktrace:
[1] print_response
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:446
[2] #70
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:405
[3] with_repl_linfo
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:678
[4] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
@ REPL ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:403
[5] (::REPL.var"#do_respond#100"{Bool, Bool, REPL.var"#116#134"{…}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
@ REPL ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1037
[6] #invokelatest#2
@ ./essentials.jl:1055 [inlined]
[7] invokelatest
@ ./essentials.jl:1052 [inlined]
[8] #126
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1444
[9] #invokelatest#2
@ ./essentials.jl:1055 [inlined]
[10] invokelatest
@ ./essentials.jl:1052 [inlined]
[11] #30
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:1711
[12] macro expansion
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2861 [inlined]
[13] macro expansion
@ ./lock.jl:273 [inlined]
[14] #282
@ ~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2851
Some type information was truncated. Use `show(err)` to see complete types.
```
Some useful info :
```
julia> versioninfo()
Julia Version 1.11.6
Commit 9615af0f269 (2025-07-09 12:58 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 16 × Intel(R) Xeon(R) W-11955M CPU @ 2.60GHz
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, tigerlake)
Threads: 16 default, 0 interactive, 8 GC (on 16 virtual cores)
```
```
julia> CUDA.versioninfo()
CUDA toolchain:
- runtime 13.0, artifact installation
- driver 550.163.1 for 13.0
- compiler 13.0
CUDA libraries:
- CUBLAS: 13.0.2
- CURAND: 10.4.0
- CUFFT: 12.0.0
- CUSOLVER: 12.0.4
- CUSPARSE: 12.6.3
- CUPTI: 2025.3.1 (API 130001.0.0)
- NVML: 12.0.0+550.163.1
Julia packages:
- CUDA: 5.8.3
- CUDA_Driver_jll: 13.0.1+0
- CUDA_Compiler_jll: 0.2.1+0
- CUDA_Runtime_jll: 0.19.1+0
Toolchain:
- Julia: 1.11.6
- LLVM: 16.0.6
1 device:
0: NVIDIA RTX A5000 Laptop GPU (sm_86, 89.562 MiB / 16.000 GiB available)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.