Files
hao-ai-lab-FastVideo/mini_fastvideo/request/artifacts.py
T
SolitaryThinker 270fae959d [feat] mini-fastvideo: model-native runtime per design_v3 (Wan2.1/LTX2 + 4 training methods)
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
2026-07-04 17:15:33 +00:00

61 lines
1.7 KiB
Python

"""Artifact — a named, typed output with provenance (design_v3 §12).
"This kills the ``extra['audio']`` pattern — audio carries its sample rate as a
first-class artifact, not a dict passenger." Every artifact records which program
node produced it (``producer``), so multi-modal fan-out outputs are traceable.
"""
from __future__ import annotations
from dataclasses import dataclass, field
from .._types import TensorLike
from .modalpart import Modality
@dataclass
class Artifact:
name: str # output slot name, e.g. "video", "audio", "text"
producer: str = "" # program node id that produced it (provenance)
meta: dict[str, object] = field(default_factory=dict)
@dataclass
class VideoArtifact(Artifact):
frames: TensorLike = None # T x H x W x C
fps: int = 16
@dataclass
class AudioArtifact(Artifact):
samples: TensorLike = None
sample_rate: int = 44100 # first-class, not an extra-dict passenger
@dataclass
class TextArtifact(Artifact):
token_ids: tuple[int, ...] = ()
text: str = ""
@dataclass
class TensorArtifact(Artifact):
tensor: TensorLike = None # generic (e.g. action stream)
@dataclass
class LatentArtifact(Artifact):
latent: TensorLike = None
of_modality: Modality = Modality.VIDEO
@dataclass
class Output:
"""The collected result of running a program for one request."""
request_id: str
artifacts: dict[str, Artifact] = field(default_factory=dict)
metrics: dict[str, float] = field(default_factory=dict)
error: str | None = None # set on partial/aborted delivery (failure isolation)
def get(self, name: str) -> Artifact | None:
return self.artifacts.get(name)