How do I save a TunedModel with MLJ? DeterministicTunedModel has no field artifact_location

I want to train a self tuning model with MLJ. I set up my model, it trains, but when I want to save the machine, I get the error message that
DeterministicTunedModel has no field artifact_location.
Any idea how to solve it?

using MLJ
using MLJTuning
using XGBoost
using MLJXGBoostInterface
using DataFrames

XGBR = MLJ.@load XGBoostRegressor pkg=XGBoost
xgboost = XGBR(num_round = 20)

r_depth = range(xgboost, :max_depth, lower = 1, upper = 10)

self_tuning_xgboost = TunedModel(
        model = xgboost,
        tuning = Grid(resolution = 2),
        resampling = CV(nfolds = 5),
        measure = rms,
        acceleration = CPUThreads(),
        range = r_depth

x = DataFrame(a = rand(1000), b = rand(1000))
y = rand(1000)

machxgb = machine(self_tuning_xgboost, x, y)
fit!(machxgb)"/path/to/file", machxgb)

I have tried it with both XGBoost/MLJXGBoostInterface and EvoTrees, and for both I get the same error.

Here is the full message.

ERROR: type DeterministicTunedModel has no field artifact_location
 [1] getproperty
   @ ./Base.jl:37 [inlined]
 [2] save(logger::MLJTuning.DeterministicTunedModel{Grid, XGBoostRegressor}, machine::Machine{XGBoostRegressor, true})
   @ MLJFlow ~/.julia/packages/MLJFlow/AAdc1/src/base.jl:29
 [3] serializable(mach::Machine{…}, model::MLJTuning.DeterministicTunedModel{…}; verbosity::Int64)
   @ MLJBase ~/.julia/packages/MLJBase/eCnWm/src/machines.jl:988
 [4] serializable (repeats 2 times)
   @ MLJBase ~/.julia/packages/MLJBase/eCnWm/src/machines.jl:978 [inlined]
 [5] save(file::String, mach::Machine{MLJTuning.DeterministicTunedModel{Grid, XGBoostRegressor}, false})
   @ MLJBase ~/.julia/packages/MLJBase/eCnWm/src/machines.jl:1082
 [6] top-level scope
   @ REPL[31]:1

Thanks @niltsz for flagging!

I suspect this is the culprit: Method ambiguity (due to type piracy) in extension of `` · Issue #37 · JuliaAI/MLJFlow.jl · GitHub , recently exposed by an unrelated fix to MLJTuning (ironically, to make save work for XGBoost atomic models).

Working on a fix.

According to my tests, this pending release of MLJ resolves the issue if you use latest versions of dependencies (in particular you need at least MLJFlow 0.4.1).

@niltsz Be great if you can independently confirm the fix.

Yes, I can confirm that it works.
Thank you very much for that super quick fix

1 Like