Skip to content

Conversation

jadechoghari
Copy link
Member

@jadechoghari jadechoghari commented Oct 6, 2025

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

env1 = make_env("jadechoghari/cartpole-env", trust_remote_code=True)
print(env1)

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:

  • add testing
  • detect edge cases
  • review the pr

@Copilot Copilot AI review requested due to automatic review settings October 6, 2025 07:53
@jadechoghari jadechoghari self-assigned this Oct 6, 2025
@jadechoghari jadechoghari added enhancement Suggestions for new features or improvements simulation Matters involving system simulation or modeling labels Oct 6, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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.

Comment on lines 25 to 30
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
Copy link

Copilot AI Oct 6, 2025

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.


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,
Copy link

Copilot AI Oct 6, 2025

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.

Comment on lines 116 to 121
>>> 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"
... )
Copy link

Copilot AI Oct 6, 2025

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])
Copy link

Copilot AI Oct 6, 2025

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)]).

Suggested change
vec = gym.vector.SyncVectorEnv([lambda: result])
vec = gym.vector.SyncVectorEnv([lambda r=result: r])

Copilot uses AI. Check for mistakes.

@jadechoghari jadechoghari added the python Pull requests that update python code label Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Suggestions for new features or improvements python Pull requests that update python code simulation Matters involving system simulation or modeling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant