Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,43 @@ pytest
## Installation

```bash
# macOS (MPS)
uv sync --extra dev

# Linux (CUDA 12.4)
uv sync --extra dev --extra cu124
```

## Development Workflow

### 1. 代码开发
### Quick Commands (Makefile)

```bash
uv run python scripts/train_rsl_rl.py --task Go1JoystickFlatTerrain
make format # Format and lint code
make type # Type check with mypy
make check # make format && make type
make test # Run all tests
make test-fast # Run tests excluding slow ones
make test-all # make check && make test
```

### 2. 提交前检查
### Manual Commands

```bash
# 格式化
# Format
uv run ruff format .
uv run ruff check --fix

# 检查
uv run ruff check .
# Type check
uv run mypy unilab

# Test
uv run pytest
```

### 3. Git 提交
使用 Conventional Commits:
## Git Commits

Use Conventional Commits:
- `feat:` 新功能
- `fix:` 修复 bug
- `docs:` 文档
Expand All @@ -46,6 +62,10 @@ uv run ruff check .
- `test:` 测试
- `chore:` 构建/工具

### 4. 自动化
- **Pre-commit hooks**(可选):`pre-commit install`
- **GitHub CI**:push 到 main 或 PR 时自动运行 lint + test
## Pre-commit

```bash
pre-commit install # Optional
```

**Always run `make check` before committing.**
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.PHONY: sync
sync:
uv sync --extra dev

.PHONY: format
format:
uv run ruff format
uv run ruff check --fix

.PHONY: type
type:
uv run mypy unilab

.PHONY: check
check: format type

.PHONY: test
test:
uv run pytest

.PHONY: test-fast
test-fast:
uv run pytest -m "not slow"

.PHONY: test-all
test-all: check test
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ brew install cmake # macOS
# sudo apt-get install cmake # Ubuntu/Debian

# 4. 同步依赖
# macOS (MPS)
uv sync

# Linux (CUDA 12.4)
uv sync --extra cu124

# 5. 可选:Motrix 后端
uv sync --extra motrix
```
Expand Down
15 changes: 6 additions & 9 deletions benchmark/benchmark_ane_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,30 @@

try:
from benchmark.core import (
bench_callable,
MLPBenchRecord,
bench_callable,
mlp_param_count,
trimmed_mean,
print_mlp_table,
trimmed_mean,
)
from benchmark.core.device_info import get_device_info_dict, get_device_info_line
except ModuleNotFoundError:
from core import bench_callable, MLPBenchRecord, mlp_param_count, trimmed_mean, print_mlp_table
from core import MLPBenchRecord, bench_callable, mlp_param_count, print_mlp_table, trimmed_mean
from core.device_info import get_device_info_dict, get_device_info_line


import argparse
import json
import os
import warnings
import shutil
import tempfile
from dataclasses import asdict, dataclass
from dataclasses import asdict
from datetime import datetime, timezone
from pathlib import Path
from typing import Callable, Dict, List, Optional, Tuple

from typing import Dict, List, Optional

import coremltools as ct
import numpy as np
import torch
import coremltools as ct

try:
import matplotlib
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark_ane_peak.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from dataclasses import asdict, dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import List, Optional
from typing import List

import numpy as np

Expand Down
23 changes: 12 additions & 11 deletions benchmark/benchmark_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@

try:
from benchmark.core import (
available_backends,
bench_callable,
parse_sizes,
parse_dtypes,
mlx_dtype,
normalize_dtypes,
available_backends,
numpy_dtype,
torch_dtype,
mlx_dtype,
parse_dtypes,
parse_sizes,
print_table,
torch_dtype,
)
from benchmark.core.device_info import get_device_info_dict
except ModuleNotFoundError:
from core import (
available_backends,
bench_callable,
parse_sizes,
parse_dtypes,
mlx_dtype,
normalize_dtypes,
available_backends,
numpy_dtype,
torch_dtype,
mlx_dtype,
parse_dtypes,
parse_sizes,
print_table,
torch_dtype,
)
from core.device_info import get_device_info_dict

Expand Down Expand Up @@ -143,7 +143,8 @@ def run_torch_mps(size, warmup, repeat, dtype_name):
dt = torch_dtype(dtype_name)
a = torch.randn(size, size, dtype=dt, device="mps")
b = torch.randn(size, size, dtype=dt, device="mps")
sync = lambda: torch.mps.synchronize()
def sync():
return torch.mps.synchronize()

mm_t = bench_callable(lambda: a @ b, sync, warmup, repeat)
ew_t = bench_callable(
Expand Down
23 changes: 11 additions & 12 deletions benchmark/benchmark_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,35 @@
import math
import platform
import statistics
import time
from dataclasses import asdict, dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Callable, Dict, List, Tuple
from typing import Any, Dict, List, Tuple

try:
from benchmark.core import (
available_backends,
bench_callable,
parse_sizes,
parse_dtypes,
mlx_dtype,
normalize_dtypes,
available_backends,
numpy_dtype,
torch_dtype,
mlx_dtype,
parse_dtypes,
parse_sizes,
print_table,
torch_dtype,
)
from benchmark.core.device_info import get_device_info_dict, get_device_info_line
except ModuleNotFoundError:
from core import (
available_backends,
bench_callable,
parse_sizes,
parse_dtypes,
mlx_dtype,
normalize_dtypes,
available_backends,
numpy_dtype,
torch_dtype,
mlx_dtype,
parse_dtypes,
parse_sizes,
print_table,
torch_dtype,
)
from core.device_info import get_device_info_dict, get_device_info_line

Expand Down
5 changes: 2 additions & 3 deletions benchmark/benchmark_forward_reset_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import argparse
import sys
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import List, Tuple
from multiprocessing import cpu_count
from pathlib import Path

import mujoco
from mujoco import batch_forward
import numpy as np
from mujoco import batch_forward

try:
from benchmark.core.device_info import get_device_info_dict, get_device_info_line
Expand Down
11 changes: 6 additions & 5 deletions benchmark/benchmark_gpu_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
Usage: python scripts/benchmark_gpu_buffer.py
"""

import sys
import time

import numpy as np
import torch
import torch.nn as nn
import numpy as np
import time
import sys


def sync_device(device):
Expand Down Expand Up @@ -72,7 +73,7 @@ def benchmark_host_buffer(capacity, obs_dim, action_dim, batch_size, num_updates
indices = np.random.randint(0, capacity, size=batch_size)
obs = torch.from_numpy(obs_buf[indices].copy()).to(device, non_blocking=True)
actions = torch.from_numpy(actions_buf[indices].copy()).to(device, non_blocking=True)
next_obs = torch.from_numpy(next_obs_buf[indices].copy()).to(device, non_blocking=True)
torch.from_numpy(next_obs_buf[indices].copy()).to(device, non_blocking=True)
sync_device(device)

# Training step
Expand Down Expand Up @@ -111,7 +112,7 @@ def benchmark_gpu_buffer(capacity, obs_dim, action_dim, batch_size, num_updates,
indices = torch.randint(0, capacity, (batch_size,), device=device)
obs = obs_buf[indices]
actions = actions_buf[indices]
next_obs = next_obs_buf[indices]
next_obs_buf[indices]

# Training step
pred_actions = actor(obs)
Expand Down
3 changes: 1 addition & 2 deletions benchmark/benchmark_ipc_buffer_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
python benchmark/benchmark_ipc_buffer_layout.py
"""

import time
import sys
import time

import numpy as np
import torch


# ---------------------------------------------------------------------------
# helpers
# ---------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions benchmark/benchmark_ipc_index_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
python benchmark/benchmark_ipc_index_sort.py
"""

import time
import sys
import time

import numpy as np
import torch


# ---------------------------------------------------------------------------
# helpers
# ---------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions benchmark/benchmark_ipc_weight_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
python benchmark/benchmark_ipc_weight_sync.py
"""

import time
import sys
import threading
import time
from multiprocessing.shared_memory import SharedMemory

import numpy as np
import torch
import torch.nn as nn


# ---------------------------------------------------------------------------
# helpers
# ---------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions benchmark/benchmark_mj_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
from pathlib import Path
from typing import Dict, List

import matplotlib
import mujoco
from mujoco import rollout as mj_rollout
import matplotlib

matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
import numpy as np
from matplotlib.patches import Patch

_IS_MACOS = platform.system() == "Darwin"

Expand Down Expand Up @@ -536,7 +536,7 @@ def main():
if _IS_MACOS:
if not _has_native_mujoco_mlx_step():
raise RuntimeError("Native MLX step backend unavailable. Requires mujoco.mlx_step.")
print(f"macOS: native mlx_step available")
print("macOS: native mlx_step available")
else:
print(f"Non-macOS: using mujoco.rollout (1t vs {args.nthread}t)")

Expand Down
Loading
Loading