Forum Discussion
Experiments and parallel processing going wrong
- 1 year ago
Thanks for reaching out to MS Fabric community support.
Your code is mostly on track, but there are a few key changes needed to ensure the MLflow experiments and runs are correctly isolated when using ThreadPoolExecutor. Specifically, you need to make sure that:
- Each location's prediction process is contained within a separate MLflow experiment.
- The nested runs (for each iteration) are correctly managed and don't interfere with other locations.
- No shared state is accessed concurrently in a way that could cause the wrong experiment or run to be affected.
Please follow below improvements:
-
Set Experiment Properly: The call to mlflow.set_experiment(location_name) inside run_prediction_task is correct for setting a separate experiment per location. However, we need to ensure that mlflow.start_run() is executed within the context of each thread and location.
-
Unique Run Names: You're using run_name=f"Prediction_{run_timestamp}" to uniquely identify the main run. That’s great! This will ensure each location has its own main run.
-
Manage Iteration Runs: You should avoid using nested=True in the mlflow.start_run() if you want fully independent runs (and if the iteration runs don't need to be nested within the main run). If nested runs are necessary, you can keep nested=True, but the parent-child relationship between runs can sometimes lead to issues when parallelizing execution.
-
DataFrame Management: Ensure that your df_with_predictions isn't being modified by multiple threads simultaneously. Each thread should work with its own version of the data.
-
MLflow Context in Threads: Make sure that each thread correctly creates and manages its own experiment and run context.
You can find more information on managing MLflow experiments and runs in the official documentation:
Thanks,
Prashanth Are
MS Fabric community support
Thanks v-prasare. We are looking further into using NotebookUtils.notebook.RunMultiple(), as it gives us better insights in what the process was for each location in the notebook instance, by providing us a link to the notebook snaphots afterwards.
nielsvdc, Thank you for the update!
It sounds like using NotebookUtils.notebook.RunMultiple() is a great choice, especially since it provides better insights and visibility into the process for each location in the notebook instance. The ability to access notebook snapshots afterwards will definitely help with tracking and debugging.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query
Thanks,
Prashanth Are
MS Fabric community support