nbox.jobs
nbox.Job
and nbox.Serve
are wrappers to the NBX-Jobs and NBX-Deploy APIs and contains staticmethods for convinience from the CLI.
datetime.now(timezone.utc)
is incorrect, use this method.
Functions
- method -
The method to use, either "job" or "serving"
- init_folder -
folder with all the relevant files or
file_path:fn_name
pair so you can use it as the entrypoint. - name -
Name of the job. Defaults to "".
- id -
ID of the job. Defaults to "".
- trigger -
If uploading a "job" trigger the job after uploading. Defaults to False.
- resource_cpu -
CPU resource. Defaults to "100m".
- resource_memory -
Memory resource. Defaults to "128Mi".
- resource_disk_size -
Disk size resource. Defaults to "3Gi".
- resource_gpu -
GPU resource. Defaults to "none".
- resource_gpu_count -
GPU count resource. Defaults to "0".
- resource_timeout -
Timeout resource. Defaults to 120_000.
- resource_max_retries -
Max retries resource. Defaults to 2.
- cron -
Cron string for scheduling. Defaults to "".
- workspace_id -
Workspace ID, if None uses the one from config. Defaults to "".
- init_kwargs -
kwargs to pass to the
init
function / class, if possible
Upload the code for a job or serving to the NBX.
Engineer's Note
This function is supposed to be exposed via CLI, you can of course make a programtic call to this as well. This is a reason why this function can keep on taking many arguments. However with greatm number of arguments comes great responsibility, ie. lots of if/else conditions. Broadly speaking this should manage all the complexity and pass along simple reduced intstructions to the underlying methods. Currently the arguments that are required in Jinja templates are packed as exe_jinja_kwargs
and we call the deploy_job
and deploy_serving
.
- name -
Name of the deployment. Defaults to "".
- id -
ID of the deployment. Defaults to "".
Get the deployment data, either by name or id
Returns:
Tuple[str, str]
: (id, name)
Print the list of deployments
- name -
Job name. Defaults to "".
- id -
Job ID. Defaults to "".
- remove_archived -
If True, will remove archived jobs. Defaults to True.
Returns the job id and name
Returns:
Tuple[str, str]
: Job ID, Job Name
Get list of jobs
Classes
- hour -
Hour of the day, if only this value is passed it will run every
hour
- minute -
Minute of the hour, if only this value is passed it will run every
minute
- days -
List of days (first three chars) of the week, if not passed it will run every day.
- months -
List of months (first three chars) of the year, if not passed it will run every month.
- starts -
UTC Start time of the schedule, if not passed it will start now.
- ends -
UTC End time of the schedule, if not passed it will end in 7 days.
Make scheduling natural. Uses 24-hour nomenclature.
Example:
# 4:20PM everyday
Schedule(16, 20)
# 4:20AM every friday
Schedule(4, 20, ["fri"])
# 4:20AM every friday from jan to feb
Schedule(4, 20, ["fri"], ["jan", "feb"])
# 4:20PM everyday starting in 2 days and runs for 3 days
starts = datetime.now(timezone.utc) + timedelta(days = 2) # NOTE: that time is in UTC
Schedule(16, 20, starts = starts, ends = starts + timedelta(days = 3))
# Every 1 hour
Schedule(1)
# Every 69 minutes
Schedule(minute = 69)
Get the cron string for the given schedule
Get the dictionary representation of this Schedule
Get the JobProto.Schedule object for this Schedule
- serving_id -
Serving ID. Defaults to None.
- model_id -
Model ID. Defaults to None.
Python wrapper for NBX-Serving gRPC API
- model_id -
Model ID. Defaults to None.
- workspace_id -
Workspace ID. Defaults to "".
Pin a model to the deployment
- model_id -
Model ID. Defaults to None.
- workspace_id -
Workspace ID. Defaults to "".
Pin a model to the deployment
Scale the model deployment
Get the logs of the model deployment
- job_name -
Job name. Defaults to "".
- job_id -
Job ID. Defaults to "".
Python wrapper for NBX-Jobs gRPC API, when both arguments are not passed, an unintialiased object is created.
Check if this job exists in the workspace
- job_name -
Job name
- description -
Job description. Defaults to "".
Create a new job
Returns:
Job
: Job object
Change schedule this job
Stream logs of the job, f
can be anything has a .write/.flush
methods
Delete this job
Refresh Job data
- tag -
Tag to be set in the run metadata, read in more detail before trying to use this. Defaults to "".
Manually triger this job.
Pause the execution of this job. WARNING: This will "cancel" all the scheduled runs, if present
Resume the Job with the current schedule, if provided else simlpy sets status as ACTIVE
- page -
Page number. Defaults to -1.
- sort -
Sort by. Defaults to "s_no".
- limit -
Number of runs to return. Defaults to 10.
Get runs for this job
Returns:
List[Dict]
: List of runs
- sort -
Sort by. Defaults to "created_at".
- page -
Page number. Defaults to -1.
- limit -
Number of runs to return. Defaults to 10.
Display runs for this job
Get last n runs for this job
Returns:
List[Dict]
: List of runs