-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(sim): allow loading envs from the hub #2121
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for loading environments from the Hugging Face Hub in addition to the existing local environment creation. Users can now specify a Hub repository string to dynamically load and execute environment code from remote repositories.
Key changes:
- Added hub URI parsing to support flexible repository and file path specifications
- Implemented dynamic module loading for Hub-downloaded Python files
- Enhanced the
make_env
function to handle both local and Hub environments with comprehensive error handling
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/lerobot/envs/factory.py
Outdated
def _load_module_from_path(path: str, module_name: Optional[str] = None): | ||
module_name = module_name or f"hub_env_{os.path.basename(path).replace('.', '_')}" | ||
spec = importlib.util.spec_from_file_location(module_name, path) | ||
module = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(module) # type: ignore | ||
return module |
Copilot
AI
Oct 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing import for importlib.util
. The function uses importlib.util.spec_from_file_location
and importlib.util.module_from_spec
but only importlib
is imported at the top of the file.
Copilot uses AI. Check for mistakes.
src/lerobot/envs/factory.py
Outdated
|
||
def make_env( | ||
cfg: EnvConfig, n_envs: int = 1, use_async_envs: bool = False | ||
cfg: Union[EnvConfig, str], n_envs: int = 1, use_async_envs: bool = False, hub_cache_dir: Optional[str] = None, |
Copilot
AI
Oct 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hub_cache_dir
parameter is added to the function signature but is not documented in the Args section of the docstring, and it's not used in the example that references it on line 120.
Copilot uses AI. Check for mistakes.
>>> envs = make_env( | ||
... "username/multi-env-repo@main:envs/pick_cube.py", | ||
... n_envs=4, | ||
... hub_uri_entry="make_env_pickcube", | ||
... hub_cache_dir="/raid/hub_cache" | ||
... ) |
Copilot
AI
Oct 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example references a hub_uri_entry
parameter that doesn't exist in the function signature. This parameter should be removed from the example or the functionality should be implemented.
Copilot uses AI. Check for mistakes.
# If the hub returned a single gym.Env, vectorize and return mapping | ||
if isinstance(result, gym.Env): | ||
# wrap into SyncVectorEnv of one env (consistent with local behavior) | ||
vec = gym.vector.SyncVectorEnv([lambda: result]) |
Copilot
AI
Oct 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda captures result
by reference, which could cause issues if result
is modified after creation. Each environment instance should be independent. Consider using a factory function instead: vec = gym.vector.SyncVectorEnv([lambda r=result: r for _ in range(1)])
.
vec = gym.vector.SyncVectorEnv([lambda: result]) | |
vec = gym.vector.SyncVectorEnv([lambda r=result: r]) |
Copilot uses AI. Check for mistakes.
What this does
feat(sim): allow loading envs from the hub
This allow people to upload environments on the hub, then easily load them.
from lerobot import make_env
For instance:
https://huggingface.co/jadechoghari/cartpole-env
Can be loaded as such
This design unlocks a powerful new model for collaboration. Instead of environments being locked away inside monolithic libraries, anyone can publish an
env.py
to the Hugging Face Hub, from simple toy tasks to large-scale, GPU-accelerated simulation worlds, and you can load them instantly with a single line of code.Over time, as more contributors share their work, the ecosystem of simulation environments will grow richer and more diverse. You can imagine a future where researchers push increasingly complex environments, physics-rich manipulation tasks, multi-agent worlds, photorealistic scenes, and they just work with the same LeRobot
make_env()
API.TODO: