# Ray MLflow Callback for nested trials

**URL:** <https://discuss.ray.io/t/ray-mlflow-callback-for-nested-trials/9762>\
**Category:** Checkpointing, Restoring\
**Created:** [March 14, 2023, 10:32pm UTC](https://discuss.ray.io/t/ray-mlflow-callback-for-nested-trials/9762 "2023-03-14T22:32:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saivivek15](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/saivivek15/32/4050_2.png) [@saivivek15](https://discuss.ray.io/u/saivivek15)\
**Post date:** [March 14, 2023, 10:32pm UTC](https://discuss.ray.io/t/ray-mlflow-callback-for-nested-trials/9762/1 "2023-03-14T22:32:55Z")

</div>

Hi Team,

I have been experiencing the below issue when I run the Population-Based Training scheduler for Ray Tune jobs. (Ray 2.0.0)

```auto
mlflow.exceptions.MlflowException: Changing param values is not allowed. Param with key='weight_decay' was already logged with value='0.2694032858904558' for run ID='5f50082291ec4f7cb3ab5692833839d5'. Attempted logging new value '0.07364522856301339'.

The cause of this error is typically due to repeated calls
to an individual run_id event logging.

Incorrect Example:
---------------------------------------
with mlflow.start_run():
    mlflow.log_param("depth", 3)
    mlflow.log_param("depth", 5)
---------------------------------------

Which will throw an MlflowException for overwriting a
logged parameter.

Correct Example:
---------------------------------------
with mlflow.start_run():
    with mlflow.start_run(nested=True):
        mlflow.log_param("depth", 3)
    with mlflow.start_run(nested=True):
        mlflow.log_param("depth", 5)
---------------------------------------

Which will create a new nested run for each individual
model and prevent parameter key collisions within the
tracking store.'

```

I’m currently using the `MLflowLoggerCallback` from `ray.air.callbacks.mlflow` to report metrics and parameters to the remote mlflow server. It does not have the nested parameter to pass it to the mlflow util inside this class that invokes `mlflow.start_run()`. I would really appreciate any help on how to pass `nested=True` for `MlflowLoggerCallback`. Please let me know if there are any alternative implementations for the same.

Thank you for your time.

Regards,  
Vivek

---

<div class="post-metadata">

**Author:** ![Jules\_Damji](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jules_damji/32/4058_2.png) [@Jules\_Damji](https://discuss.ray.io/u/Jules_Damji)\
**Post date:** [March 15, 2023, 9:31pm UTC](https://discuss.ray.io/t/ray-mlflow-callback-for-nested-trials/9762/2 "2023-03-15T21:31:17Z")

</div>

@saivivek15 Looks like this might be related to [old issue still open](https://github.com/mlflow/mlflow/issues/2446). I remember this from my days at Databricks and MLflow.

---

<div class="post-metadata">

**Author:** ![saivivek15](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/saivivek15/32/4050_2.png) [@saivivek15](https://discuss.ray.io/u/saivivek15)\
**Post date:** [March 15, 2023, 11:31pm UTC](https://discuss.ray.io/t/ray-mlflow-callback-for-nested-trials/9762/3 "2023-03-15T23:31:57Z")

</div>

Thank you @Jules_Damji for sharing the old issue. Could you please share if you have any workarounds/suggestions that you might have tried?

---

<div class="post-metadata">

**Author:** ![Jules\_Damji](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jules_damji/32/4058_2.png) [@Jules\_Damji](https://discuss.ray.io/u/Jules_Damji)\
**Post date:** [March 16, 2023, 4:51pm UTC](https://discuss.ray.io/t/ray-mlflow-callback-for-nested-trials/9762/4 "2023-03-16T16:51:57Z")

</div>

One thing you could try as workaround is salt the depth parameter. That is,

```auto
depth_id="depth" + <uniquid_id>
with mlflow.start_run():
            mlflow.log_param("depth_id", <value>)

```

That way each trail will log its unique depth\_id-parameter.
