DWSLM-256M-Base / dwslm /batch.py
dwsdubey's picture
DWSLM-256M release v1.0: weights, config, tokenizer, reference code, model card
ca76ef5 verified
Raw History Blame Contribute Delete
865 Bytes
"""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()