Files
hao-ai-lab-FastVideo/v2/deploy/card.py
T
SolitaryThinker 4e331eb7ff [refactor] v2: use absolute imports (v2.*) everywhere instead of relative
Mechanical conversion of every relative import under v2/ to an absolute v2.* path
(from .x / ..x / ...x -> from v2.<pkg>.x) so imports are unambiguous, grep-able, and
stable when code is copied/moved between entrypoints (VideoGenerator, CLI, server).

Surgical prefix-only rewrite: only the 'from <dots><module>' prefix changed — import
names, parentheses, multi-line formatting, comments, and ordering are byte-for-byte
preserved (no collapsing, no reorder, no unrelated reformatting).

- 471 imports across 125 files; v2/tests/ was already absolute (untouched).
- Validated: all 125 files compile, every 'from v2.* import' target resolves to a real
  module/package, zero relative imports remain (full sweep), CPU mini suite green
  (202 passed, 2 skipped).
2026-07-04 17:15:34 +00:00

71 lines
2.9 KiB
Python

"""DeploymentCard — what an engine exports to a fleet (design_v3 §14; designv2 Deployment plane).
> The engine exports a ``DeploymentCard`` and lets a fleet orchestrator route. ... The cost model is
> the SAME §6 object — one object, two consumers (the scheduler's budget and the fleet's routing input).
This is the contract our OWN fleet (``deploy/fleet.py``) consumes AND the Dynamo adapter
(``deploy/dynamo.py``) exports — so we are frontable by Dynamo without depending on it.
"""
from __future__ import annotations
import dataclasses
from dataclasses import dataclass, field
from typing import Any
from v2._enums import Capability
from v2.card import CostModel
@dataclass
class HealthSchema:
status: str = "healthy" # "healthy" | "draining" | "unhealthy"
in_flight: int = 0
queue_depth: int = 0
@dataclass
class SLOSchema:
slo_class: str = "standard" # "latency" | "throughput" | "cost"
max_concurrent: int = 8
@dataclass
class DeploymentCard:
engine_id: str
model_cards: list[str] = field(default_factory=list)
capabilities: frozenset[Capability] = frozenset()
role_pools: list = field(default_factory=list) # list[RolePoolSpec]
supported_programs: list[str] = field(default_factory=list)
cost_model: CostModel | None = None # the SAME §6 cost model
health: HealthSchema = field(default_factory=HealthSchema)
slo: SLOSchema = field(default_factory=SLOSchema)
def serves(self, model_id: str) -> bool:
return model_id in self.model_cards
def build_deployment_card(engine_id: str, model_cards: list, *, max_concurrent: int = 8,
slo_class: str = "standard", role_pools: list | None = None,
supported_programs: list[str] | None = None) -> DeploymentCard:
"""Export a DeploymentCard from the model cards an engine serves (design_v3 §14).
Picks a representative ``step_cost_model`` so the fleet/Dynamo route on the SAME cost object the
scheduler budgets with."""
caps: set = set()
cost_model = None
ids: list[str] = []
for c in model_cards:
ids.append(c.model_id)
caps |= set(c.capabilities.capabilities)
if cost_model is None:
for lp in c.loops.values():
if lp.step_cost_model is not None:
# own copy so online calibration of one card's cost doesn't alias another replica's
cost_model = dataclasses.replace(lp.step_cost_model,
coefficients=dict(lp.step_cost_model.coefficients))
break
return DeploymentCard(
engine_id=engine_id, model_cards=ids, capabilities=frozenset(caps),
role_pools=role_pools or [], supported_programs=supported_programs or [],
cost_model=cost_model, slo=SLOSchema(slo_class=slo_class, max_concurrent=max_concurrent))