Skip to content

modify rl ray images mapping for newer versions #1618

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

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/sagemaker/fw_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"{} framework does not support version {}. Please use one of the following: {}."
)

VALID_PY_VERSIONS = ["py2", "py3", "py37"]
VALID_PY_VERSIONS = ["py2", "py3", "py37", "py36"]
VALID_EIA_FRAMEWORKS = [
"tensorflow",
"tensorflow-serving",
Expand Down
35 changes: 32 additions & 3 deletions src/sagemaker/rl/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

logger = logging.getLogger("sagemaker")

DEFAULT_RL_ACCOUNT = "462105765813"
SAGEMAKER_ESTIMATOR = "sagemaker_estimator"
SAGEMAKER_ESTIMATOR_VALUE = "RLEstimator"
PYTHON_VERSION = "py3"
Expand All @@ -41,6 +42,8 @@
"0.5": {"tensorflow": "1.11"},
"0.6.5": {"tensorflow": "1.12"},
"0.6": {"tensorflow": "1.12"},
"0.8.2": {"tensorflow": "2.1"},
"0.8.5": {"tensorflow": "2.1", "pytorch": "1.5"},
},
}

Expand All @@ -57,14 +60,15 @@ class RLFramework(enum.Enum):

TENSORFLOW = "tensorflow"
MXNET = "mxnet"
PYTORCH = "pytorch"


class RLEstimator(Framework):
"""Handle end-to-end training and deployment of custom RLEstimator code."""

COACH_LATEST_VERSION_TF = "0.11.1"
COACH_LATEST_VERSION_MXNET = "0.11.0"
RAY_LATEST_VERSION = "0.6.5"
RAY_LATEST_VERSION = "0.8.5"

def __init__(
self,
Expand Down Expand Up @@ -277,6 +281,18 @@ def train_image(self):
"""
if self.image_name:
return self.image_name

# use different account for rl images if ray version is later than 0.8.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coach > 1.0.0 also has the different account/repo, right? (looking at https://github.com/aws/sagemaker-rl-container/#rl-images-provided-by-sagemaker)

if self.toolkit == RLToolkit.RAY.value and self.toolkit_version >= "0.8.2":
return fw_utils.create_image_uri(
self.sagemaker_session.boto_region_name,
"rl-ray-container",
self.train_instance_type,
self._image_version(),
py_version="py36",
account=DEFAULT_RL_ACCOUNT,
)

return fw_utils.create_image_uri(
self.sagemaker_session.boto_region_name,
self._image_framework(),
Expand Down Expand Up @@ -454,6 +470,13 @@ def _validate_toolkit_support(cls, toolkit, toolkit_version, framework):

def _image_version(self):
"""Placeholder docstring"""
if self.toolkit == RLToolkit.RAY.value and self.toolkit_version >= "0.8.2":
frameworkd_tag = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/frameworkd/framework

if self.framework == RLFramework.TENSORFLOW.value:
frameworkd_tag = "tf"
elif self.framework == RLFramework.PYTORCH.value:
frameworkd_tag = "torch"
return "{}-{}-{}".format(self.toolkit, self.toolkit_version, frameworkd_tag)
return "{}{}".format(self.toolkit, self.toolkit_version)

def _image_framework(self):
Expand Down Expand Up @@ -483,7 +506,13 @@ def default_metric_definitions(cls, toolkit):
float_regex = "[-+]?[0-9]*[.]?[0-9]+([eE][-+]?[0-9]+)?" # noqa: W605, E501

return [
{"Name": "episode_reward_mean", "Regex": "episode_reward_mean: (%s)" % float_regex},
{"Name": "episode_reward_max", "Regex": "episode_reward_max: (%s)" % float_regex},
{
"Name": "episode_reward_mean",
"Regex": "episode_reward_mean: {}".format(float_regex),
},
{
"Name": "episode_reward_max",
"Regex": "episode_reward_max: {}".format(float_regex),
},
]
raise ValueError("An unknown RLToolkit enum was passed in. toolkit: {}".format(toolkit))
4 changes: 2 additions & 2 deletions tests/data/ray_cartpole/train_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from ray.tune.logger import pretty_print

# Based on https://github.com/ray-project/ray/blob/master/doc/source/rllib-training.rst#python-api
ray.init(log_to_driver=False)
ray.init(log_to_driver=False, webui_host="127.0.0.1")
config = ppo.DEFAULT_CONFIG.copy()
config["num_gpus"] = int(os.environ.get("SM_NUM_GPUS", 0))
checkpoint_dir = os.environ.get("SM_MODEL_DIR", "/Users/nadzeya/gym")
config["num_workers"] = 1
agent = ppo.PPOAgent(config=config, env="CartPole-v0")
agent = ppo.PPOTrainer(config=config, env="CartPole-v0")

# Can optionally call agent.restore(path) to load a checkpoint.

Expand Down