Files
hao-ai-lab-FastVideo/mini_fastvideo/parallel/plan.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

47 lines
1.8 KiB
Python

"""ParallelPlan — parallelism as a model contract (design_v3 §8).
Parallelism is not a launch flag; it affects cache keys, scheduling, transport,
capture, and parity, so it lives on the card. Declarative, validated, compiled to a
mesh via a ParallelDims-style builder (``parallel/mesh.py``). This module is a pure
leaf (no card/runtime imports) so ``card/`` can hold plans without a cycle.
"""
from __future__ import annotations
import hashlib
import json
from dataclasses import dataclass, field
# Canonical axis names (design_v3 §8). cfgp is ≤2.
AXIS_NAMES = ("dp", "tp", "sp", "cp", "cfgp", "pp_patch", "vae", "ep", "fsdp", "role", "replica")
@dataclass
class ParallelPlan:
axes: dict[str, int] = field(default_factory=dict) # e.g. {"tp": 2, "sp": 4, "cfgp": 2}
mesh_order: list[str] = field(default_factory=list)
placement: str = "colocated"
communication: dict[str, str] = field(default_factory=dict)
# design_v3 §8 + omni-readiness §4b: applicability conditions travel with axes
applicability: dict[str, dict] = field(default_factory=dict)
per_axis_communication: dict[str, str] = field(default_factory=dict)
def degree(self, axis: str) -> int:
return int(self.axes.get(axis, 1))
def world_size(self) -> int:
w = 1
for v in self.axes.values():
w *= int(v)
return max(w, 1)
@property
def hash(self) -> str:
"""Stable hash — part of the CacheKey (design_v3 §7.1: parallel_plan_hash)."""
payload = json.dumps({"axes": self.axes, "order": self.mesh_order}, sort_keys=True)
return hashlib.sha256(payload.encode()).hexdigest()[:16]
@classmethod
def single(cls) -> "ParallelPlan":
"""The default deployment: one device, all degree-one trivial groups."""
return cls(axes={"dp": 1}, mesh_order=["dp"])