/** * video_rvq.ts — VideoRVQCodec: the pixels ⇄ tokens bottleneck that lets Evermind * generate video without changing the generator. * * Evermind is a discrete-token autoregressive SSM. To make it a video model you * do NOT touch the model — you give it a codec that maps a clip to a stream of * discrete tokens and back. This is the visual analogue of the BPE tokenizer: * where BPE turns text ⇄ ids, VideoRVQCodec turns frames ⇄ ids. * * Design — TEMPORAL residual vector quantization (the "video-from-the-start" * choice): * * • Each frame is cut into non-overlapping p×p patches; each patch is a vector * of length p·p·C (the "latent"). * • KEYFRAMES (frame 0 and every `keyframeInterval`-th frame) are quantized * directly against the INTRA codebook bank. * • Every other frame is INTER: we quantize the *residual against the previous * RECONSTRUCTED frame* against the INTER bank. Video is mostly temporally * redundant, so these deltas are small and cheap — this is exactly why an * SSM (linear-time in sequence length) is the right generator for the long * token streams video produces. * • Quantization at each bank is RESIDUAL VQ over `levels` codebooks: level 0 * picks the nearest entry, level 1 quantizes what level 0 missed, and so on. * More levels ⇒ finer reconstruction ⇒ more tokens per patch. * * The encoder runs closed-loop (it references its own reconstruction, never the * ground-truth previous frame) so the decoder — which only ever has * reconstructions — stays exactly in sync. * * Codebooks start random (a cold codec is lossy, like any untrained neural * codec) and are learned by {@link VideoRVQCodec.fit} (greedy per-level k-means). * Reaching photoreal fidelity needs training on a real corpus with real compute * — that is the one genuine blocker on shipping generated video, not the wiring. * * Pure CPU, zero deps, deterministic under a seed — same conventions as the rest * of the engine. A WGSL/WebGPU acceleration is a future drop-in with these shapes. */ import { MultimodalVocab } from "./multimodal_vocab.js"; /** A single frame: length `height·width·channels`, layout `((y·W)+x)·C + ch`, values in [0,1]. */ export type Frame = Float32Array; /** A clip: T frames, all the same shape. */ export type Video = Frame[]; export interface VideoRVQConfig { height: number; width: number; /** Colour channels. Default 3 (RGB). */ channels?: number; /** Square patch size; `height` and `width` must be divisible by it. Default 4. */ patch?: number; /** Residual-VQ depth (codes per patch). Default 2. */ levels?: number; /** Codebook entries per level per bank. Default 16. */ codebookSize?: number; /** Emit a keyframe every N frames (frame 0 is always a keyframe). Default 12. */ keyframeInterval?: number; /** Size of the text region this codec's tokens sit above; 0 ⇒ pure-video vocab. Default 0. */ textVocabSize?: number; /** Deterministic seed for codebook init. */ seed?: number; } export declare class VideoRVQCodec { readonly height: number; readonly width: number; readonly channels: number; readonly patch: number; readonly levels: number; readonly codebookSize: number; readonly keyframeInterval: number; /** Patch latent dimension = patch·patch·channels. */ readonly latentDim: number; /** Patches per frame = (H/patch)·(W/patch). */ readonly patchesPerFrame: number; /** Code tokens emitted per frame = patchesPerFrame·levels. */ readonly tokensPerFrame: number; /** The unified text+video vocabulary; feed `.vocab.size` to EvermindLM. */ readonly vocab: MultimodalVocab; /** Two banks × levels codebooks; each codebook is `codebookSize × latentDim` row-major. */ private readonly banks; constructor(config: VideoRVQConfig); /** Total vocabulary size for this codec's model. */ get vocabSize(): number; /** * Serialize config + learned codebooks to a compact "VRQ0" binary. A generated * video model is only servable if its codec travels with it (the decoder needs * these codebooks), so this is the video analogue of EvermindLM.exportWeights. */ serialize(): ArrayBuffer; /** Reconstruct a codec (config + codebooks) from a "VRQ0" binary. */ static deserialize(buffer: ArrayBuffer): VideoRVQCodec; /** Encode a clip to a self-delimiting token stream: ` (marker codes…)… `. */ encode(video: Video): number[]; /** * Decode a token stream back to frames. Tolerant by design: it skips text / * stray tokens, treats a frame whose codes run short as zero-padded, and stops * at `` or end-of-stream — so a stream sampled from an under-trained * generator still yields a valid (if noisy) clip instead of throwing. */ decode(tokens: number[]): Video; /** * Learn both codebook banks from a set of clips (greedy per-level k-means over * residuals — the standard way to train residual VQ). Returns the mean * reconstruction MSE over the training clips after fitting. This is the codec's * "training"; the generator is trained separately on the resulting token streams. */ fit(videos: Video[], opts?: { iterations?: number; seed?: number; }): number; /** Fit one bank's `levels` codebooks greedily over residuals. */ private fitBank; private rvqEncode; private toPatches; private fromPatches; private assertShape; } //# sourceMappingURL=video_rvq.d.ts.map