Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example to run "n" number of ML models using Polly CLI jobs
A B C job_name job_file_name
A1 B1 C1 job name 1 job_file_name1
A2 B2 C2 job name 2 job_file_name2
A3 B3 C3 job name 3 job_file_name3
A4 B4 C4 job name 4 job_file_name4
A5 B5 C5 job name 5 job_file_name5
A6 B6 C6 job name 6 job_file_name6
A7 B7 C7 job name 7 job_file_name7
A8 B8 C8 job name 8 job_file_name8
A9 B9 C9 job name 9 job_file_name9
A10 B10 C10 job name 10 job_file_name10
A11 B11 C11 job name 11 job_file_name11
A12 B12 C12 job name 12 job_file_name12
A13 B13 C13 job name 13 job_file_name13
A14 B14 C14 job name 14 job_file_name14
A15 B15 C15 job name 15 job_file_name15
A16 B16 C16 job name 16 job_file_name16
A17 B17 C17 job name 17 job_file_name17
A18 B18 C18 job name 18 job_file_name18
A19 B19 C19 job name 19 job_file_name19
import csv
import json
import os
import time
#################### TO BE CHANGED ################################
# Change this job template with the template that needs to be run #
###################################################################
sample_job_template = {
"cpu": "100m",
"memory": "64Mi",
"image": "docker/whalesay",
"tag": "latest",
"command": ["cowsay", "hello world"]
}
first = False
############################# OPTIONAL CHANGE ########################
# make the variable delete_json_after_creation True for deleting the #
# job json once job is created. By default its set to False #
######################################################################
delete_json_after_creation = False
############################# TO BE CHANGED ###########################
# change the workspace ID to a workspace in which job needs to be run #
#######################################################################
workspace_id = xxxx
with open('model_parameters.csv','rt')as f:
data = csv.reader(f)
for row in data:
if (first):
sample_job_template['env'] = {}
#################################### TO BE CHANGED ###################################
# update the environment to match the headings inside the model_parameters.csv file #
######################################################################################
sample_job_template['env']['A'] = row[0]
sample_job_template['env']['B'] = row[1]
sample_job_template['env']['C'] = row[2]
################# TO BE CHANGED ###############
# update the job name and job file name index #
###############################################
sample_job_template['name'] = row[3]
file_name = './' + row[4] + '.json'
with open(file_name, 'w') as outfile:
json.dump(sample_job_template, outfile, indent=2)
abs_file_name = os.path.abspath(file_name)
polly_command = 'polly jobs submit --workspace-id ' + str(workspace_id) + '--job-file ' + abs_file_name
print(polly_command)
################# TO BE CHANGED #####################
# uncomment line 49 to execute the commands #
#####################################################
# os.system(polly_command)
time.sleep(5)
if delete_json_after_creation:
os.remove(abs_file_name)
else:
first = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment