API Client represents a low level interface for Model API. All API operation can be performed using this.
A Low-Level client for Training API
from abeja.training import APIClient
api_client = APIClient()
Archive a training job.
API reference: POST /organizations/<organization_id>/training/definitions/{job_definition_name}/jobs/{training_job_id}/archive
organization_id = "1102940376065"
job_definition_name = "test"
training_job_id = "1234567890123"
response = api_client.archive_training_job(organization_id,
job_definition_name,
training_job_id)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
training_job_id (str): TRAINING_JOB_ID
BadRequest
Unauthorized: Authentication failed
InternalServerError
archive a training job definition
API reference: POST /organizations/<organization_id>/training/definitions/{name}/archive
organization_id = "1102940376065"
job_definition_name = "test"
response = api_client.archive_training_job_definition(organization_id,
job_definition_name)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
BadRequest
Unauthorized: Authentication failed
InternalServerError
archive a training job definition version
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/versions/<version_id>/archive
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
version_id = 1
response = api_client.archive_training_job_definition_version(organization_id, job_definition_name, version_id)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
version_id (int): training job version
dict
Response Syntax:
{
"message": "archived"
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
archive a training model
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/models/<model_id>/archive
response = api_client.archive_training_model(
organization_id='1111111111111', job_definition_name='1111111111111', model_id='1111111111111')
organization_id (str): organization_id
job_definition_name (str): training job definition name
model_id (str): model_id of the requested model
dict
{
"message": "{job_definition_name}:{model_id} archived"
}
message (str) : message
NotFound: model not found
Unauthorized: Authentication failed
InternalServerError
create a training job
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/versions/<version_id>/jobs
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
version_id = 1
user_parameters = {
'BATCH_SIZE': 50
}
datasets = {
"mnist": "1111111111111"
}
response = api_client.create_training_job(
organization_id, job_definition_name, version_id, user_parameters, datasets)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
version_id (int): training job version
user_parameters (dict): (deprecated!!) user defined parameters set as environment variables. use environment
instead.
datasets (dict): [optional] datasets, combination of alias and dataset_id
instance_type (str): [optional] instance type of running environment
environment (dict): [optional] user defined parameters set as environment variables
description (str): [optional] description of this job
export_log (bool): [optional] If true
, include the log in the model.
This feature is only available with 19.04 or later images. (default: false
)
dict
Response Syntax:
{
"job_definition_id": "1443714239154",
"user_parameters": {},
"start_time": null,
"created_at": "2018-05-17T12:43:59.322367Z",
"job_definition_version": 1,
"completion_time": null,
"status": "Pending",
"instance_type": "cpu-1",
"modified_at": "2018-05-17T12:43:59.322673Z",
"training_job_id": "1443722127663",
"creator": {
"email": "test@abeja.asia",
"is_registered": true,
"created_at": "2017-05-26T01:38:46Z",
"id": "1128347408389",
"display_name": null,
"updated_at": "2018-01-04T03:02:12Z",
"role": "admin"
},
"description": null,
"statistics": null
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
create a training job definition
API reference: POST /organizations/<organization_id>/training/definitions
organization_id = "1102940376065"
job_definition_name = "test"
response = api_client.create_training_job_definition(organization_id,
job_definition_name)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
dict
Response Syntax:
{
"job_definition_id": "1443334816413",
"versions": [],
"organization_id": "1200123565071",
"modified_at": "2018-05-17T02:13:35.726812Z",
"created_at": "2018-05-17T02:13:35.726691Z",
"version_count": 0,
"name": "test"
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
create a training job definition version.
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/versions
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
filepaths = ["./requirements.txt", "./train.py"]
handler = "train:handler"
image = "abeja-inc/all-gpu:19.04"
environment = {"key": "value"}
description = "description"
response = api_client.create_training_job_definition_version(
organization_id, job_definition_name, filepaths, handler,
image=image, environment=environment, description=description)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
filepaths (list): file list to run training job
handler (str): path to handler (ex. train:handler )
image (Optional[str]): runtime environment
environment (Optional[dict]): user defined parameters set as environment variables
description (Optional[str]): description
dict
Response Syntax:
{
"job_definition_version": 1,
"user_parameters": {},
"environment": {},
"description": "description",
"datasets": {
"mnist": "1111111111111"
},
"modified_at": "2018-05-17T12:34:46.344076Z",
"job_definition_id": "1443714239154",
"handler": "train:handler",
"created_at": "2018-05-17T12:34:46.296488Z",
"image": "abeja-inc/all-gpu:19.04"
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
create a training job definition version.
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/versions
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
source_code = open("./train.zip", "rb")
handler = "train:handler"
image = "abeja-inc/all-gpu:19.04"
environment = {"key": "value"}
description = "description"
response = api_client.create_training_job_definition_version_native_api(
organization_id, job_definition_name, source_code,
parameters={"handler": handler, "image": image, "environment": environment, "description": description})
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
source_code (IO): zip or tar.gz archived file-like object to run training job
parameters (dict): parameters excluding source code to run training job
dict
Response Syntax:
{
"job_definition_version": 1,
"user_parameters": {},
"environment": {},
"description": "description",
"datasets": {
"mnist": "1111111111111"
},
"modified_at": "2018-05-17T12:34:46.344076Z",
"job_definition_id": "1443714239154",
"handler": "train:handler",
"created_at": "2018-05-17T12:34:46.296488Z",
"image": "abeja-inc/all-gpu:19.04"
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
create a training model.
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/models
organization_id = "1102940376065"
job_definition_name = 'test_job_definition'
model_data = '....'
parameters = {
"description": "description",
"user_parameters": {}
}
response = api_client.create_training_model(
organization_id, job_definition_name, model_data, parameters)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
model_data (IO): model data
training_job_id (str): The ID of a corresponding training job.
description (str): Description
user_parameters (dict): user defined parameters.
metrics (dict): user defined metrics.
dict
Response Syntax:
{
"training_model_id": "1111111111111",
"job_definition_id": "1111111111111",
"training_job_id": "1111111111111",
"user_parameters": {},
"description": "this is description of the model",
"archived": false,
"exec_env": "cloud",
"created_at": "2018-01-01T00:00:00.00000Z",
"modified_at": "2018-01-01T00:00:00.00000Z"
}
InvalidDataFormat
Unauthorized: Authentication failed
InternalServerError
delete a training job definition.
API reference: DELETE /organizations/<organization_id>/training/definitions/<job_definition_name>
organization_id = "1102940376065"
job_definition_name = 'test'
response = api_client.delete_training_job_definition(organization_id, job_definition_name)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
dict
Response Syntax:
{
"message": "test deleted"
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
delete a training job definition version
API reference: DELETE /organizations/<organization_id>/training/definitions/<job_definition_name>/versions/<version_id>
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
version_id = 1
response = api_client.delete_training_job_definition_version(organization_id, job_definition_name, version_id)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
version_id (int): training job version
dict
Response Syntax:
{
"message": "deleted"
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
download a training model
API reference: GET /organizations/<organization_id>/training/definitions/<job_definition_name>/models/<model_id>/download
response = api_client.download_training_model(
organization_id='1111111111111', job_definition_name='1111111111111', model_id='1111111111111')
organization_id (str): organization_id
job_definition_name (str): training job definition name
model_id (str): model_id of the requested model
dict
{
"download_uri": "https://..."
}
download_uri (str) : presigned download link of the training model
NotFound: model not found
Unauthorized: Authentication failed
InternalServerError
get a training job
API reference: GET /organizations/<organization_id>/training/definitions/<job_definition_name>/jobs/<training_job_id>
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
training_job_id = "1443722127663"
response = api_client.get_training_job(organization_id, job_definition_name, training_job_id)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
training_job_id (str): TRAINING_JOB_ID
dict
Response Syntax:
{
"job_definition_id": "1443714239154",
"user_parameters": {},
"start_time": null,
"created_at": "2018-05-17T12:43:59.322367Z",
"job_definition_version": 1,
"completion_time": null,
"status": "Pending",
"modified_at": "2018-05-17T12:43:59.322673Z",
"training_job_id": "1443722127663",
"archived": false,
"creator": {
"email": "test@abeja.asia",
"is_registered": true,
"created_at": "2017-05-26T01:38:46Z",
"id": "1128347408389",
"display_name": null,
"updated_at": "2018-01-04T03:02:12Z",
"role": "admin"
},
"description": null,
"statistics": null
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
get a training job definition.
API reference: GET /organizations/<organization_id>/training/definitions/<job_definition_name>
organization_id = "1102940376065"
job_definition_name = 'test'
response = api_client.get_training_job_definition(organization_id, job_definition_name)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
True
, also returns training jobs in response. By historical reason,the default value is True, but you should specify False because it degrades API performance if you have a massive amount of jobs in the target training job definition.
dict
Response Syntax:
{
"modified_at": "2018-05-17T02:13:35.726812Z",
"organization_id": "1200123565071",
"created_at": "2018-05-17T02:13:35.726691Z",
"job_definition_id": "1443334816413",
"name": "test",
"archived": false,
"versions": [],
"version_count": 0
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
get a training job definition version
API reference: GET /organizations/<organization_id>/training/definitions/<job_definition_name>/versions/<version_id>
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
version_id = 1
response = api_client.get_training_job_definition_version(organization_id, job_definition_name, version_id)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
version_id (int): training job version
dict
Response Syntax:
{
"job_definition_version": 1,
"user_parameters": {},
"datasets": {
"mnist": "1111111111111"
},
"modified_at": "2018-05-17T12:34:46.344076Z",
"job_definition_id": "1443714239154",
"handler": "train:handler",
"created_at": "2018-05-17T12:34:46.296488Z",
"image": "abeja-inc/all-gpu:19.04",
"archived": false
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
get training job definition versions.
API reference: GET /organizations/<organization_id>/training/definitions/<job_definition_name>/versions
organization_id = "1102940376065"
job_definition_name = 'test_job_definition'
response = api_client.get_training_job_definition_versions(organization_id, job_definition_name)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
filter_archived (bool): [optional] If true
, include archived jobs, otherwise exclude archived jobs. (default: false
)
dict
Response Syntax:
{
"entries": [
{
"job_definition_version": 1,
"user_parameters": {},
"datasets": {
"mnist": "1111111111111"
},
"modified_at": "2018-05-17T12:34:46.344076Z",
"job_definition_id": "1443714239154",
"handler": "train:handler",
"created_at": "2018-05-17T12:34:46.296488Z",
"image": "abeja-inc/all-gpu:19.04",
"archived": false
}
]
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
get training job definitions
API reference: GET /organizations/<organization_id>/training/definitions
organization_id = "1102940376065"
response = api_client.get_training_job_definitions(organization_id)
organization_id (str): ORGANIZATION_ID
filter_archived (bool): [optional] If true
, include archived jobs, otherwise exclude archived jobs. (default: false
)
offset (int): [optional] paging offset.
limit (int): [optional] paging limit.
dict
Response Syntax:
{
"entries": [
{
"version_count": 1,
"created_at": "2018-03-08T00:46:50.791787Z",
"organization_id": "1200123565071",
"versions": [
{
"job_definition_version": 1,
"user_parameters": {},
"handler": "train:handler",
"image": "abeja-inc/all-gpu:19.04",
"modified_at": "2018-03-08T00:48:12.207883Z",
"datasets": {
"train": "1376063797251"
},
"created_at": "2018-03-08T00:48:12.132471Z",
"job_definition_id": "1381349997580"
}
],
"name": "test",
"archived": false,
"modified_at": "2018-03-08T00:46:50.791946Z",
"job_definition_id": "1381349997580"
}
]
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
get training jobs
API reference: GET /organizations/<organization_id>/training/definitions/<job_definition_name>/jobs
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
response = api_client.get_training_jobs(organization_id, job_definition_name)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
limit (int): [optional] max number of jobs to be returned (default: 10)
offset (int): [optional] offset of jobs ( which starts from 0 )
filter_archived (bool): [optional] If true
, include archived jobs, otherwise exclude archived jobs. (default: false
)
dict
Response Syntax:
{
"entries": [
{
"user_parameters": {},
"start_time": null,
"training_job_id": "1443722127663",
"created_at": "2018-05-17T12:43:59.322367Z",
"completion_time": null,
"id": "1443722127663",
"job_definition_version": 1,
"description": null,
"statistics": null,
"job_definition_id": "1443714239154",
"modified_at": "2018-05-17T12:43:59.322673Z",
"status": "Pending",
"archived": false,
"creator": {
"email": "test@abeja.asia",
"created_at": "2017-05-26T01:38:46Z",
"id": "1128347408389",
"role": "admin",
"display_name": null,
"updated_at": "2018-01-04T03:02:12Z",
"is_registered": true
}
}
],
"limit": 10,
"offset": 0,
"total": 1
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
get a training model
API reference: GET /organizations/<organization_id>/training/definitions/<job_definition_name>/models/<model_id>
response = api_client.get_training_model(
organization_id='1111111111111', job_definition_name='1111111111111', model_id='1111111111111')
organization_id (str): organization_id
job_definition_name (str): training job definition name
model_id (str): model_id of the requested model
dict
{
"training_model_id": "1111111111111",
"job_definition_id": "1111111111111",
"training_job_id": "1111111111111",
"user_parameters": {},
"description": "this is description of the model",
"archived": false,
"exec_env": "cloud",
"archived": false,
"created_at": "2018-01-01T00:00:00.00000Z",
"modified_at": "2018-01-01T00:00:00.00000Z"
}
training_model_id (str) : training model id
job_definition_id (str) : job definition id
training_job_id (str) : training job id
user_parameters (dict): user defined parameters.
description (str) : model description.
archived (bool) : archived or not.
exec_env (enum) : Executed environment. One of [cloud, local, none].
NotFound: model not found
Unauthorized: Authentication failed
InternalServerError
Get models entries
API reference: GET /organizations/<organization_id>/training/definitions/<job_definition_name>/models
response = api_client.list_models(organization_id='1102940376065')
organization_id (str): organization_id
job_definition_name (str): training job definition name
filter_archived (bool): [optional] If true
, include archived jobs, otherwise exclude archived jobs. (default: false
)
dict
{
"entries": [
{
"training_model_id": "1111111111111",
"job_definition_id": "1111111111111",
"training_job_id": "1111111111111",
"user_parameters": {},
"description": "this is description of the model",
"archived": false,
"exec_env": "cloud",
"archived": false,
"created_at": "2018-01-01T00:00:00.00000Z",
"modified_at": "2018-01-01T00:00:00.00000Z"
}
]
}
training_model_id (str) : training model id
job_definition_id (str) : job definition id
training_job_id (str) : training job id
user_parameters (dict): user defined parameters.
description (str) : model description.
archived (bool) : archived or not.
exec_env (enum) : Executed environment. One of [cloud, local, none].
Unauthorized: Authentication failed
InternalServerError
get a training job result
API reference: GET /organizations/<organization_id>/training/definitions/<job_definition_name>/jobs/<training_job_id>/result
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
training_job_id = "1443722127663"
response = api_client.get_training_result(organization_id, job_definition_name,
training_job_id)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
training_job_id (str): TRAINING_JOB_ID
dict
Response Syntax:
{
"artifacts": {
"complete": {
"uri": "dummy_url",
}
}
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
Update a training job definition version
API reference: PATCH /organizations/<organization_id>/training/definitions/<job_definition_name>/versions/<version_id>
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
version_id = 1
response = api_client.patch_training_job_definition_version(organization_id, job_definition_name, version_id, description='new version')
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
version_id (int): training job version
description (str): description
dict
Response Syntax:
{
"job_definition_version": 1,
"user_parameters": {},
"datasets": {
"mnist": "1111111111111"
},
"modified_at": "2018-05-17T12:34:46.344076Z",
"job_definition_id": "1443714239154",
"handler": "train:handler",
"created_at": "2018-05-17T12:34:46.296488Z",
"image": "abeja-inc/all-gpu:19.04",
"archived": false
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
patch a training model
API reference: PATCH /organizations/<organization_id>/training/definitions/<job_definition_name>/models/<model_id>
response = api_client.patch_training_model(
organization_id='1111111111111', job_definition_name='1111111111111',
model_id='1111111111111', description='new description')
organization_id (str): organization_id
job_definition_name (str): training job definition name
model_id (str): model_id of the requested model
description (str): description
dict
{
"training_model_id": "1111111111111",
"job_definition_id": "1111111111111",
"training_job_id": "1111111111111",
"user_parameters": {},
"description": "this is description of the model",
"archived": false,
"exec_env": "cloud",
"created_at": "2018-01-01T00:00:00.00000Z",
"modified_at": "2018-01-01T00:00:00.00000Z"
}
training_model_id (str) : training model id
job_definition_id (str) : job definition id
training_job_id (str) : training job id
user_parameters (dict): user defined parameters.
description (str) : model description.
archived (bool) : archived or not.
exec_env (enum) : Executed environment. One of [cloud, local, none].
NotFound: model not found
Unauthorized: Authentication failed
InternalServerError
stop a training job
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/jobs/<training_job_id>/stop
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
training_job_id = "1443722127663"
response = api_client.stop_training_job(organization_id, job_definition_name, training_job_id)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
training_job_id (str): TRAINING_JOB_ID
dict
Response Syntax:
{
"message": "test_job_definition:1443722127663 stopped"
}
Unauthorized: Authentication failed
Forbidden:
InternalServerError
Archive a training job.
API reference: POST /organizations/<organization_id>/training/definitions/{job_definition_name}/jobs/{training_job_id}/unarchive
organization_id = "1102940376065"
job_definition_name = "test"
training_job_id = "1234567890123"
response = api_client.unarchive_training_job(organization_id,
job_definition_name,
training_job_id)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
training_job_id (str): TRAINING_JOB_ID
BadRequest
Unauthorized: Authentication failed
InternalServerError
unarchive a training job definition
API reference: POST /organizations/<organization_id>/training/definitions/{name}/unarchive
organization_id = "1102940376065"
job_definition_name = "test"
response = api_client.unarchive_training_job_definition(organization_id,
job_definition_name)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
BadRequest
Unauthorized: Authentication failed
InternalServerError
unarchive a training job definition version
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/versions/<version_id>/unarchive
organization_id = "1102940376065"
job_definition_name = "test_job_definition"
version_id = 1
response = api_client.unarchive_training_job_definition_version(organization_id, job_definition_name, version_id)
organization_id (str): ORGANIZATION_ID
job_definition_name (str): training job definition name
version_id (int): training job version
dict
Response Syntax:
{
"message": "unarchived"
}
BadRequest
Unauthorized: Authentication failed
InternalServerError
unarchive a training model
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/models/<model_id>/unarchive
response = api_client.unarchive_training_model(
organization_id='1111111111111', job_definition_name='1111111111111', model_id='1111111111111')
organization_id (str): organization_id
job_definition_name (str): training job definition name
model_id (str): model_id of the requested model
dict
{
"message": "{job_definition_name}:{model_id} unarchived"
}
message (str) : message
NotFound: model not found
Unauthorized: Authentication failed
InternalServerError
update a training job statistics
API reference: POST /organizations/<organization_id>/training/definitions/<job_definition_name>/jobs/<training_job_id>/statistics
from abeja.training.statistics import Statistics
statistics = Statistics(progress_percentage=0.5, epoch=1, num_epochs=5, key1='value1')
statistics.add_stage(name=Statistics.STAGE_TRAIN, accuracy=0.9, loss=0.05)
statistics.add_stage(name=Statistics.STAGE_VALIDATION, accuracy=0.8, loss=0.1, key2=2)
response = api_client.update_statistics(statistics.get_statistics())
statistics (str): statistics needs to be saved and updated
dict
Response Syntax:
{
"statistics": {
"num_epochs": 5,
"epoch": 1,
"progress_percentage": 0.5,
"stages": {
"train": {
"accuracy": 0.9,
"loss": 0.05
},
"validation": {
"accuracy": 0.8,
"loss": 0.1,
"key2": 2
}
},
"key1": "value1"
}
}
BadRequest
Unauthorized: Authentication failed
InternalServerError