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

Multithreading option not working #27

Closed
ablaom opened this issue Mar 9, 2023 · 0 comments · Fixed by #34
Closed

Multithreading option not working #27

ablaom opened this issue Mar 9, 2023 · 0 comments · Fixed by #34
Assignees
Labels
bug Something isn't working

Comments

@ablaom
Copy link
Member

ablaom commented Mar 9, 2023

The code below works fine if acceleration option is omitted.

using MLJ # or `MLJBase, MLJModels, MLJEnsembles` for minimal install

DecisionTreeClassifier = @iload DecisionTreeClassifier pkg=DecisionTree

atom = DecisionTreeClassifier()
model = EnsembleModel(
    atom;
    bagging_fraction=0.6,
    rng=123,
    acceleration=CPUThreads(),
    out_of_bag_measure = [log_loss, accuracy],
)

X, y = @load_iris # a table and a vector

julia> mach = machine(model, X, y) |> fit!
[ Info: Training machine(ProbabilisticEnsembleModel(model = DecisionTreeClassifier(max_depth = -1, ), ), ).
Ensemble-building in parallel on 5 threads.
┌ Error: Problem fitting the machine machine(ProbabilisticEnsembleModel(model = DecisionTreeClassifier(max_depth = -1, ), ), ). 
└ @ MLJBase ~/MLJ/MLJBase/src/machines.jl:682
[ Info: Running type checks... 
[ Info: Type checks okay. 
ERROR: TaskFailedException
Stacktrace:
  [1] wait
    @ ./task.jl:345 [inlined]
  [2] threading_run(fun::MLJEnsembles.var"#170#threadsfor_fun#29"{MLJEnsembles.var"#170#threadsfor_fun#28#30"{typeof(MLJEnsembles.get_ensemble_and_indices), Vector{Any}, Int64, Int64, Tuple{Matrix{Float64}, Vector{UInt32}, Vector{Symbol}, CategoricalArrays.CategoricalVector{String, UInt32, String, CategoricalArrays.CategoricalValue{String, UInt32}, Union{}}}, ProgressMeter.Progress, Random.MersenneTwister, Int64, Int64, MLJDecisionTreeInterface.DecisionTreeClassifier, UnitRange{Int64}}}, static::Bool)
    @ Base.Threads ./threadingconstructs.jl:38
  [3] macro expansion
    @ ./threadingconstructs.jl:89 [inlined]
  [4] _fit(res::CPUThreads{Nothing}, func::Function, verbosity::Int64, stuff::Tuple{MLJDecisionTreeInterface.DecisionTreeClassifier, Int64, Int64, Int64, Random.MersenneTwister, ProgressMeter.Progress, Tuple{Matrix{Float64}, Vector{UInt32}, Vector{Symbol}, CategoricalArrays.CategoricalVector{String, UInt32, String, CategoricalArrays.CategoricalValue{String, UInt32}, Union{}}}})                                                                               
    @ MLJEnsembles ~/.julia/packages/MLJEnsembles/NtgQL/src/ensembles.jl:414
  [5] fit(::MLJEnsembles.ProbabilisticEnsembleModel{MLJDecisionTreeInterface.DecisionTreeClassifier}, ::Int64, ::NamedTuple{(:sepal_length, :sepal_width, :petal_length, :petal_width), NTuple{4, Vector{Float64}}}, ::CategoricalArrays.CategoricalVector{String, UInt32, String, CategoricalArrays.CategoricalValue{String, UInt32}, Union{}})      
    @ MLJEnsembles ~/.julia/packages/MLJEnsembles/NtgQL/src/ensembles.jl:476
  [6] fit_only!(mach::Machine{MLJEnsembles.ProbabilisticEnsembleModel{MLJDecisionTreeInterface.DecisionTreeClassifier}, true}; rows::Nothing, verbosity::Int64, force::Bool, composite::
Nothing)                                                                                   
    @ MLJBase ~/MLJ/MLJBase/src/machines.jl:680
  [7] fit_only!
    @ ~/MLJ/MLJBase/src/machines.jl:606 [inlined]
  [8] #fit!#63
    @ ~/MLJ/MLJBase/src/machines.jl:778 [inlined]
  [9] fit!
    @ ~/MLJ/MLJBase/src/machines.jl:775 [inlined]
 [10] |>(x::Machine{MLJEnsembles.ProbabilisticEnsembleModel{MLJDecisionTreeInterface.DecisionTreeClassifier}, true}, f::typeof(fit!))
    @ Base ./operators.jl:911
 [11] top-level scope
    @ REPL[31]:1

    nested task error: AssertionError: length(ints) == 501
    Stacktrace:
      [1] mt_setfull!(r::Random.MersenneTwister, #unused#::Type{UInt64})
        @ Random /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Random/src/RNGs.jl:226
      [2] reserve1
        @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Random/src/RNGs.jl:257 [inlined]
      [3] mt_pop!
        @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Random/src/RNGs.jl:262 [inlined]
      [4] rand
        @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Random/src/RNGs.jl:419 [inlined]
      [5] rand
        @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Random/src/Random.jl:257 [inlined]
      [6] rand(rng::Random.MersenneTwister, sp::Random.SamplerRangeNDL{UInt64, Int64})
        @ Random /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Random/src/generation.jl:344
      [7] rand
        @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Random/src/Random.jl:254 [inlined]
      [8] fisher_yates_sample!(rng::Random.MersenneTwister, a::UnitRange{Int64}, x::Vector{Int64})                                                                                    
        @ StatsBase ~/.julia/packages/StatsBase/XgjIN/src/sampling.jl:199
      [9] sample!(rng::Random.MersenneTwister, a::UnitRange{Int64}, x::Vector{Int64}; replace::Bool, ordered::Bool)                                                               
        @ StatsBase ~/.julia/packages/StatsBase/XgjIN/src/sampling.jl:484
     [10] #sample#207
        @ ~/.julia/packages/StatsBase/XgjIN/src/sampling.jl:511 [inlined]
     [11] #15
        @ ./none:0 [inlined]
     [12] iterate
        @ ./generator.jl:47 [inlined]
     [13] collect_to!
        @ ./array.jl:845 [inlined]
     [14] collect_to_with_first!
        @ ./array.jl:823 [inlined]
     [15] collect(itr::Base.Generator{UnitRange{Int64}, MLJEnsembles.var"#15#17"{Int64, Int64, Random.MersenneTwister}})         
        @ Base ./array.jl:797
     [16] get_ensemble_and_indices
        @ ~/.julia/packages/MLJEnsembles/NtgQL/src/ensembles.jl:153 [inlined]
     [17] macro expansion
        @ ~/.julia/packages/MLJEnsembles/NtgQL/src/ensembles.jl:416 [inlined]
     [18] (::MLJEnsembles.var"#170#threadsfor_fun#29"{MLJEnsembles.var"#170#threadsfor_fun#28#30"{typeof(MLJEnsembles.get_ensemble_and_indices), Vector{Any}, Int64, Int64, Tuple{Matrix{Float64}, Vector{UInt32}, Vector{Symbol}, CategoricalArrays.CategoricalVector{String, UInt32, String, CategoricalArrays.CategoricalValue{String, UInt32}, Union{}}}, ProgressMeter.Progress, Random.MersenneTwister, Int64, Int64, MLJDecisionTreeInterface.DecisionTreeClassifier, UnitRange{Int64}}})(tid::Int64; onethread::Bool)
        @ MLJEnsembles ./threadingconstructs.jl:84
     [19] #170#threadsfor_fun
        @ ./threadingconstructs.jl:51 [inlined]
     [20] (::Base.Threads.var"#1#2"{MLJEnsembles.var"#170#threadsfor_fun#29"{MLJEnsembles.var"#170#threadsfor_fun#28#30"{typeof(MLJEnsembles.get_ensemble_and_indices), Vector{Any}, Int64, Int64, Tuple{Matrix{Float64}, Vector{UInt32}, Vector{Symbol}, CategoricalArrays.CategoricalVector{String, UInt32, String, CategoricalArrays.CategoricalValue{String, UInt32}, Union{}}}, ProgressMeter.Progress, Random.MersenneTwister, Int64, Int64, MLJDecisionTreeInterface.DecisionTreeClassifier, UnitRange{Int64}}}, Int64})()
        @ Base.Threads ./threadingconstructs.jl:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants