Skip to content

Commit

Permalink
Speed up CI, add more checks (#115)
Browse files Browse the repository at this point in the history
- Split pytest and end-to-end tests into separate jobs
- Add poetry check to ensure pyproject.toml and poetry.lock are in sync
- Add ruff format --diff to ensure style formatting is applied (fails if ruff would reformat anything)
  • Loading branch information
aliberts authored Apr 29, 2024
1 parent 1ec5f77 commit 2765877
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:

jobs:
latest-cpu:
name: "Build CPU"
name: CPU
runs-on: ubuntu-latest
steps:
- name: Cleanup disk
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
# SLACK_BOT_TOKEN: ${{ secrets.SLACK_CIFEEDBACK_BOT_TOKEN }}

latest-cuda:
name: "Build GPU"
name: GPU
runs-on: ubuntu-latest
steps:
- name: Cleanup disk
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:

jobs:
run_all_tests_cpu:
name: "Test CPU"
name: CPU
strategy:
fail-fast: false
runs-on: ubuntu-latest
Expand All @@ -40,7 +40,7 @@ jobs:


run_all_tests_single_gpu:
name: "Test GPU"
name: GPU
strategy:
fail-fast: false
runs-on: [single-gpu, nvidia-gpu, t4, ci]
Expand Down
26 changes: 22 additions & 4 deletions .github/workflows/style.yml → .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Style
name: Quality

on:
workflow_dispatch:
Expand All @@ -14,7 +14,8 @@ env:
PYTHON_VERSION: "3.10"

jobs:
ruff_check:
style:
name: Style
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
Expand All @@ -34,5 +35,22 @@ jobs:
- name: Install Ruff
run: python -m pip install "ruff==${{ env.RUFF_VERSION }}"

- name: Run Ruff
run: ruff check .
- name: Ruff check
run: ruff check

- name: Ruff format
run: ruff format --diff


poetry_check:
name: Poetry check
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Poetry check
run: poetry check
6 changes: 3 additions & 3 deletions .github/workflows/test-docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Inspired by
# https://github.com/huggingface/peft/blob/main/.github/workflows/test-docker-build.yml
name: Test Docker builds (PR)
name: Test Dockerfiles

on:
pull_request:
Expand All @@ -15,7 +15,7 @@ env:

jobs:
get_changed_files:
name: "Get all modified Dockerfiles"
name: Detect modified Dockerfiles
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
Expand All @@ -40,7 +40,7 @@ jobs:
build_modified_dockerfiles:
name: "Build all modified Docker images"
name: Build modified Docker images
needs: get_changed_files
runs-on: ubuntu-latest
if: ${{ needs.get_changed_files.outputs.matrix }} != ''
Expand Down
36 changes: 35 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ on:
- "poetry.lock"

jobs:
tests:
pytest:
name: Pytest
runs-on: ubuntu-latest
env:
DATA_DIR: tests/data
Expand Down Expand Up @@ -60,6 +61,39 @@ jobs:
-W ignore::UserWarning:gymnasium.utils.env_checker:247 \
&& rm -rf tests/outputs outputs
end-to-end:
name: End-to-end
runs-on: ubuntu-latest
env:
DATA_DIR: tests/data
MUJOCO_GL: egl
steps:
- name: Add SSH key for installing envs
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- uses: actions/checkout@v4

- name: Install EGL
run: sudo apt-get update && sudo apt-get install -y libegl1-mesa-dev

- name: Install poetry
run: |
pipx install poetry && poetry config virtualenvs.in-project true
echo "${{ github.workspace }}/.venv/bin" >> $GITHUB_PATH
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "poetry"

- name: Install poetry dependencies
run: |
poetry install --all-extras
- name: Test end-to-end
run: |
make test-end-to-end \
Expand Down
4 changes: 3 additions & 1 deletion examples/3_train_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
policy.train()
policy.to(device)

optimizer = torch.optim.Adam(policy.diffusion.parameters(), cfg.lr, cfg.adam_betas, cfg.adam_eps, cfg.adam_weight_decay)
optimizer = torch.optim.Adam(
policy.diffusion.parameters(), cfg.lr, cfg.adam_betas, cfg.adam_eps, cfg.adam_weight_decay
)

# Create dataloader for offline training.
dataloader = torch.utils.data.DataLoader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


class PushTProcessor:
""" Process zarr files formatted like in: https://github.com/real-stanford/diffusion_policy
"""
"""Process zarr files formatted like in: https://github.com/real-stanford/diffusion_policy"""

def __init__(self, folder_path: Path, fps: int | None = None):
self.zarr_path = folder_path
if fps is None:
Expand Down
1 change: 0 additions & 1 deletion lerobot/common/policies/act/modeling_act.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def forward(self, batch, **_) -> dict[str, Tensor]:

return loss_dict


def _stack_images(self, batch: dict[str, Tensor]) -> dict[str, Tensor]:
"""Stacks all the images in a batch and puts them in a new key: "observation.images".
Expand Down
24 changes: 19 additions & 5 deletions lerobot/scripts/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def update_policy(policy, batch, optimizer, grad_clip_norm, lr_scheduler=None):
info = {
"loss": loss.item(),
"grad_norm": float(grad_norm),
"lr": optimizer.param_groups[0]['lr'],
"lr": optimizer.param_groups[0]["lr"],
"update_s": time.time() - start_time,
}

Expand Down Expand Up @@ -271,17 +271,31 @@ def train(cfg: dict, out_dir=None, job_name=None):
# Temporary hack to move optimizer out of policy
if cfg.policy.name == "act":
optimizer_params_dicts = [
{"params": [p for n, p in policy.named_parameters() if not n.startswith("backbone") and p.requires_grad]},
{
"params": [p for n, p in policy.named_parameters() if n.startswith("backbone") and p.requires_grad],
"params": [
p
for n, p in policy.named_parameters()
if not n.startswith("backbone") and p.requires_grad
]
},
{
"params": [
p for n, p in policy.named_parameters() if n.startswith("backbone") and p.requires_grad
],
"lr": cfg.policy.lr_backbone,
},
]
optimizer = torch.optim.AdamW(optimizer_params_dicts, lr=cfg.policy.lr, weight_decay=cfg.policy.weight_decay)
optimizer = torch.optim.AdamW(
optimizer_params_dicts, lr=cfg.policy.lr, weight_decay=cfg.policy.weight_decay
)
lr_scheduler = None
elif cfg.policy.name == "diffusion":
optimizer = torch.optim.Adam(
policy.diffusion.parameters(), cfg.policy.lr, cfg.policy.adam_betas, cfg.policy.adam_eps, cfg.policy.adam_weight_decay
policy.diffusion.parameters(),
cfg.policy.lr,
cfg.policy.adam_betas,
cfg.policy.adam_eps,
cfg.policy.adam_weight_decay,
)
# TODO(rcadene): modify lr scheduler so that it doesn't depend on epochs but steps
# configure lr scheduler
Expand Down

0 comments on commit 2765877

Please sign in to comment.