Hyperparameter Tuning with W&B Sweeps

Weights & Biases · Intermediate ·🏭 MLOps & LLMOps ·3y ago

Key Takeaways

This video demonstrates hyperparameter tuning using Weights & Biases Sweeps, a tool for orchestrating hyperparameter optimization, and showcases how to define a sweep configuration file, launch an agent, and run multiple agents in parallel to reduce the time spent on hyperparameter exploration.

Full Transcript

hello again let's take care of the original task improving the model performance how can we make them all better and increase the intersection of a union metric in our previous video we refactored the Baseline notebook now we'll want to export everything to a train.buy script file there are multiple ways of doing this you can export every single cell by hand copy pasting them on the train.bi file or you can use a semi-automatic way like nbdev or nbconvert keep it simple I went the manual way I merge every single cell and copy paste them on the train.pi file at the end of the file you have the train function that depends on the config the only thing I have added it's a pause args functionality this enables you to override arguments on the Fly it converts your Python program into an interactive command line interface there are multiple tools to add this functionality I'm using default python Arc paths as we are using fast AI you can use the built-in call pass decorator the transform your script into a command line interface inside the environment to just call this file with python python trend.pi this way we'll run the file in the same way as you have presented on The Notebook this is not very interesting as it will run with default arcs and we already have a bunch of runs like that let's just cancel the Run using Ctrl C let's go to the workspace and see the new run that we logged there it is we can delete this partial run by clicking on the three dots as we said before we have an interactive Python program now so let's make use of that you can access the help menu by calling pythontrain.help and it will print you out all the parameters you are capable of overriding or with a different batch size let's try batch size 16 for a change you can override batch size by passing the argument name and the new value this will create a new run with batch size equals 16 overriding the default 8 let's confirm this on the workspace there it is let's click on the run and on the overview tab and scroll down to the config we can confirm that the batch size is 16 now let's also kill this run where we actually want to do is explore the hyper parameter space but we don't want to do it manually like that we want to define a way to orchestrate our hyper parameter optimization Here Comes Waits and biases sweeps our Apple parameter optimization tool with just a few lines of code on our already instrumented training script you will be running massive hyper parameter tuning in no time but how do we actually do this how do we tell weights and devices to run this code automatically this is done through a yaml configuration file first you define what script you want to run in our case train.pi second you have to define a method of exploration of the hyper parameter space we provide grid random unbiation optimization search you can refer to the weights and biases sweeps documentation to get more information about the algorithms then you have to Define which project your sweep will live in sometimes you want to use a different project to put your sweeps in to not pollute your main workspace in our case we'll use the same project as before then you define a metric to monitor in our case we want to maximize mean intersection of a union and finally you want to Define your hyper parameter space you can use these to overwrite default arguments like log predictions it is equivalent to changing the default values on the train.pi file you can use a distribution to sample continuous parameters in our case we'll sample the learning rate between the log of the mean and Max values you can also pass a list of values for discrete parameters we'll try a smaller batch size so we get more Optimizer updates as our data set is really small I had good results in the past using this trick with small data sets we'll also increase the image size a little bit this should improve the model performance on segmentation of small objects finally we'll try different image backbones these are my four favorite backbone from torch vision feel free to go to dodge Vision malls and try all the backbones there are plenty of them depending on your task and your data set you may want to try bigger malls torch Vision malls are trained regularly with state-of-the-art techniques our sweep configuration file is ready let's switch to a terminal now and start the sweep you can launch the sweep using 1db sweep and the sweep configuration file The Sweep has been created you can click the link and you will be redirected to the sweep workspace still empty but you can click on the overview Tab and see the configuration file that was used to create the sweep and you see the proposed sweep command to launch an agent this is the same command suggested on the terminal let's run this command before doing that let's check the options available for the 1db agent we see that we have a count parameter so we can limit the max number of runs per agent as we are doing random search if you don't pass any count parameter it will run forever so you'll have to kill it manually let's start by 50 runs running this command will launch the agent and you will start populating your sweep workspace with runs you can see the selected hyper parameters at the beginning of the script now we can switch to the workspace and we should see the incoming run that is you will see the plot updating automatically as more runs come in but I have an extra surprise for you I have switch machines I'm not using the same machine as we were using before this machine is equipped with two gpus you can check the available gpus on your machine using the Nvidia SMI command we see that the first GPU is being used and the second one is just sitting idle let's fix that let's open a new terminal we can override the Cuda visible device environment variable and force the code to run on the second GPU this command will create a new agent on the second GPU we will also pass a quota of 50 runs this is really powerful when you have access to large compute centers like a cluster or machines equipped with multiple gpus as you expect you can launch agents in parallel and greatly reduce the time spent performing The Sweep is we go to the workspace we see that two runs are coming in parallel great now we have two agents contributing in parallel to finish the sweep this should reduce in half the time needed to complete our hyper parameter exploration in the next video we'll explore the results of the finished sweep

Original Description

A sample of what you'll learn while getting your MLOps certification from the *free* Weights & Biases course. 📜 *Get MLOps Certified!* ➡️ http://wandb.me/free-mlops-course *About this sample:* Hyperparameter tuning is an essential part of the machine learning process, as it can significantly impact the performance of your model. It can be a tedious and manual process, requiring the testing of various combinations and the tracking of results. In this video, we demonstrate how to use Weights & Biases Sweeps to automate the hyperparameter tuning process. With Weights & Biases Sweeps, you can define the hyperparameters you want to test and the range of values for each parameter. The platform will then automatically run a series of experiments, tracking the results in real-time and providing insights into the best performing combinations. This can save time and help you quickly find the optimal hyperparameters for your model. If you want to streamline your hyperparameter tuning process, be sure to watch this video.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Weights & Biases · Weights & Biases · 0 of 60

← Previous Next →
1 0. What is machine learning?
0. What is machine learning?
Weights & Biases
2 1. Build Your First Machine Learning Model
1. Build Your First Machine Learning Model
Weights & Biases
3 Intro to ML: Course Overview
Intro to ML: Course Overview
Weights & Biases
4 2. Multi-Layer Perceptrons
2. Multi-Layer Perceptrons
Weights & Biases
5 3. Convolutional Neural Networks
3. Convolutional Neural Networks
Weights & Biases
6 Weights & Biases at OpenAI
Weights & Biases at OpenAI
Weights & Biases
7 Why Experiment Tracking is Crucial to OpenAI
Why Experiment Tracking is Crucial to OpenAI
Weights & Biases
8 4. Autoencoders
4. Autoencoders
Weights & Biases
9 5. Sentiment Analysis
5. Sentiment Analysis
Weights & Biases
10 6. Recurrent Neural Networks [RNNs]
6. Recurrent Neural Networks [RNNs]
Weights & Biases
11 7. Text Generation using LSTMs and GRUs
7. Text Generation using LSTMs and GRUs
Weights & Biases
12 8. Text Classification Using Convolutional Neural Networks
8. Text Classification Using Convolutional Neural Networks
Weights & Biases
13 9. Hybrid LSTMs [Long Short-Term Memory]
9. Hybrid LSTMs [Long Short-Term Memory]
Weights & Biases
14 Toyota Research Institute on Experiment Tracking with Weights & Biases
Toyota Research Institute on Experiment Tracking with Weights & Biases
Weights & Biases
15 Weights and Biases - Developer Tools for Deep Learning
Weights and Biases - Developer Tools for Deep Learning
Weights & Biases
16 Introducing Weights & Biases
Introducing Weights & Biases
Weights & Biases
17 10. Seq2Seq Models
10. Seq2Seq Models
Weights & Biases
18 11. Transfer Learning for Domain-Specific Image Classification with Small Datasets
11. Transfer Learning for Domain-Specific Image Classification with Small Datasets
Weights & Biases
19 12. One-shot learning for teaching neural networks to classify objects never seen before
12. One-shot learning for teaching neural networks to classify objects never seen before
Weights & Biases
20 13. Speech Recognition with Convolutional Neural Networks in Keras/TensorFlow
13. Speech Recognition with Convolutional Neural Networks in Keras/TensorFlow
Weights & Biases
21 14. Data Augmentation | Keras
14. Data Augmentation | Keras
Weights & Biases
22 15. Batch Size and Learning Rate in CNNs
15. Batch Size and Learning Rate in CNNs
Weights & Biases
23 Applied Deep Learning Fellowship Overview and Project Selection with Josh Tobin (2019)
Applied Deep Learning Fellowship Overview and Project Selection with Josh Tobin (2019)
Weights & Biases
24 Grading Rubric for AI Applications with Sergey Karayev  (2019)
Grading Rubric for AI Applications with Sergey Karayev (2019)
Weights & Biases
25 16. Video Frame Prediction using CNNs and LSTMs (2019)
16. Video Frame Prediction using CNNs and LSTMs (2019)
Weights & Biases
26 Image to LaTeX - Applied Deep Learning Fellowship (2019)
Image to LaTeX - Applied Deep Learning Fellowship (2019)
Weights & Biases
27 17.  Build and Deploy an Emotion Classifier (2019)
17. Build and Deploy an Emotion Classifier (2019)
Weights & Biases
28 Applied Deep Learning - Data Management with Josh Tobin (2019)
Applied Deep Learning - Data Management with Josh Tobin (2019)
Weights & Biases
29 Snorkel: Programming Training Data with Paroma Varma of Stanford University (2019)
Snorkel: Programming Training Data with Paroma Varma of Stanford University (2019)
Weights & Biases
30 Applied Deep Learning - Troubleshooting and Debugging with Josh Tobin (2019)
Applied Deep Learning - Troubleshooting and Debugging with Josh Tobin (2019)
Weights & Biases
31 Troubleshooting and Iterating ML Models with Lee Redden (2019)
Troubleshooting and Iterating ML Models with Lee Redden (2019)
Weights & Biases
32 Designing a Machine Learning Project with Neal Khosla (2019)
Designing a Machine Learning Project with Neal Khosla (2019)
Weights & Biases
33 Lukas Beiwald on ML Tools and Experiment Management (2019)
Lukas Beiwald on ML Tools and Experiment Management (2019)
Weights & Biases
34 Building Machine Learning Teams with Josh Tobin (2019)
Building Machine Learning Teams with Josh Tobin (2019)
Weights & Biases
35 Pieter Abeel on Potential Deep Learning Research Directions  (2019)
Pieter Abeel on Potential Deep Learning Research Directions (2019)
Weights & Biases
36 Testing and Deployment of Deep Learning Models with Josh Tobin (2019)
Testing and Deployment of Deep Learning Models with Josh Tobin (2019)
Weights & Biases
37 Five Lessons for Team-Oriented Research with Peter Welder (2019)
Five Lessons for Team-Oriented Research with Peter Welder (2019)
Weights & Biases
38 Applied Deep Learning - Rosanne Liu on AI Research (2019)
Applied Deep Learning - Rosanne Liu on AI Research (2019)
Weights & Biases
39 Making the Mid-career Leap from Urban Design to Deep Learning/Data Science
Making the Mid-career Leap from Urban Design to Deep Learning/Data Science
Weights & Biases
40 Organizing ML projects — W&B walkthrough (2020)
Organizing ML projects — W&B walkthrough (2020)
Weights & Biases
41 Brandon Rohrer — Machine Learning in Production for Robots
Brandon Rohrer — Machine Learning in Production for Robots
Weights & Biases
42 Nicolas Koumchatzky — Machine Learning in Production for Self-Driving Cars
Nicolas Koumchatzky — Machine Learning in Production for Self-Driving Cars
Weights & Biases
43 My experiments with Reinforcement Learning with Jariullah Safi
My experiments with Reinforcement Learning with Jariullah Safi
Weights & Biases
44 Applications of Machine Learning to COVID-19 Research with Isaac Godfried
Applications of Machine Learning to COVID-19 Research with Isaac Godfried
Weights & Biases
45 Testing Machine Learning Models with Eric Schles
Testing Machine Learning Models with Eric Schles
Weights & Biases
46 How Linear Algebra is not like Algebra with Charles Frye
How Linear Algebra is not like Algebra with Charles Frye
Weights & Biases
47 Predicting Protein Structures using Deep Learning with Jonathan King
Predicting Protein Structures using Deep Learning with Jonathan King
Weights & Biases
48 Rachael Tatman — Conversational AI and Linguistics
Rachael Tatman — Conversational AI and Linguistics
Weights & Biases
49 Reformer by Han Lee
Reformer by Han Lee
Weights & Biases
50 Sequence Models with Pujaa Rajan
Sequence Models with Pujaa Rajan
Weights & Biases
51 GitHub Actions & Machine Learning Workflows with Hamel Husain
GitHub Actions & Machine Learning Workflows with Hamel Husain
Weights & Biases
52 Look Mom, No Indices! Vector Calculus with the Fréchet Derivative by Charles Frye
Look Mom, No Indices! Vector Calculus with the Fréchet Derivative by Charles Frye
Weights & Biases
53 Jack Clark — Building Trustworthy AI Systems
Jack Clark — Building Trustworthy AI Systems
Weights & Biases
54 Surprising Utility of Surprise: Why ML Uses Negative Log Probabilities - Charles Frye
Surprising Utility of Surprise: Why ML Uses Negative Log Probabilities - Charles Frye
Weights & Biases
55 Track your machine learning experiments locally, with W&B Local - Chris Van Pelt
Track your machine learning experiments locally, with W&B Local - Chris Van Pelt
Weights & Biases
56 Antipatterns in open source research code with Jariullah Safi
Antipatterns in open source research code with Jariullah Safi
Weights & Biases
57 Attention for time series forecasting & COVID predictions - Isaac Godfried
Attention for time series forecasting & COVID predictions - Isaac Godfried
Weights & Biases
58 Made with ML - Goku Mohandas
Made with ML - Goku Mohandas
Weights & Biases
59 Angela & Danielle — Designing ML Models for Millions of Consumer Robots
Angela & Danielle — Designing ML Models for Millions of Consumer Robots
Weights & Biases
60 Deep Learning Salon by Weights & Biases
Deep Learning Salon by Weights & Biases
Weights & Biases

This video teaches how to use Weights & Biases Sweeps for hyperparameter tuning and how to define a sweep configuration file to orchestrate the optimization process. It also shows how to launch multiple agents in parallel to reduce the time spent on hyperparameter exploration.

Key Takeaways
  1. Export the training script to a file
  2. Add a pause args functionality to the script
  3. Define a sweep configuration file
  4. Launch an agent using the sweep configuration file
  5. Run multiple agents in parallel to reduce the time spent on hyperparameter exploration
💡 Using Weights & Biases Sweeps can greatly simplify the hyperparameter tuning process and reduce the time spent on optimization.

Related Reads

📰
Building a self-healing MLOps pipeline on AWS: from raw data to a model that fixes itself
Learn to build a self-healing MLOps pipeline on AWS that automates model fixing, increasing model reliability and reducing downtime
Medium · Machine Learning
📰
Building a self-healing MLOps pipeline on AWS: from raw data to a model that fixes itself
Learn to build a self-healing MLOps pipeline on AWS that automates model fixes, increasing model reliability and reducing downtime
Medium · DevOps
📰
qModel Open-Source Platform v1.2.0 Released: Streamlined Python Model Integration & Execution Pipeline
Learn how to streamline Python model integration and execution with qModel Open-Source Platform v1.2.0, a tool for MLOps and AI development
Dev.to AI
📰
Inference Infrastructure Best Practices for High-Traffic AI Applications
Learn best practices for building scalable inference infrastructure for high-traffic AI applications to ensure reliable and efficient deployment
Dev.to AI
Up next
Pole Pruner How A Rope Lever Shears High Branches
Innoforge Studio
Watch →