refactor: import other lerobot packages through their package API #5215
All Vouch review confidence checks passed
Residual risk 0.32 = Change Risk (0.91) × (1 − Review Confidence (0.65)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.91 · 1664 lines diff across 217 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.58 · 4 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 10%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.400
No Reviewer Assigned
no_reviewer_assigned
0.120
Mass File Touch
mass_file_touch
0.080
Real PR Conversation Timeline
5 items
The base CI job fails to collect test_streaming_mp4_timing.py and test_streaming_sync_cache.py because both import lerobot.streaming at module scope and hit the new dependency check. Could we add pytest.importorskip guards before those imports and mark both modules as dataset, as the other streaming tests do?
This method now looks up full_model_state_dict and is_main_process on lerobot.distributed, while the Wall-OSS save test still patches the original submodules. Both cases pass on the base revision and fail at assert gathered == [policy] on this PR. Could we update both patch targets to lerobot.distributed, as the DM05 test does?
CarolinePascal
Summary / Motivation
This PR states one import convention in
AGENTS.mdand applies it acrosssrc/lerobot. Every top-level package now exposes the symbols other packages use through its__init__.py, and code outside a package imports them from there.Rules now in
AGENTS.md__init__.py: each top-level package's__init__.pyimports every symbol other packages use and lists it in__all__. A symbol deliberately left out gets a comment there naming the module to import it from.from .sibling import X). Across packages, import from the package (from lerobot.policies import PreTrainedPolicy), never from its files or subpackages.-
tests/;-
lerobot.utilsandlerobot.common;- symbols left out of a package's
__init__.py, which you import from the module its comment names.lerobot.utils: importing it pulls in only base dependencies and no other lerobot package. Import from its modules, not from the package (from lerobot.utils.constants import ACTION).lerobot.common: code that bridges packages. It may import other lerobot packages and optional extras. Import from its modules, not from the package (from lerobot.common.train_utils import save_checkpoint).Symbols left out of an
__init__.pyare documented with a uniform comment placed right before__all__:Main changes needed to follow the rules
Breaking the
configs↔optimimport cycleconfigs.policiesandconfigs.rewardsnow importOptimizerConfigandLRSchedulerConfigonly for type checking.optim.factorydoes the same forTrainPipelineConfigandPreTrainedPolicy, somake_optimizer_and_schedulercan be re-exported fromlerobot.optim.datasets.factoryimportsTrainPipelineConfigonly for type checking.TrainPipelineConfig,CheckpointFormat,TRAIN_CONFIG_NAMEandEvalPipelineConfigstay out oflerobot.configsbecause they would create a cycle. Import them fromlerobot.configs.trainandlerobot.configs.eval.Keeping
lerobot.utilsbase-onlyLANGUAGE_COLUMNSis now defined inlerobot.utils.constants, soutils.collateno longer importslerobot.datasets.lerobot.utils.doctest_utilsmoved totests/doctest_utils.pybecause it depends on pytest.conftest.py, theMakefileandquality.ymlare updated to the new path.lerobot.streamingrequires thedatasetextralerobot.streamingonly exists to feedLeRobotDataset, so its__init__now checks for thedatasetextra, aslerobot.datasetsdoes.StreamingSamplingStrategymoved tolerobot.configs.types, solerobot.configsno longer importslerobot.streaming.lerobot-build-mp4-sidecar --helpstill works on a base install: the script importslerobot.streamingunder the existing_datasets_availableguard.dataset, andtest_streaming_core_imports.pyis removed.Symbols deliberately not re-exported (each one documented with a NOTE)
| Package | Left out | Reason |
| --- | --- | --- |
|
policies| modeling classes and policy-specific helpers | they pull heavy optional dependencies;get_policy_class()loads them lazily ||
rewards| reward model classes and reward-specific helpers | same;get_reward_model_class()loads them lazily ||
robots| robot implementations,so_follower.robot_kinematic_processor| device-specific dependencies, and the processor pullslerobot.processor(TODO: move it to a robot-agnostic location) ||
robots.unitree_g1| kinematics helpers |config_unitree_g1importslerobot.envs, which importslerobot.robots||
sim| simulator integrations (lerobot.sim.integrations.<type>) | each simulator package is imported only when used ||
rl|gym_manipulator| it pulls the camera, robot and teleoperator stacks ||
transport| RL gRPC modules | they requirelerobot[grpcio-dep]||
utils,common| everything | callers load only the modules they need; existing re-exports are kept for backward compatibility |Other
__version__is imported through thelerobotpackage.lerobot.distributed, where callers now look them up.lerobot.datasetsare guarded on_datasets_available and _av_available, since the package requires both at import time.fit_fast_tokenizerguardspyarrowon a new_pyarrow_availableflag.envs/line inAGENTS.mdnow says env configs definesim_settings(), which names thelerobot.simintegration thatcreate_envs()runs.Breaking changes
lerobot.utils.doctest_utilsis removed. It now lives intests/doctest_utils.py, which only pytest uses.import lerobot.streamingnow fails without thedatasetextra (pip install 'lerobot[dataset]').Follow-up
policies/__init__.py,motors/__init__.pyandenvs/__init__.pylist the ones to rename:- the
MLPclasses ingaussian_actor,vqbetandvla_jepa;- the
MotorStateclasses indamiao,robstrideandunitree_g1;- the two
RewardClassifierConfigclasses, inenvs.configsandrewards.classifier.examples/anddocs/that still take re-exported symbols from submodules (for examplelerobot.model.kinematics.RobotKinematicsandlerobot.rollout.strategies.BaseStrategy) are fixed in #5216, which is stacked on this PR.How was this tested
pre-commit(ruff check and format, mypy) passes.lerobotpackages and CLI entry points import successfully.