A scoped, CPU-testable realization of design_v3.md — the architecture where the atomic unit is a typed (recipe, runtime) ModelCard, the model owns loop semantics while the runtime owns loop lifecycle, one resident instance runs many loops, and training records behavior on the same loops it serves. Implements: - card/ loop/ runtime/ cache/ memory/ parallel/ parity/ extend/ program/ request/ training/ spanning design_v3 §4-§13: ModelCard + validate(); driven loops (init/next/advance/finalize); step-interleaving Engine with reservation-before-admission + per-class caches keyed by CacheKey; the C0-C4 consistency ladder + the non-negotiable batch-of-N interleave parity gate. - Inference: Wan2.1-1.3B (T2V), LTX2.3 (two-stage distilled, shared transformer), Wan-causal (chunk rollout + slab-KV streaming). - Training (Wan2.1-1.3B), each driving the SAME loops the engine serves: finetune (flow-match), DMD2 (teacher/critic distribution matching), DiffusionNFT (likelihood-free C2, samples from the decay-blended old policy, group-relative advantages, shared-prompt cache reuse), self-forcing (causal chunk loop). The engine never imports training (the §10 dependency rule, grep-verified). numpy-only core (no torch/GPU here); heavy Wan/LTX forwards are deterministic toy stand-ins with lazy torch-adapter seams (ComponentSpec.load_id/factory) for a GPU box. 49 tests pass via pytest and a zero-dependency runner; interleave parity verified (and a buggy module-global interceptor provably breaks it). Omni-ready spine (ar_decode/chunk_step loop kinds, multi-loop instances, LoopState.extension) for the phase-2 Cosmos3 + vllm-omni omni ports. Run: python3 -m pytest mini_fastvideo/tests/ -q ; python3 -m mini_fastvideo.examples
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
"""Request parameters: AR sampling vs diffusion params + output/capture spec.
|
|
|
|
design_v3 §12: "AR ``sampling`` vs ``diffusion`` params, an ``OutputSpec``
|
|
(requested modalities + streaming + capture flags), and per-node overrides."
|
|
design.md §6.1: ``sampling``/``diffusion`` are *defaults*; ``node_params`` override
|
|
per graph node (validated against the PipelineSpec's node-parameter schema).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from enum import Enum
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class SamplingParams:
|
|
"""AR decode knobs (used by ar_decode loops: reasoner/thinker/talker — phase 2)."""
|
|
max_tokens: int = 512
|
|
temperature: float = 1.0
|
|
top_p: float = 1.0
|
|
top_k: int = 0
|
|
stop: tuple[str, ...] = ()
|
|
seed: int | None = None
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class DiffusionParams:
|
|
"""Denoise knobs. ``guidance`` may be a scalar or per-modality dict (joint A/V)."""
|
|
num_steps: int = 50
|
|
guidance_scale: float = 5.0
|
|
# Per-modality guidance for joint denoise (LTX-2 A/V, Cosmos3 t2vs). Empty => use scalar.
|
|
guidance_per_modality: dict[str, float] = field(default_factory=dict)
|
|
shift: float = 5.0 # flow-match sigma shift
|
|
sigmas: tuple[float, ...] | None = None # explicit schedule (distilled few-step)
|
|
negative_prompt: str = ""
|
|
height: int = 480
|
|
width: int = 832
|
|
num_frames: int = 81
|
|
fps: int = 16
|
|
seed: int | None = None
|
|
|
|
|
|
class CaptureMode(str, Enum):
|
|
"""What the loop captures while running (design_v3 §9.4, §10)."""
|
|
NONE = "none" # serve forward: no-grad, no capture
|
|
BEHAVIOR = "behavior" # rollout forward: emit BehaviorRecord slices for RL/distill
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class OutputSpec:
|
|
modalities: frozenset[str] = frozenset({"video"})
|
|
# streaming flags per modality: True | chunk size (ms / frames). {} => no streaming.
|
|
stream: dict[str, object] = field(default_factory=dict)
|
|
return_latents: bool = False
|
|
return_trajectory: bool = False # full denoise trajectory (parity / debug)
|
|
capture: CaptureMode = CaptureMode.NONE
|
|
|
|
@property
|
|
def streaming(self) -> bool:
|
|
return bool(self.stream)
|