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] Add a test for loading checkpoint v1.0 Policies using the new Policy.from_checkpoint(). #29370

Merged
merged 4 commits into from
Oct 25, 2022
Merged
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "Policy", "checkpoint_version": "1.0", "ray_version": "3.0.0.dev0", "ray_commit": "5ae1638c8797518dc2177d7cf5d327cd9c32d706"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "Algorithm", "checkpoint_version": "1.0", "ray_version": "3.0.0.dev0", "ray_commit": "5ae1638c8797518dc2177d7cf5d327cd9c32d706"}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "Policy", "checkpoint_version": "1.0", "ray_version": "3.0.0.dev0", "ray_commit": "5ae1638c8797518dc2177d7cf5d327cd9c32d706"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "Algorithm", "checkpoint_version": "1.0", "ray_version": "3.0.0.dev0", "ray_commit": "5ae1638c8797518dc2177d7cf5d327cd9c32d706"}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "Policy", "checkpoint_version": "1.0", "ray_version": "3.0.0.dev0", "ray_commit": "5ae1638c8797518dc2177d7cf5d327cd9c32d706"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "Algorithm", "checkpoint_version": "1.0", "ray_version": "3.0.0.dev0", "ray_commit": "5ae1638c8797518dc2177d7cf5d327cd9c32d706"}
32 changes: 0 additions & 32 deletions rllib/tests/backward_compat/old_ppo.py

This file was deleted.

236 changes: 0 additions & 236 deletions rllib/tests/backward_compat/old_registry.py

This file was deleted.

30 changes: 29 additions & 1 deletion rllib/tests/backward_compat/test_backward_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,39 @@ def test_old_checkpoint_formats(self):

# Also test restoring a Policy from an algo checkpoint.
policies = Policy.from_checkpoint(path_to_checkpoint)
assert "default_policy" in policies
self.assertTrue("default_policy" in policies)

print(algo.train())
algo.stop()

def test_v1_policy_from_checkpoint(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my understanding: Any reason, why we shouldn't just do this test case in a loop?

B/c you just want to test Policy (not algo)? Python/pickle versions?

Copy link
Member Author

Choose a reason for hiding this comment

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

you mean merge this test with the one above?
the thing is that I need to test DQN policies here. because that is the one we didn't finish migrating to PolicyV2.
it feels a special case compared to the other backward compatibility tests.
we can also remove this test once I move DQN, etc to PolicyV2.

"""Tests, whether we can load Policy checkpoints for different frameworks."""

# We wouldn't need this test once we get rid of V1 policy implementations.

rllib_dir = Path(__file__).parent.parent.parent
print(f"rllib dir={rllib_dir} exists={os.path.isdir(rllib_dir)}")

for fw in framework_iterator(with_eager_tracing=True):
path_to_checkpoint = os.path.join(
rllib_dir,
"tests",
"backward_compat",
"checkpoints",
"v1.0",
"dqn_frozenlake_" + fw,
"policies",
"default_policy",
)

print(
f"path_to_checkpoint={path_to_checkpoint} "
f"exists={os.path.isdir(path_to_checkpoint)}"
)

policy = Policy.from_checkpoint(path_to_checkpoint)
self.assertTrue(isinstance(policy, Policy))


if __name__ == "__main__":
import pytest
Expand Down