Skip to content

Conversation

@akacmazz
Copy link

@akacmazz akacmazz commented Aug 28, 2025

What this does

  • Addresses Make LeRobot mypy compliant #1719; fixes Ensure the policy module passes MyPy type checks #1720. (🛠️ Tooling)
  • Policies typing:
    • ACT: type‑safe activation helper; move batch tensors to the module device before normalization for consistent
      device semantics.
    • SAC: constructor accepts None to match tests (base class raises the expected error); forward returns a typed dict.
    • Config: PreTrainedConfig now respects LEROBOT_TEST_DEVICE for deterministic device selection in CI/local runs.
  • Tooling (pre‑commit): enable a scoped MyPy run via the hook (uses pyproject.toml, installs types, ignores missing
    imports in the hook venv to avoid heavy deps). No global behavior change.

How it was tested

  • Static checks:
    • pre-commit run -a → all hooks green (ruff, typos, bandit, mypy).
    • mypy → success on the policies scope configured in pyproject.toml.
  • Tests (CPU to keep runs deterministic and lightweight):
    • SAC: PYTHONPATH=src pytest -q tests/policies -k sac
    • ACT back‑compat (uses small artifacts): PYTHONPATH=src pytest -q tests/policies -k 'act and
      backward_compatibility'
  • Notes:
    • Set local HF caches to avoid permission issues and reduce flakiness.
    • On low‑memory machines, split ACT/SAC runs to avoid OOM.

How to checkout & try? (for the reviewer)

From repo root

export LEROBOT_TEST_DEVICE=cpu
mkdir -p .cache/hf_datasets .cache/hf_home
export HF_DATASETS_CACHE=$(pwd)/.cache/hf_datasets
export HF_HOME=$(pwd)/.cache/hf_home

Static checks

pre-commit run -a
mypy

SAC tests

PYTHONPATH=src pytest -q tests/policies -k sac

ACT back-compat tests

PYTHONPATH=src pytest -q tests/policies -k 'act and backward_compatibility'
If you’d like me to extend MyPy coverage to the next module (e.g., Datasets) in a follow‑up PR, I can prepare the scoped
config and initial fixes similarly.

cc @CadeRemi @AdilZouitine for review

Copy link
Collaborator

@AdilZouitine AdilZouitine left a comment

Choose a reason for hiding this comment

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

Hey thank you for your contribution, I started the review for Act policy 😄
I will do the next policy later 🤗

  - Remove --ignore-missing-imports flag from pre-commit config
  - Add TypedDict annotations (OptimizerKwargs, ForwardKwargs)
  - Improve get_optim_params() return type annotation
  - Add activation function casts for MyPy stub compatibility
  - Remove device handling code (non-MyPy related)
  - Maintain parent class method signature compatibility.
@AdilZouitine
Copy link
Collaborator

Hey we have merged a big pr #1452. Could you rebase this branch please ? I will finish the review 😄

@imstevenpmwork imstevenpmwork added enhancement Suggestions for new features or improvements python Pull requests that update python code labels Oct 5, 2025
@imstevenpmwork imstevenpmwork self-requested a review October 5, 2025 10:36
@imstevenpmwork
Copy link
Collaborator

Hello @akacmazz

Can you ping me whenever this is ready for a review ? Feel free to ping me in discord
Sorry for the back and forth, thanks !

@akacmazz
Copy link
Author

Hey @imstevenpmwork, Just wanted to let you know that my PR for Issue #1720 (MyPy compliance for policies module) is ready for review:

#2295

Thank you.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure the policy module passes MyPy type checks

3 participants