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

[FEATURE] Modify n_rendered_envs to rendered_envs_idx #752

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

Conversation

lupinjia
Copy link

@lupinjia lupinjia commented Feb 19, 2025

Description

modify n_rendered_envs attribute in vis_options to rendered_envs_idx, to support specification of which env to be rendered.

Motivation and Context

When training, sometimes I need to render specific env to see what happened to that env, so this specification can be useful

How Has This Been / Can This Be Tested?

  • modified examples/tutorials/visualization.py to test different idx rendered, run visualization.py to see the result.

  • CI tests have been conducted locally, and there's no problem.

    True island 	| 1 cubes 	| <CG: 0> 	| 10,347,075.60 fps 	| 8192 envs
    False island 	| 1 cubes 	| <CG: 0> 	| 21,736,861.82 fps 	| 8192 envs
    True island 	| 10 cubes 	| <CG: 0> 	| 1,093,222.22 fps 	| 8192 envs
    False island 	| 10 cubes 	| <CG: 0> 	| 816,686.37 fps 	| 8192 envs
    True island 	| 1 cubes 	| <Newton: 1> 	| 8,947,203.02 fps 	| 8192 envs
    False island 	| 1 cubes 	| <Newton: 1> 	| 17,418,196.78 fps 	| 8192 envs
    True island 	| 10 cubes 	| <Newton: 1> 	| 925,635.75 fps 	| 8192 envs
    False island 	| 10 cubes 	| <Newton: 1> 	| 317,976.76 fps 	| 8192 envs
    random 	| <CG: 0> 	| 1,243,238.90 fps 	| 30000 envs
    random 	| <Newton: 1> 	| 1,823,401.43 fps 	| 30000 envs
    anymal 	| <CG: 0> 	| 4,958,232.78 fps 	| 30000 envs
    anymal 	| <Newton: 1> 	| 4,623,612.63 fps 	| 30000 envs
    frank 	| <CG: 0> 	| 10,531,791.39 fps 	| 30000 envs
    frank 	| <Newton: 1> 	| 11,374,890.36 fps 	| 30000 envs

Screenshots (if appropriate):

render first 5 envs:
first_5_envs

render envs with idx 10 to 14:
11_to_15_envs

Checklist:

  • I read the CONTRIBUTING document.
  • I followed the Submitting Code Changes section of CONTRIBUTING document.
  • I tagged the title correctly (including BUG FIX/FEATURE/MISC/BREAKING)
  • I updated the documentation accordingly or no change is needed.
  • I tested my changes and added instructions on how to test it for reviewers.

@lupinjia lupinjia marked this pull request as ready for review February 19, 2025 06:34
@Kashu7100
Copy link
Collaborator

@YilingQiao do you think we can merge this after we modified add the examples using n_rendered_envs?

@@ -285,7 +285,7 @@ def on_rigid(self):
mesh = geom.get_sdf_trimesh()
else:
mesh = geom.get_trimesh()
geom_T = geoms_T[geom.idx][: self.n_rendered_envs]
geom_T = geoms_T[geom.idx][self.rendered_envs_idx]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beware this would trigger a copy since ‘self.rendered_envs_idx’ is not a slice but a list. No sure about the overall performance penalty it induces.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. We should bench first...

Copy link
Author

Choose a reason for hiding this comment

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

For this problem, I added a new variable called rendered_envs_idx_slice to avoid copy list to slice in the loop

@@ -285,7 +285,7 @@ def on_rigid(self):
mesh = geom.get_sdf_trimesh()
else:
mesh = geom.get_trimesh()
geom_T = geoms_T[geom.idx][: self.n_rendered_envs]
geom_T = geoms_T[geom.idx][self.rendered_envs_idx]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. We should bench first...

@YilingQiao
Copy link
Collaborator

@YilingQiao do you think we can merge this after we modified add the examples using n_rendered_envs?

Yeah, I think we can merge this after incorporating the suggested changes.

@@ -64,6 +64,7 @@ def build(self, scene):

if self.rendered_envs_idx is None:
self.rendered_envs_idx = list(range(self.sim._B))
self.rendered_envs_idx_slice = slice(self.rendered_envs_idx[0], self.rendered_envs_idx[-1] + 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the assumption of consecutive rendered_envs_idx is good. What we should do instead is to measure the overhead introduced by list indexing and verify it won't add more overhead compared to the current version.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely

@@ -208,7 +208,8 @@ def build(self, scene):
self.sim = scene.sim
self.visualizer = scene.visualizer
if self.rendered_envs_idx is None:
self.rendered_envs = list(range(self.sim._B))
self.rendered_envs_idx = list(range(self.sim._B))
self.rendered_envs_idx_slice = slice(self.rendered_envs_idx[0], self.rendered_envs_idx[-1] + 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the assumption of consecutive rendered_envs_idx is good.

@@ -285,7 +286,7 @@ def on_rigid(self):
mesh = geom.get_sdf_trimesh()
else:
mesh = geom.get_trimesh()
geom_T = geoms_T[geom.idx][self.rendered_envs_idx]
geom_T = geoms_T[geom.idx][self.rendered_envs_idx_slice]
Copy link
Collaborator

Choose a reason for hiding this comment

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

should keep self.rendered_envs_idx but make sure this won't affect the performance.

@@ -312,7 +313,7 @@ def update_rigid(self, buffer_updates):
geoms_T = self.sim.rigid_solver._geoms_render_T

for geom in geoms:
geom_T = geoms_T[geom.idx][self.rendered_envs_idx]
geom_T = geoms_T[geom.idx][self.rendered_envs_idx_slice]
Copy link
Collaborator

Choose a reason for hiding this comment

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

should keep self.rendered_envs_idx but make sure this won't affect the performance.

@duburcqa duburcqa changed the title [FEATURE]modify n_rendered_envs to rendered_envs_idx [FEATURE] Modify n_rendered_envs to rendered_envs_idx Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants