Skip to content

Commit

Permalink
Print out billable seconds after training completes (#30)
Browse files Browse the repository at this point in the history
* Added: print out billable seconds after training completes

* Fixed: test_session.py to pass unit tests

* Fixed: removed offending tzlocal()
  • Loading branch information
djarpin authored and laurenyu committed Feb 21, 2018
1 parent 81531d4 commit 06249d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sagemaker/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ def logs_for_job(self, job_name, wait=False, poll=5): # noqa: C901 - suppress c
if dot:
print()
print('===== Job Complete =====')
# Customers are not billed for hardware provisioning, so billable time is less than total time
billable_time = (description['TrainingEndTime'] - description['TrainingStartTime']) * instance_count
print('Billable seconds:', int(billable_time.total_seconds()) + 1)


def container_def(image, model_data_url=None, env=None):
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from mock import Mock, patch, call
import sagemaker
from sagemaker import s3_input, Session, get_execution_role
import datetime

from botocore.exceptions import ClientError

Expand Down Expand Up @@ -177,6 +178,11 @@ def test_s3_input_all_arguments():
{'ModelArtifacts': {
'S3ModelArtifacts': S3_OUTPUT + '/model/model.tar.gz'
}})
# TrainingStartTime and TrainingEndTime are for billable seconds calculation
COMPLETED_DESCRIBE_JOB_RESULT.update(
{'TrainingStartTime': datetime.datetime(2018, 2, 17, 7, 15, 0, 103000)})
COMPLETED_DESCRIBE_JOB_RESULT.update(
{'TrainingEndTime': datetime.datetime(2018, 2, 17, 7, 19, 34, 953000)})
IN_PROGRESS_DESCRIBE_JOB_RESULT = dict(DEFAULT_EXPECTED_TRAIN_JOB_ARGS)
IN_PROGRESS_DESCRIBE_JOB_RESULT.update({'TrainingJobStatus': 'InProgress'})

Expand Down

0 comments on commit 06249d4

Please sign in to comment.