Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: Use sagemaker-training for training #104

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python-dateutil==2.8.0
requests<2.21
retrying==1.3.3
sagemaker-containers>=2.8.3
sagemaker-training>=3.5.2
scikit-learn
scipy==1.2.2
smdebug==0.4.13
Expand Down
15 changes: 8 additions & 7 deletions src/sagemaker_xgboost_container/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import os
import sys

from sagemaker_containers import _env
import sagemaker_containers.beta.framework as framework
from sagemaker_training import entry_point, environment
from sagemaker_xgboost_container.algorithm_mode.train import sagemaker_train
from sagemaker_xgboost_container.constants import sm_env_constants

Expand Down Expand Up @@ -80,16 +79,18 @@ def train(training_environment):
"""
if training_environment.user_entry_point is not None:
logger.info('Invoking user training script.')
framework.modules.run_module(training_environment.module_dir, training_environment.to_cmd_args(),
training_environment.to_env_vars(), training_environment.module_name,
capture_error=False)
entry_point.run(uri=training_environment.module_dir,
user_entry_point=training_environment.user_entry_point,
args=training_environment.to_cmd_args(),
env_vars=training_environment.to_env_vars(),
capture_error=False)
else:
logger.info("Running XGBoost Sagemaker in algorithm mode")
_env.write_env_vars(training_environment.to_env_vars())
environment.write_env_vars(training_environment.to_env_vars())

run_algorithm_mode()


def main():
train(framework.training_env())
train(environment.Environment())
sys.exit(0)
9 changes: 6 additions & 3 deletions test/unit/test_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ def mock_training_env(current_host='algo-1', module_dir='s3://my/script', module
class TestTraining(unittest.TestCase):
"""Note: The 'train' method has been mocked since this test only checks the training resource setup"""

@patch('sagemaker_containers.beta.framework.modules.run_module')
@patch('sagemaker_training.entry_point.run')
def test_script_mode(self, mock_run_module):
env = mock_training_env()
env.user_entry_point = "dummy_entry_point"
training.train(env)

mock_run_module.assert_called_with(
's3://my/script', env.to_cmd_args(), env.to_env_vars(), 'svm', capture_error=False)
mock_run_module.assert_called_with(uri="s3://my/script",
user_entry_point="dummy_entry_point",
args=env.to_cmd_args(),
env_vars=env.to_env_vars(),
capture_error=False)

@patch('sagemaker_xgboost_container.training.run_algorithm_mode')
def test_algorithm_mode(self, mock_algorithm_mode_train):
Expand Down