Download src/elyon_lm/data.py from unkony/gibridllm-code: direct link, hf CLI and curl.
- Browser
- Download file 659 Bytes
-
https://huggingface.co/unkony/gibridllm-code/resolve/main/src/elyon_lm/data.py
- Command line
-
hf download hf://unkony/gibridllm-code/src/elyon_lm/data.py
-
curl -L -o data.py https://huggingface.co/unkony/gibridllm-code/resolve/main/src/elyon_lm/data.py
659 Bytes
| """Данные для Elyon-LM: токены лежат в .bin (uint16), батчи берутся случайными окнами.""" | |
| from __future__ import annotations | |
| import numpy as np | |
| import torch | |
| def load_bin(path: str) -> np.ndarray: | |
| return np.memmap(path, dtype=np.uint16, mode="r") | |
| def get_batch(data: np.ndarray, batch_size: int, ctx: int, rng: np.random.Generator): | |
| ix = rng.integers(0, len(data) - ctx - 1, size=batch_size) | |
| x = np.stack([data[i:i + ctx] for i in ix]).astype(np.int64) | |
| y = np.stack([data[i + 1:i + 1 + ctx] for i in ix]).astype(np.int64) | |
| return torch.from_numpy(x), torch.from_numpy(y) | |