# How do I save a TunedModel with MLJ? DeterministicTunedModel has no field artifact\_location

**URL:** <https://discourse.julialang.org/t/how-do-i-save-a-tunedmodel-with-mlj-deterministictunedmodel-has-no-field-artifact-location/111307>\
**Category:** Machine Learning\
**Tags:** question, mlj\
**Created:** [March 7, 2024, 3:58pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-tunedmodel-with-mlj-deterministictunedmodel-has-no-field-artifact-location/111307 "2024-03-07T15:58:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![niltsz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niltsz/32/30060_2.png) [@niltsz](https://discourse.julialang.org/u/niltsz)\
**Post date:** [March 7, 2024, 3:58pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-tunedmodel-with-mlj-deterministictunedmodel-has-no-field-artifact-location/111307/1 "2024-03-07T15:58:50Z")

</div>

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?

```julia
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)

MLJ.save("/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.

```julia
ERROR: type DeterministicTunedModel has no field artifact_location
Stacktrace:
 [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

```

---

<div class="post-metadata">

**Author:** ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)\
**Post date:** [March 8, 2024, 3:42am UTC](https://discourse.julialang.org/t/how-do-i-save-a-tunedmodel-with-mlj-deterministictunedmodel-has-no-field-artifact-location/111307/3 "2024-03-08T03:42:12Z")

</div>

Thanks @niltsz for flagging!

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

Working on a fix.

---

<div class="post-metadata">

**Author:** ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)\
**Post date:** [March 8, 2024, 6:36am UTC](https://discourse.julialang.org/t/how-do-i-save-a-tunedmodel-with-mlj-deterministictunedmodel-has-no-field-artifact-location/111307/4 "2024-03-08T06:36:43Z")

</div>

According to my tests, [this pending release of MLJ](https://github.com/JuliaRegistries/General/pull/102512) 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.

---

<div class="post-metadata">

**Author:** ![niltsz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niltsz/32/30060_2.png) [@niltsz](https://discourse.julialang.org/u/niltsz)\
**Post date:** [March 8, 2024, 8:03am UTC](https://discourse.julialang.org/t/how-do-i-save-a-tunedmodel-with-mlj-deterministictunedmodel-has-no-field-artifact-location/111307/5 "2024-03-08T08:03:44Z")

</div>

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