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
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
"""Structured cancellation (design_v3 §6.4, §12).
|
|
|
|
"Cancellation is common-path, not exceptional" — vibe-directing makes abandoning
|
|
in-flight work the *normal* user action. Cancel takes effect at the next loop step
|
|
boundary: the driver checks the scope between steps, drops queued work, releases
|
|
LoopState + cache handles, and reports ``cancelled``.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from enum import Enum
|
|
|
|
|
|
class CancelKind(str, Enum):
|
|
REQUEST = "request"
|
|
LOOP = "loop"
|
|
STREAM = "stream"
|
|
SESSION = "session"
|
|
|
|
|
|
class Cancelled(Exception):
|
|
"""Raised at a step boundary when a CancelScope is tripped."""
|
|
|
|
|
|
@dataclass
|
|
class CancelScope:
|
|
kind: CancelKind = CancelKind.REQUEST
|
|
target_id: str = ""
|
|
_flag: list[bool] = field(default_factory=lambda: [False]) # shared mutable cell
|
|
|
|
def cancel(self) -> None:
|
|
self._flag[0] = True
|
|
|
|
@property
|
|
def cancelled(self) -> bool:
|
|
return self._flag[0]
|
|
|
|
def check(self) -> None:
|
|
"""Called by the driver at each step boundary."""
|
|
if self._flag[0]:
|
|
raise Cancelled(f"{self.kind.value}:{self.target_id}")
|