Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 11 additions & 1 deletion huggingface_sb3/naming_schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ class EnvironmentName(str):
"""

def __new__(cls, gym_id: str):
normalized_name = super().__new__(cls, gym_id.replace("/", "-"))
normalized_str = gym_id.replace("/", "-")
if ":" in normalized_str:
split_by_colon = normalized_str.split(":")
if len(split_by_colon) == 2:
# split by colon and take the first part
normalized_str = split_by_colon[1]
else:
raise ValueError(
f"Environment name {gym_id} contains more than one colon!"
)
normalized_name = super().__new__(cls, normalized_str)
normalized_name._gym_id = gym_id
return normalized_name

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"pyyaml~=6.0",
"wasabi",
"numpy",
"cloudpickle>=1.6"
"cloudpickle>=1.6",
"gym~=0.21",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this prevents hf hub sb3 from using it with gymnasium/sb3, no? is it needed only for the tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think right now huggingface_sb3 does not support gymnasium anyways (see #30).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey there 👋 I'm finishing the gymnasium integration can we remove this requirement? (gym one)

The PR: https://github.com/huggingface/huggingface_sb3/compare/gymnasium-v2

"stable-baselines3~=1.7",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not sure if it's a good thing that this packages depends on SB3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SB3 is used in push_to_hub.py so it makes sense to depend on it?

I set up a venv for huggingface_sb3, installed it there and then wanted to run the tests. Those tests failed due to missing gym and sb3 dependencies.
Therefore I added them.

Why do you think we should not add the dependency?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh, that's true, but I think @simoninithomas wanted to switch to gymnasium (so a simple dependency on SB3 should work).

]

extras = {}
Expand Down
16 changes: 14 additions & 2 deletions tests/test_naming_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from huggingface_sb3 import EnvironmentName, ModelName, ModelRepoId


@pytest.fixture(params=["seals/Walker2d-v0", "LunarLander-v2"])
@pytest.fixture(params=["seals/Walker2d-v0", "LunarLander-v2", "seals:seals/Walker2d-v0"])
def env_id(request) -> str:
return request.param

Expand All @@ -23,12 +23,24 @@ def repo_id(model_name: ModelName) -> ModelRepoId:
return ModelRepoId("orga", model_name)


def test_that_slashes_are_removed(env_id: str, env_name: EnvironmentName, model_name: ModelName, repo_id: ModelRepoId):
def test_that_slashes_are_removed(env_name: EnvironmentName, model_name: ModelName, repo_id: ModelRepoId):
assert "/" not in env_name
assert "/" not in model_name
assert "/" not in model_name.filename
assert repo_id.count("/") == 1 # note: repo id has exactly one slash separating org from repo name


def test_that_colon_is_removed(env_name: EnvironmentName, model_name: ModelName, repo_id: ModelRepoId):
assert ":" not in env_name
assert ":" not in model_name
assert ":" not in model_name.filename
assert ":" not in repo_id


def test_that_package_before_colon_is_removed():
env_name = EnvironmentName("seals:seals/Walker2d-v0")
assert env_name == "seals-Walker2d-v0"


def test_that_gym_id_is_preserved(env_id: str, env_name: EnvironmentName):
assert env_name.gym_id == env_id