TensorFlow Models
Interface
class Handler:
def __init__(self, tensorflow_client, config, job_spec):
"""(Required) Called once during each worker initialization. Performs
setup such as downloading/initializing the model or downloading a
vocabulary.
Args:
tensorflow_client (required): TensorFlow client which is used to
make predictions. This should be saved for use in handle_batch().
config (required): Dictionary passed from API configuration (if
specified) merged with configuration passed in with Job
Submission API. If there are conflicting keys, values in
configuration specified in Job submission takes precedence.
job_spec (optional): Dictionary containing the following fields:
"job_id": A unique ID for this job
"api_name": The name of this batch API
"config": The config that was provided in the job submission
"workers": The number of workers for this job
"total_batch_count": The total number of batches in this job
"start_time": The time that this job started
"""
self.client = tensorflow_client
# Additional initialization may be done here
def handle_batch(self, payload, batch_id):
"""(Required) Called once per batch. Preprocesses the batch payload (if
necessary), runs inference (e.g. by calling
self.client.predict(model_input)), postprocesses the inference output
(if necessary), and writes the predictions to storage (i.e. S3 or a
database, if desired).
Args:
payload (required): a batch (i.e. a list of one or more samples).
batch_id (optional): uuid assigned to this batch.
Returns:
Nothing
"""
pass
def on_job_complete(self):
"""(Optional) Called once after all batches in the job have been
processed. Performs post job completion tasks such as aggregating
results, executing web hooks, or triggering other jobs.
"""
passpredict method
predict methodSpecifying models
API spec
Single model
Multiple models
Structure
On CPU/GPU
On Inferentia
Last updated