Download verl/workers/rollout/arithmetic_sampling.py from LeTue09/arithmetic-grpo: direct link, hf CLI and curl.
- Browser
- Download file 561 Bytes
-
https://huggingface.co/LeTue09/arithmetic-grpo/resolve/main/verl/workers/rollout/arithmetic_sampling.py
- Command line
-
hf download hf://LeTue09/arithmetic-grpo/verl/workers/rollout/arithmetic_sampling.py
-
curl -L -o arithmetic_sampling.py https://huggingface.co/LeTue09/arithmetic-grpo/resolve/main/verl/workers/rollout/arithmetic_sampling.py
561 Bytes
| import random | |
| from functools import lru_cache | |
| def make_arithmetic_codes(group_size: int, seed: int) -> tuple[float, ...]: | |
| if group_size < 1: | |
| raise ValueError(f"group_size must be positive, got {group_size}") | |
| shift = random.Random(seed).random() | |
| return tuple(((i + 0.5) / group_size + shift) % 1.0 for i in range(group_size)) | |
| def get_arithmetic_code(group_size: int, seed: int, rollout_n: int) -> float: | |
| codes = make_arithmetic_codes(group_size=group_size, seed=seed) | |
| return codes[rollout_n % len(codes)] | |