File size: 659 Bytes
c105f80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"""Данные для 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)