File size: 865 Bytes
ca76ef5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | """The packed-batch record the model reads (a copy of model/loader.py's Batch, without the training loader)."""
from __future__ import annotations
from dataclasses import dataclass
from torch import Tensor
@dataclass
class Batch:
"""One packed microbatch on the GPU: every sequence is its own segment, positions restart at 0."""
x: Tensor # (N,) int64 inputs
y: Tensor # (N,) int64 targets (ignored by inference)
pos: Tensor # (N,) int32 position inside its segment (RoPE)
cu: Tensor # (S+1,) int32 segment offsets
cu64: Tensor # same offsets, int64 (fla)
cu_host: Tensor # same offsets, int64 on the CPU
row: int # longest segment
segs: int # segment count
weight: Tensor | None = None # (N,) loss weight per target; None = plain mean
@property
def tokens(self) -> int:
return self.x.numel()
|