文件
Evo-RL/tests/value/test_lerobot_value_infer_sampler.py
Elvin 3a87382ba4 chore(ci): make quality checks pass across repo
- fix ruff violations in dataset, recording, and value modules

- fix typos findings and markdown/workflow lint issues

- update pages workflow checkout to disable credential persistence

- apply pre-commit auto-formatting and EOF normalization

- include requested repo housekeeping updates (.gitignore and README)
2026-03-04 11:02:06 +08:00

51 行
1.4 KiB
Python

#!/usr/bin/env python
from lerobot.scripts.lerobot_value_infer import ContiguousDistributedEvalSampler
def test_contiguous_distributed_eval_sampler_has_contiguous_shards_with_tail_padding():
dataset_size = 10
world_size = 3
shards: list[list[int]] = []
for rank in range(world_size):
sampler = ContiguousDistributedEvalSampler(
dataset_size=dataset_size, num_replicas=world_size, rank=rank
)
shard = list(iter(sampler))
shards.append(shard)
assert len(shard) == len(sampler) == 4
assert shards[0] == [0, 1, 2, 3]
assert shards[1] == [4, 5, 6, 7]
assert shards[2] == [8, 9, 9, 9]
covered = set()
for shard in shards:
covered.update(shard)
assert covered == set(range(dataset_size))
def test_contiguous_distributed_eval_sampler_handles_more_ranks_than_samples():
dataset_size = 2
world_size = 4
shards: list[list[int]] = []
for rank in range(world_size):
sampler = ContiguousDistributedEvalSampler(
dataset_size=dataset_size, num_replicas=world_size, rank=rank
)
shard = list(iter(sampler))
shards.append(shard)
assert len(shard) == len(sampler) == 1
assert shards[0] == [0]
assert shards[1] == [1]
assert shards[2] == [1]
assert shards[3] == [1]
covered = set()
for shard in shards:
covered.update(shard)
assert covered == set(range(dataset_size))