Skip to content

rand! without rng falls-back to sampler interface #1446

@avik-pal

Description

@avik-pal
julia> function rand_on_device()
           x = Reactant.Ops.fill(0.0f0, (3, 4, 5))
           rand!(x)
           return x
       end
rand_on_device (generic function with 1 method)

julia> @code_hlo rand_on_device()
ERROR: MethodError: no method matching Random.Sampler(::Type{Reactant.ReactantRNG{…}}, ::Random.SamplerType{Reactant.TracedRNumber{…}}, ::Val{1})
This error has been manually thrown, explicitly, so the method may exist but be intentionally marked as unimplemented.

Closest candidates are:
  Random.Sampler(::Type{<:AbstractRNG}, ::Random.Sampler, ::Union{Val{1}, Val{Inf}})
   @ Random ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:147
  Random.Sampler(::Type{<:AbstractRNG}, ::Any, ::Union{Val{1}, Val{Inf}})
   @ Random ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:183
  Random.Sampler(::Type{<:AbstractRNG}, ::BitSet, ::Union{Val{1}, Val{Inf}})
   @ Random ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/generation.jl:488
  ...

Stacktrace:
  [1] Sampler
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:147 [inlined]
  [2] Random.Sampler(none::Type{Reactant.ReactantRNG{Reactant.TracedRArray{UInt64, 1}}}, none::Random.SamplerType{Reactant.TracedRNumber{Float32}}, none::Val{1})
    @ Reactant ./<missing>:0
  [3] Sampler
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:147 [inlined]
  [4] call_with_reactant(::Reactant.MustThrowError, ::Type{Random.Sampler}, ::Type{Reactant.ReactantRNG{Reactant.TracedRArray{UInt64, 1}}}, ::Random.SamplerType{Reactant.TracedRNumber{Float32}}, ::Val{1})
    @ Reactant /mnt/software/lux/Reactant.jl/src/utils.jl:0
  [5] Sampler
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:141 [inlined]
  [6] Random.Sampler(none::Reactant.ReactantRNG{Reactant.TracedRArray{UInt64, 1}}, none::Random.SamplerType{Reactant.TracedRNumber{Float32}}, none::Val{1})
    @ Reactant ./<missing>:0
  [7] Sampler
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:141 [inlined]
  [8] call_with_reactant(::Reactant.MustThrowError, ::Type{Random.Sampler}, ::Reactant.ReactantRNG{Reactant.TracedRArray{UInt64, 1}}, ::Random.SamplerType{Reactant.TracedRNumber{Float32}}, ::Val{1})
    @ Reactant /mnt/software/lux/Reactant.jl/src/utils.jl:0
  [9] rand
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:255 [inlined]
 [10] rand(none::Reactant.ReactantRNG{Reactant.TracedRArray{UInt64, 1}}, none::Random.SamplerType{Reactant.TracedRNumber{Float32}})
    @ Reactant ./<missing>:0
 [11] rand
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:255 [inlined]
 [12] call_with_reactant(::Reactant.MustThrowError, ::typeof(rand), ::Reactant.ReactantRNG{Reactant.TracedRArray{UInt64, 1}}, ::Random.SamplerType{Reactant.TracedRNumber{Float32}})
    @ Reactant /mnt/software/lux/Reactant.jl/src/utils.jl:0
 [13] rand!
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:273 [inlined]
 [14] rand!
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:269 [inlined]
 [15] rand! (repeats 2 times)
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:266 [inlined]
 [16] rand!(none::Reactant.TracedRArray{Float32, 3})
    @ Reactant ./<missing>:0
 [17] rand! (repeats 2 times)
    @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:266 [inlined]
 [18] call_with_reactant(::typeof(rand!), ::Reactant.TracedRArray{Float32, 3})
    @ Reactant /mnt/software/lux/Reactant.jl/src/utils.jl:0
 [19] rand_on_device
    @ ./REPL[23]:3 [inlined]
 [20] rand_on_device()
    @ Reactant ./<missing>:0
 [21] fill
    @ /mnt/software/lux/Reactant.jl/src/Ops.jl:174 [inlined]
 [22] rand_on_device
    @ ./REPL[23]:2 [inlined]
 [23] call_with_reactant(redub_arguments#232::typeof(rand_on_device))
    @ Reactant /mnt/software/lux/Reactant.jl/src/utils.jl:0
 [24] make_mlir_fn(f::typeof(rand_on_device), args::Tuple{}, kwargs::@NamedTuple{}, name::String, concretein::Bool; toscalar::Bool, return_dialect::Symbol, args_in_result::Symbol, construct_function_without_args::Bool, do_transpose::Bool, input_shardings::Nothing, output_shardings::Nothing, runtime::Val{…}, verify_arg_names::Nothing, argprefix::Symbol, resprefix::Symbol, resargprefix::Symbol, num_replicas::Int64, optimize_then_pad::Bool)
    @ Reactant.TracedUtils /mnt/software/lux/Reactant.jl/src/TracedUtils.jl:330
 [25] compile_mlir!(mod::Reactant.MLIR.IR.Module, f::Function, args::Tuple{}, compile_options::CompileOptions, callcache::Dict{…}, sdycache::Dict{…}; fn_kwargs::@NamedTuple{}, backend::String, runtime::Val{…}, kwargs::@Kwargs{})
    @ Reactant.Compiler /mnt/software/lux/Reactant.jl/src/Compiler.jl:1510
 [26] compile_mlir!
    @ /mnt/software/lux/Reactant.jl/src/Compiler.jl:1478 [inlined]
 [27] (::Reactant.Compiler.var"#9#10"{Nothing, typeof(rand_on_device), Tuple{}})(ctx::Reactant.MLIR.IR.Context)
    @ Reactant.Compiler /mnt/software/lux/Reactant.jl/src/Compiler.jl:1335
 [28] with_context(f::Reactant.Compiler.var"#9#10"{Nothing, typeof(rand_on_device), Tuple{}}; allow_use_existing::Bool)
    @ Reactant.MLIR.IR /mnt/software/lux/Reactant.jl/src/mlir/IR/Context.jl:99
 [29] with_context(f::Function)
    @ Reactant.MLIR.IR /mnt/software/lux/Reactant.jl/src/mlir/IR/Context.jl:82
 [30] compile_mlir(f::Function, args::Tuple{}; client::Nothing, kwargs::@Kwargs{})
    @ Reactant.Compiler /mnt/software/lux/Reactant.jl/src/Compiler.jl:1331
 [31] top-level scope
    @ /mnt/software/lux/Reactant.jl/src/Compiler.jl:2557
 [32] top-level scope
    @ none:1
Some type information was truncated. Use `show(err)` to see complete types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions