Skip to content

Commit 06249d4

Browse files
djarpinlaurenyu
authored andcommitted
Print out billable seconds after training completes (#30)
* Added: print out billable seconds after training completes * Fixed: test_session.py to pass unit tests * Fixed: removed offending tzlocal()
1 parent 81531d4 commit 06249d4

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/sagemaker/session.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ def logs_for_job(self, job_name, wait=False, poll=5): # noqa: C901 - suppress c
645645
if dot:
646646
print()
647647
print('===== Job Complete =====')
648+
# Customers are not billed for hardware provisioning, so billable time is less than total time
649+
billable_time = (description['TrainingEndTime'] - description['TrainingStartTime']) * instance_count
650+
print('Billable seconds:', int(billable_time.total_seconds()) + 1)
648651

649652

650653
def container_def(image, model_data_url=None, env=None):

tests/unit/test_session.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from mock import Mock, patch, call
1717
import sagemaker
1818
from sagemaker import s3_input, Session, get_execution_role
19+
import datetime
1920

2021
from botocore.exceptions import ClientError
2122

@@ -177,6 +178,11 @@ def test_s3_input_all_arguments():
177178
{'ModelArtifacts': {
178179
'S3ModelArtifacts': S3_OUTPUT + '/model/model.tar.gz'
179180
}})
181+
# TrainingStartTime and TrainingEndTime are for billable seconds calculation
182+
COMPLETED_DESCRIBE_JOB_RESULT.update(
183+
{'TrainingStartTime': datetime.datetime(2018, 2, 17, 7, 15, 0, 103000)})
184+
COMPLETED_DESCRIBE_JOB_RESULT.update(
185+
{'TrainingEndTime': datetime.datetime(2018, 2, 17, 7, 19, 34, 953000)})
180186
IN_PROGRESS_DESCRIBE_JOB_RESULT = dict(DEFAULT_EXPECTED_TRAIN_JOB_ARGS)
181187
IN_PROGRESS_DESCRIBE_JOB_RESULT.update({'TrainingJobStatus': 'InProgress'})
182188

0 commit comments

Comments
 (0)