clearml-docs/docs/getting_started/video_tutorials/hyperparameter_optimization.md

69 lines
6.1 KiB
Markdown
Raw Normal View History

2022-11-23 14:35:41 +00:00
---
title: Hyperparameter Optimization
description: Learn more about hyperparameter optimization.
keywords: [mlops, components, hyperparameter optimization, hyperparameter]
2022-11-23 14:35:41 +00:00
---
## Video Tutorial
<div style={{position: 'relative', overflow: 'hidden', width: '100%', paddingTop: '56.25%' }} >
<iframe style={{position: 'absolute', top: '0', left: '0', bottom: '0', right: '0', width: '100%', height: '100%'}}
src="https://www.youtube.com/embed/dLkP7y4USFg?rel=0"
2022-11-23 14:35:41 +00:00
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen"
allowfullscreen>
</iframe>
</div>
2023-01-24 09:43:07 +00:00
### Video Transcript
2023-01-12 14:57:08 +00:00
Hello and welcome to ClearML. In this video well take a look at one cool way of using the agent other than rerunning a task remotely: hyperparameter optimization (HPO).
2022-11-23 14:35:41 +00:00
2022-12-26 09:08:10 +00:00
By now, we know that ClearML can easily capture our hyperparameters and scalars as part of the experiment tracking. We also know we can clone any task and change its hyperparameters, so theyll be injected into the original code at runtime. In the last video, we learnt how to make a remote machine execute this task automatically by using the agent.
2022-11-23 14:35:41 +00:00
2022-12-26 09:08:10 +00:00
Soooo… Can we just clone a task like 100 times, inject different hyperparameters in every clone, run the clones on 10 agents and then sort the results based on a specific scalar?
2022-11-23 14:35:41 +00:00
Yeah, yeah we can, it's called hyperparameter optimization. And we can do all of this automatically too! No way you were going to clone and edit those 100 tasks yourself, right?
2022-11-23 14:35:41 +00:00
If you dont know what Hyperparameter Optimization is yet, you can find a link to our blog post on the topic in the description below. But in its most basic form, hyperparameter optimization tries to optimize a certain output by changing a set of inputs.
2023-01-24 09:43:07 +00:00
Lets say weve been working on this model here, and we were tracking our experiments with it anyway. We can see we have some hyperparameters to work with in the **Hyperparameters** tab of the web UI. They are logged by using the `task.connect` function in our code. These are our inputs. We also have a scaler called `validation/epoch_accuracy`, that we want to get as high as possible. This is our output. We could also select to minimize the `epoch_loss` for example, that is something you can decide yourself.
2022-11-23 14:35:41 +00:00
We can see that no code was used to log the scalar. It's done automatically because we are using TensorBoard.
2022-11-23 14:35:41 +00:00
We are using a training script as our task in our example here, but the optimizer doesnt actually care whats in our task, it just wants inputs and outputs. So you can optimize basically anything you want.
The only thing we have to do to start optimizing this model is to write a small python file detailing what exactly we want our optimizer to do.
When youre a ClearML Pro user, you can just start the optimizer straight from the UI, but more on that later.
2022-11-23 14:35:41 +00:00
First of all, everything in ClearML is a task. The optimizer itself is one too, so we let the server know that, by using the `task_type` argument.
2022-11-23 14:35:41 +00:00
Next, we choose which task we want to optimize by providing its ID.
Now the optimizer needs its inputs and outputs. For the inputs, we can tell it to choose a parameter either from a discrete list of options, or within certain boundaries. The name of the hyperparameter consists of the section its reported to, followed by a slash and then its name.
2022-11-23 14:35:41 +00:00
For the outputs, we tell the optimizer what the scalar is that we want to optimize. You can find the necessary information in your original task, under scalars. The metric title is the title of the plot, the metric series is the trace, and the sign is whether we want to minimize or maximize this scalar.
2022-11-23 14:35:41 +00:00
There are many more parameters that you can tune, but if you want to go deeper, check out our other HPO blogpost on the website and in the description.
Thats it! With just a few lines of code, we can optimize a task. If we take a look now at the experiment list, we can see that both our optimizer task and our different clones are showing up here. Each clone is using the same code as the original task, but with different hyperparameters injected.
And thats really cool! Instead of inserting the HPO process in our original code, like you would do with most optimization libraries, weve now put it on top of it instead. So we can keep our code completely separate from the optimization process. Which, again, means we can optimize anything we want.
2023-01-24 09:43:07 +00:00
We can now follow the progress of our optimization process by looking at the optimizer task under the **Plots** section. Here we can see several interesting things happening.
2022-11-23 14:35:41 +00:00
Every point in this graph is a task, or a single run of your code using a specific hyperparameter configuration. It will give you a quick glimpse into how all tasks are performing.
The next graph is a really cool one, designed to give you some intuition on what parameters ranges are good and which parameters have the most impact on the final outcome. For example here we can clearly see that the adam optimizer is much better for our task than the sgd optimizer.
Then we have the table, which is a sorted list of all tasks with their objective value, parameter combinations and current status.
As we saw earlier, if youre a ClearML pro user, you can even launch your optimizer straight from the UI, no optimizer script required, and you get a nicer overview dashboard included. This means you can optimize your tasks literally in a minute.
2022-11-23 14:35:41 +00:00
And dont forget about autoscaling! You can run it for free using code of course, but with ClearML Pro you can set it up in the UI as well. Which means that, starting from scratch, you can have an autoscaling cluster of cloud VMs running hyperparameter optimization on your experiment tasks in just a few minutes. How cool is that?
2022-11-23 14:35:41 +00:00
2023-01-24 09:43:07 +00:00
In the next video, well take a look at another example of automation goodness: pipelines. In the meantime, why not try and optimize one of your existing models for free at [app.clear.ml](https://app.clear.ml), and dont forget to join our [Slack Channel](https://join.slack.com/t/clearml/shared_invite/zt-1kvcxu5hf-SRH_rmmHdLL7l2WadRJTQg), if you need any help.