Files
hao-ai-lab-FastVideo/v2/core/request/artifacts.py
T
Will Lin 1fe50c0092 [refactor] v2: group flat top-level into planes; isolate vendored under _vendor/
The v2 top level had grown to ~27 dirs + 13 loose files — half of them
single-concept abstraction shells (memory/ 86 LOC, transport/ 222, parity/ 178,
extend/ 226) and half vendored fastvideo code sitting as peers to the actual v2
design. Regroup to mirror README section 3 "Planes & dependency order":

  core/     enums+types, card, loop, program, parity, request, parallel
            (the model-native contracts; no kernels)
  runtime/  + folded-in substrate: cache, memory, transport, extend
            (the import graph shows only runtime consumes them; compile/cudagraph
            already lived here)
  serving/  + deploy/ (products / fleet)
  _vendor/  all copied fastvideo: models, layers, attention, configs, distributed,
            platforms, api, hooks, logging_utils, third_party + fastvideo_args/
            utils/logger/envs/forward_context — internal layout unchanged, still
            mirrors upstream for diffing

28 dirs + 13 root files -> 8 dirs + 6 root files. Pure mechanical move: 947
absolute-import paths rewritten (v2.X -> v2.{core,runtime,serving,_vendor}.X),
boundary-anchored so platform/ (native dispatch) and platforms/ (vendored CUDA
detect) no longer collide and neither does hooks/ vs extend/. Deleted the empty
v2/loader/. README section 3 + 16 updated; stale test count corrected
(34 files/216 tests -> 22 files/143 tests).

Validated: `import v2` stays torch-free; `v2/run_tests.py` and `pytest v2/tests/`
-> 143 passed, 2 skipped on the numpy toy backend. (On a GPU box force the toy
backend with CUDA_VISIBLE_DEVICES="" or detect() picks cuda.) No external importer
changed — examples use the re-exported `from v2 import VideoGenerator`.
2026-07-04 17:15:34 +00:00

61 lines
1.6 KiB
Python

"""Artifact — a named, typed output with provenance.
Each modality is its own typed artifact (e.g. audio carries its sample rate as a
field, not via an ``extra`` dict). 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 v2.core.types import TensorLike
from v2.core.request.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)