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`.
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""Observers + interceptors. Per-request interceptor state is interleave-safe; a module-global
|
|
version provably is NOT — which is why state is scoped to ``LoopState.plugin_state`` per request
|
|
and per CFG branch.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from v2.runtime.extend import (
|
|
InterceptorChain,
|
|
InterceptorConflict,
|
|
NaNWatch,
|
|
ResidualSkipInterceptor,
|
|
)
|
|
from v2.recipes import build_default_engine
|
|
from v2.core.request import DiffusionParams, TaskType, make_request
|
|
from v2.runtime import Engine
|
|
|
|
|
|
def _req(prompt, seed):
|
|
return make_request(TaskType.T2V, "wan2.1-1.3b", prompt,
|
|
diffusion=DiffusionParams(num_steps=6, seed=seed))
|
|
|
|
|
|
def test_residual_skip_interceptor_skips():
|
|
eng = build_default_engine(Engine(interceptors=InterceptorChain([ResidualSkipInterceptor(interval=2)])))
|
|
out = eng.run(_req("c", 3))
|
|
assert out.metrics.get("skipped_steps", 0) > 0 # the cache-dit-style skip actually fired
|
|
|
|
|
|
def test_conflicting_distribution_altering_interceptors_rejected():
|
|
try:
|
|
InterceptorChain([ResidualSkipInterceptor(), ResidualSkipInterceptor()])
|
|
assert False, "two step-skippers must be rejected pre-flight"
|
|
except InterceptorConflict:
|
|
pass
|
|
|
|
|
|
def test_exact_mode_rejects_distribution_altering():
|
|
try:
|
|
InterceptorChain([ResidualSkipInterceptor()], exact_mode=True)
|
|
assert False
|
|
except InterceptorConflict:
|
|
pass
|
|
|
|
|
|
def test_nanwatch_clean_on_good_run():
|
|
eng = build_default_engine()
|
|
nan = NaNWatch()
|
|
eng.observers.add(nan)
|
|
eng.run(_req("x", 1))
|
|
assert not nan.tripped # clean run, no NaNs
|