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

[RLlib] Algorithm/Policy checkpoint overhaul and Policy Model export (in native formats). #28166

Merged
merged 105 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
d026a99
wip
sven1977 Jun 8, 2022
50b6d69
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Jun 9, 2022
74cc999
wip.
sven1977 Jun 9, 2022
f6de7cd
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Jun 9, 2022
8a24cd8
wip.
sven1977 Jun 9, 2022
de46f48
wip.
sven1977 Jun 9, 2022
db5324d
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Aug 28, 2022
e5611c1
wip
sven1977 Aug 29, 2022
01a9e47
wip
sven1977 Aug 30, 2022
eed6218
wip.
sven1977 Aug 30, 2022
69352dc
wip.
sven1977 Aug 30, 2022
88ec1d6
wip
sven1977 Aug 30, 2022
f8c796e
wip.
sven1977 Aug 31, 2022
6ad1e80
wip.
sven1977 Aug 31, 2022
191550d
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 5, 2022
52235db
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 6, 2022
5e44e2e
wip
sven1977 Sep 6, 2022
fb8e89b
wip
sven1977 Sep 6, 2022
49429bd
wip
sven1977 Sep 6, 2022
f5a5430
wip
sven1977 Sep 6, 2022
41e9dd8
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 7, 2022
5261c53
wip
sven1977 Sep 7, 2022
94399e1
wip
sven1977 Sep 7, 2022
8ddba8b
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 9, 2022
799be4b
wip
sven1977 Sep 9, 2022
0117db2
wip
sven1977 Sep 9, 2022
e3bdf70
wip
sven1977 Sep 9, 2022
3071270
wip.
sven1977 Sep 9, 2022
82f5b41
wip.
sven1977 Sep 12, 2022
81c7d30
wip.
sven1977 Sep 12, 2022
c044cae
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 13, 2022
c898e18
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 13, 2022
08ba388
wip.
sven1977 Sep 13, 2022
5f66ee9
wip.
sven1977 Sep 13, 2022
1474621
wip.
sven1977 Sep 13, 2022
3d91cd1
wip.
sven1977 Sep 13, 2022
04b9e01
wip.
sven1977 Sep 13, 2022
b7b3ebb
wip.
sven1977 Sep 13, 2022
6209017
wip.
sven1977 Sep 13, 2022
113ccf8
wip.
sven1977 Sep 15, 2022
6aa6f06
wip.
sven1977 Sep 15, 2022
0b54fbf
wip.
sven1977 Sep 15, 2022
d3d85d2
wip.
sven1977 Sep 15, 2022
c0e2e8d
wip
sven1977 Sep 16, 2022
6fafcf4
Merge branch 'master' of https://github.com/ray-project/ray into befo…
sven1977 Sep 19, 2022
70f2bdb
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 20, 2022
f69ed2a
wip
sven1977 Sep 20, 2022
5ffab1e
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 20, 2022
f0dfda9
wip
sven1977 Sep 20, 2022
b31114c
wip
sven1977 Sep 20, 2022
8fde067
merge
sven1977 Sep 20, 2022
c8afcf3
wip
sven1977 Sep 20, 2022
2c250d7
wip
sven1977 Sep 21, 2022
f230ffc
wip
sven1977 Sep 21, 2022
80b1829
Merge branch 'master' of https://github.com/ray-project/ray into add_…
sven1977 Sep 23, 2022
a01ccb2
wip
sven1977 Sep 23, 2022
447ba02
wip
sven1977 Sep 23, 2022
9a80a90
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 23, 2022
2c4754c
wip
sven1977 Sep 23, 2022
8070201
wip
sven1977 Sep 23, 2022
51ff6ae
wip
sven1977 Sep 23, 2022
b72a192
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 23, 2022
bb8e7a0
wip
sven1977 Sep 23, 2022
9ad4aa7
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 23, 2022
3b1bc8f
Merge branch 'add_policy_takes_policy_instance' into model_export_ove…
sven1977 Sep 23, 2022
60b0e51
wip
sven1977 Sep 26, 2022
45f3792
LINT
sven1977 Sep 26, 2022
73fd3d1
wip
sven1977 Sep 26, 2022
cc61975
wip
sven1977 Sep 26, 2022
a3bf614
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 26, 2022
1ad8e7a
wip
sven1977 Sep 26, 2022
b6de057
wip
sven1977 Sep 26, 2022
27083df
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 27, 2022
b396923
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 27, 2022
4c7a85c
wip
sven1977 Sep 27, 2022
4efb544
wip
sven1977 Sep 27, 2022
35a1eb7
wip
sven1977 Sep 27, 2022
11ee0f5
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 27, 2022
3f375b3
LINT
sven1977 Sep 27, 2022
11c8212
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Sep 28, 2022
2258378
wip
sven1977 Sep 28, 2022
ccca4e5
wip
sven1977 Sep 30, 2022
c66d30b
merge
sven1977 Sep 30, 2022
d52cda3
wip
sven1977 Sep 30, 2022
5f09214
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Oct 4, 2022
5e03461
wip
sven1977 Oct 4, 2022
151b65d
wip
sven1977 Oct 4, 2022
5a652cf
wip
sven1977 Oct 4, 2022
fd17683
LINT
sven1977 Oct 4, 2022
881c128
wip
sven1977 Oct 4, 2022
c099a55
wip
sven1977 Oct 5, 2022
b3adcd2
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Oct 5, 2022
84e92d0
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Oct 5, 2022
926808d
wip
sven1977 Oct 5, 2022
bfe1a21
wip
sven1977 Oct 5, 2022
6fd673c
wip
sven1977 Oct 5, 2022
e80459a
wip
sven1977 Oct 6, 2022
116e706
Merge branch 'master' of https://github.com/ray-project/ray into mode…
sven1977 Oct 6, 2022
7b724fc
wip
sven1977 Oct 6, 2022
1cfdf81
wip
sven1977 Oct 6, 2022
e27c0d1
wip
sven1977 Oct 6, 2022
2f53966
wip
sven1977 Oct 6, 2022
cef1d2a
wip
sven1977 Oct 6, 2022
30c3dad
wip
sven1977 Oct 6, 2022
9a18fcc
wip
sven1977 Oct 6, 2022
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
4 changes: 2 additions & 2 deletions doc/source/serve/tutorials/rllib.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def train_ppo_model():
# Train for one iteration.
algo.train()
# Save state of the trained Algorithm in a checkpoint.
algo.save("/tmp/rllib_checkpoint")
return "/tmp/rllib_checkpoint/checkpoint_000001/checkpoint-1"
checkpoint_dir = algo.save("/tmp/rllib_checkpoint")
return checkpoint_dir
checkpoint_path = train_ppo_model()
Expand Down
12 changes: 12 additions & 0 deletions python/ray/train/rl/rl_checkpoint.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from packaging import version
from typing import Optional

from ray.air.checkpoint import Checkpoint
import ray.cloudpickle as cpickle
from ray.rllib.policy.policy import Policy
from ray.rllib.utils.checkpoints import get_checkpoint_info
from ray.rllib.utils.typing import EnvType
from ray.util.annotations import PublicAPI

Expand All @@ -30,6 +32,16 @@ def get_policy(self, env: Optional[EnvType] = None) -> Policy:
Returns:
The policy stored in this checkpoint.
"""
# TODO: Deprecate this RLCheckpoint class (or move all our
# Algorithm/Policy.from_checkpoint utils into here).
# If newer checkpoint version -> Use `Policy.from_checkpoint()` util.
checkpoint_info = get_checkpoint_info(checkpoint=self)
if checkpoint_info["checkpoint_version"] > version.Version("0.1"):
# Since we have an Algorithm checkpoint, will extract all policies in that
# Algorithm -> need to index into "default_policy" in the returned dict.
return Policy.from_checkpoint(checkpoint=self)["default_policy"]

# Older checkpoint version.
with self.as_directory() as checkpoint_path:
trainer_class_path = os.path.join(checkpoint_path, RL_TRAINER_CLASS_FILE)
config_path = os.path.join(checkpoint_path, RL_CONFIG_FILE)
Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/tests/test_tune_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def setUp(self):

logdir = os.path.expanduser(os.path.join(tmpdir, test_name))
self.logdir = logdir
self.checkpoint_path = recursive_fnmatch(logdir, "checkpoint-1")[0]
self.checkpoint_path = recursive_fnmatch(logdir, "algorithm_state.pkl")[0]

def tearDown(self):
shutil.rmtree(self.logdir)
Expand Down
42 changes: 34 additions & 8 deletions rllib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,13 @@ py_test(
data = ["tests/data/cartpole/small.json"],
)

py_test(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests the new Algorithm checkpointing mechanism.

name = "test_algorithm_export_checkpoint",
tags = ["team:rllib", "algorithms_dir", "algorithms_dir_generic"],
size = "medium",
srcs = ["algorithms/tests/test_algorithm_export_checkpoint.py"],
)

py_test(
name = "test_callbacks",
tags = ["team:rllib", "algorithms_dir", "algorithms_dir_generic"],
Expand Down Expand Up @@ -1876,6 +1883,13 @@ py_test(
srcs = ["policy/tests/test_compute_log_likelihoods.py"]
)

py_test(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests the new individual Policy checkpointing and native model saving mechanisms.

name = "policy/tests/test_export_checkpoint_and_model",
tags = ["team:rllib", "policy"],
size = "large",
srcs = ["policy/tests/test_export_checkpoint_and_model.py"]
)

py_test(
name = "policy/tests/test_multi_agent_batch",
tags = ["team:rllib", "policy"],
Expand Down Expand Up @@ -1919,6 +1933,14 @@ py_test(
# Tag: utils
# --------------------------------------------------------------------

# Checkpoint Utils
py_test(
name = "test_checkpoint_utils",
tags = ["team:rllib", "utils"],
size = "small",
srcs = ["utils/tests/test_checkpoint_utils.py"]
)

py_test(
name = "test_errors",
tags = ["team:rllib", "utils"],
Expand Down Expand Up @@ -2078,7 +2100,8 @@ py_test(
name = "tests/backward_compat/test_backward_compat",
tags = ["team:rllib", "tests_dir", "tests_dir_B"],
size = "medium",
srcs = ["tests/backward_compat/test_backward_compat.py"]
srcs = ["tests/backward_compat/test_backward_compat.py"],
data = glob(["tests/backward_compat/checkpoints/**"]),
)

py_test(
Expand Down Expand Up @@ -2168,13 +2191,6 @@ py_test(
srcs = ["tests/test_execution.py"]
)

py_test(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced by rllib/policy/tests/test_export_checkpoint_and_model.py

name = "tests/test_export",
tags = ["team:rllib", "tests_dir", "tests_dir_E"],
size = "medium",
srcs = ["tests/test_export.py"]
)

py_test(
name = "tests/test_filters",
tags = ["team:rllib", "tests_dir", "tests_dir_F"],
Expand Down Expand Up @@ -2940,6 +2956,16 @@ py_test(
tags = ["team:rllib", "exclusive", "examples", "examples_E", "no_main"],
size = "medium",
srcs = ["examples/export/onnx_tf.py"],
args = ["--framework=tf"],
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tf2 example for exporting to ONNX format.

py_test(
name = "examples/export/onnx_tf2",
main = "examples/export/onnx_tf.py",
tags = ["team:rllib", "exclusive", "examples", "examples_E", "no_main"],
size = "medium",
srcs = ["examples/export/onnx_tf.py"],
args = ["--framework=tf2"],
)

py_test(
Expand Down
Loading