Parameterize A Job
When you develop a Python script, there are often instances where you want to alter the script’s behaviour without having to rewrite the code. This is where arguments come in handy. Arguments allow you to pass values to a script when it is executed, and these values can then be used to control the script’s behaviour.
For instance, let’s consider a script that trains a Support Vector Machine (SVM) model. Arguments can be used to pass the values of the hyper-parameters to your script as command-line arguments. This enables you to easily modify the values of the hyper-parameters without having to modify your code.
Here’s an example of how to use argparse to pass hyper-parameters to a Python script that trains an SVM model:
You can now run this script by passing the following command:
This will train the SVM model with a linear kernel and a regularisation parameter of 2.0. You can easily set the kernel type and C parameter without having to change the code repeatedly.
Configuring a Job with Params
To set up Params, follow these steps:
- Setup the params in job form. Here, you’ll provide details regarding the arguments you want to make params. You’ll need to provide the name, description, and default value for each parameter.
- In the command you specify while configuring the Job, you need to specify a command template. It will be like the following:
For example, python train.py --C {{c_val}} --kernel {{kernel}}.
Running a Job with params
Once you configure the job with params and deploy it, you will start seeing a form rendered on clicking run job.
TrueFoundry automatically generates this form based on the parameters defined in the job’s configuration. This dynamic form simplifies parameter handling, where you just need to change the values for the parameters and the command updates accordingly.