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

Filter deactivated sensors. #2078

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

0mdc
Copy link
Contributor

@0mdc 0mdc commented Sep 13, 2024

Motivation and Context

This changeset adds a flag to filter out unused sensors from simulation.

In lab, only the sensors listed in gym.obs_keys can be read. However, all other sensors are still rendered.
Therefore, when pulling agents from configs, all their sensors are rendered.

For example, if a human and spot are instantiated, the following sensors are rendered:
image (6)

Note:
This breaks composite sensors. For example, a "human sensor" may depend on a RGB camera, but the filtering will cull out the RGB camera because it's not listed in gym.obs_key. For this reason, the flag is disabled by default. A sensor dependency graph will be implemented to work around this problem.

Performance

Here's the difference on a single-learn HITL session with 3 visual sensors.

Before After
sensor_filter_before2 sensor_filter_after

On a reference single-learn HITL application, this improves the framerate from 9.1 FPS to 11.3 FPS.
Performance gains were reported to be significantly higher in other use cases such as training.

How Has This Been Tested

Tested locally and profiled.
Running unit tests on CI.

Types of changes

  • [Optimization]

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation if required.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes if required.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 13, 2024
@0mdc 0mdc added the do not merge Not ready to merge. This label should block merging. label Sep 13, 2024
@0mdc 0mdc changed the title Filter deactivated sensors. [DO NOT MERGE] - Filter deactivated sensors. Sep 13, 2024
@0mdc 0mdc force-pushed the 0mdc/filter_deactivated_sensors branch from e2e87eb to 1fda203 Compare November 14, 2024 16:39
@0mdc 0mdc changed the title [DO NOT MERGE] - Filter deactivated sensors. Filter deactivated sensors. Nov 15, 2024
Copy link
Contributor

@eundersander eundersander left a comment

Choose a reason for hiding this comment

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

I left some comments.

@@ -1887,6 +1887,10 @@ class GymConfig(HabitatBaseConfig):
action_keys: Optional[List[str]] = None
achieved_goal_keys: List = field(default_factory=list)
desired_goal_keys: List[str] = field(default_factory=list)
cull_visual_sensors: Optional[bool] = False
Copy link
Contributor

Choose a reason for hiding this comment

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

How about cull_unused_visual_sensors

Copy link
Contributor

Choose a reason for hiding this comment

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

How about a warning comment that explains the dependency issue. You can mention humanoid_detector_sensor and spot_head_stereo_depth_sensor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I would expect the comment for this flag to go above it, not below it.

Copy link
Contributor Author

@0mdc 0mdc Nov 15, 2024

Choose a reason for hiding this comment

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

Also I would expect the comment for this flag to go above it, not below it.

You right that in this file, only class docstrings are under the symbols, so I'll change accordingly.
However, comments above the attributes aren't recognized as docstrings.

image

image

habitat-lab/habitat/core/env.py Outdated Show resolved Hide resolved
@@ -111,6 +111,22 @@ def __init__(
else:
self.number_of_episodes = None

# Filter out inactive sensors from habitat-sim config.
if config.gym.cull_visual_sensors:
Copy link
Contributor

Choose a reason for hiding this comment

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

Doing this cull logic here in Env.__init__... I wonder if this is too late and not ideal. For example, what about our call to envs.initialize_batch_renderer which also reads sim_sensors? Will it see the updated sim_sensors? For reference, when I accidentally re-implemented this recently, I put the culling in default.py patch_config, which is much earlier in our loading path. I don't know if that's better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. There is some unwrangling to do here.

This pattern of changing configs on-the-fly is causing us headaches with sensors. @aclegg3 and @jturner65 are currently working on refactoring them.

For example:

rearrange_sim changes the UUIDs here:

UUIDs get changed again when they are passed to sim here:

@aclegg3 let's consider this as we refactor agents and sensors.

Copy link
Contributor

Choose a reason for hiding this comment

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

So what's your plan here? Are you going to make a change here before merging this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sensor refactor won't be "done" for a few weeks. I suggest you move forward with a stop-gap if you need this change to be around soon. If this is just living on a branch or not really needed in the short term then you could wait. A similar mechanism is planned to be included in the sensor refactor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eundersander I would then go and merge this as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. do not merge Not ready to merge. This label should block merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants