Skip to content

[Feature] MinariExperienceReplay now can handle text fields like "mission" #3075

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

Open
wants to merge 14 commits into
base: main
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
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ If the generation of this artifact in MacOs M1 doesn't work correctly or in the
ARCHFLAGS="-arch arm64" python setup.py develop
```

In some MacOs devices, the installation of the required libraries errors if the correct version of
clang is not used. Using `llvm@16` (installable with brew), may fix your issues.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!


## Formatting your code
**Type annotation**

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ def _main(argv):
"einops", # For tensor operations
"safetensors", # For model loading
],
"all": set(),
}
extra_requires["all"] = set()
for key in list(extra_requires.keys()):
extra_requires["all"] = extra_requires["all"].union(extra_requires[key])
extra_requires["all"] = sorted(extra_requires["all"])
Expand Down
33 changes: 33 additions & 0 deletions test/test_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3453,6 +3453,39 @@ def fn(data):
assert sample["data"].shape == torch.Size([32, 8])
assert sample["next", "data"].shape == torch.Size([32, 8])

@pytest.mark.parametrize("selected_dataset", ["minigrid/BabyAI-Pickup/optimal-v0"])
def test_minari_string_to_tensor(self, selected_dataset):
# Define the possible missions
colors = ["red", "green", "blue", "purple", "yellow", "grey"]
object_types = ["box", "ball", "key"]
mission_to_idx = {
f"pick up {color} {obj}": i
for i, (color, obj) in enumerate(
(c, o) for c in colors for o in object_types
)
}
num_missions = len(mission_to_idx)

def encode_mission_string(mission: bytes) -> torch.Tensor:
mission = mission.decode("utf-8")
clean_mission = mission.replace(" a", "").replace(" the", "")
idx = mission_to_idx.get(clean_mission, -1)
if idx == -1:
raise ValueError(f"Unknown mission string: {clean_mission}")
return torch.nn.functional.one_hot(
torch.tensor(idx), num_classes=num_missions
).to(torch.uint8)

data = MinariExperienceReplay(
dataset_id=selected_dataset,
batch_size=1,
download="force",
string_to_tensor_map={"observations/mission": encode_mission_string},
)
sample = data.sample(batch_size=1)
assert isinstance(sample["observation", "mission"], torch.Tensor)
assert sample["observation", "mission"].shape == (1, num_missions)


@pytest.mark.slow
class TestRoboset:
Expand Down
Loading
Loading