Download scripts/infer/run_egl_renderer.py from Tinghong-Ye22/code-HFD: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/scripts/infer/run_egl_renderer.py
- Command line
-
hf download hf://Tinghong-Ye22/code-HFD/scripts/infer/run_egl_renderer.py
-
curl -L -o run_egl_renderer.py https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/scripts/infer/run_egl_renderer.py
1.4 kB
| """Resolve EGL's own device enumeration before running a MuJoCo renderer. | |
| CUDA ordinals are not EGL ordinals. CPU/Mesa containers can expose a single | |
| EGL device despite having several CUDA GPUs. Never pass CUDA=3 blindly to EGL. | |
| """ | |
| import os | |
| from pathlib import Path | |
| import runpy | |
| import sys | |
| def selected_device(count, requested): | |
| if count < 1: | |
| raise RuntimeError("No EGL rendering device available") | |
| if count == 1: | |
| return "0" | |
| if requested is None: | |
| return None | |
| value = int(requested) | |
| if not 0 <= value < count: | |
| raise ValueError(f"EGL device {value} outside available 0..{count-1}") | |
| return str(value) | |
| def main(): | |
| from mujoco.egl import egl_ext as EGL | |
| count = len(EGL.eglQueryDevicesEXT()) | |
| requested = os.environ.get("HFD_RENDER_EGL_DEVICE_ID", os.environ.get("MUJOCO_EGL_DEVICE_ID")) | |
| selected = selected_device(count, requested) | |
| if selected is not None: | |
| os.environ["MUJOCO_EGL_DEVICE_ID"] = selected | |
| print(f"[render] EGL devices={count} selected={selected or 'auto'} " | |
| f"(CUDA allocation={os.environ.get('CUDA_VISIBLE_DEVICES', 'all')}; independent enumerations)", flush=True) | |
| target = Path(sys.argv[1]).resolve() | |
| sys.argv = [str(target), *sys.argv[2:]] | |
| sys.path.insert(0, str(target.parent)) | |
| runpy.run_path(str(target), run_name="__main__") | |
| if __name__ == "__main__": | |
| main() | |