fix(m0): count only video windows that played 1080p60 under the cap they claim
- A window counts only when the player kept the asked quality and height the whole time and played the source's 60 fps; a player stuck below 1080p is a stage error, not a note. - Pauses, seeks and buffering are counted inside the page during the window, so a pause that ended before the last snapshot no longer passes as GPU stutter. - A capped window whose cap found nothing to pause, ran no pause cycle, or could not pause or resume a process is an error and does not count for the cap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,10 @@ from m0lib.llm_client import ChatClient, http_json
|
||||
# Blender's own upload (CC BY 3.0, 10:34, 4K and 1080p at 60 fps): no music claim, rarely ads.
|
||||
VIDEO_URL = "https://www.youtube.com/watch?v=aqz-KE-bpKQ"
|
||||
QUALITY = "hd1080"
|
||||
# What a counted window must have played: the asked quality at its height and the source's 60 fps (the
|
||||
# player's frame counter includes dropped frames, so a busy GPU does not lower it; a 30 fps format does).
|
||||
WANT = {"quality": QUALITY, "height": 1080, "fps": 60}
|
||||
MIN_FPS_SHARE = 0.8
|
||||
QUIET_S = 60 # the video alone, and Jarvis loaded but idle
|
||||
SETTLE_S = 5 # after a quality change or a seek, before a window starts
|
||||
MIN_LEFT_S = 240 # a window that could reach the end starts the video again first
|
||||
@@ -155,8 +159,11 @@ _INSTALL = """(() => {
|
||||
const v = document.querySelector('video.html5-main-video') || document.querySelector('video');
|
||||
if (!v || !v.requestVideoFrameCallback) return false;
|
||||
if (window.__m0 && window.__m0.v === v) return true;
|
||||
const m = window.__m0 = {v, shown: 0, last: null, maxGap: 0, gaps: [0, 0], waits: 0, ad: false};
|
||||
const m = window.__m0 = {v, shown: 0, last: null, maxGap: 0, gaps: [0, 0], waits: 0, pauses: 0, seeks: 0,
|
||||
ad: false, minH: v.videoHeight, maxH: v.videoHeight};
|
||||
v.addEventListener('waiting', () => { m.waits++; });
|
||||
v.addEventListener('pause', () => { m.pauses++; });
|
||||
v.addEventListener('seeking', () => { m.seeks++; });
|
||||
const tick = (now) => {
|
||||
if (m.last !== null) {
|
||||
const g = now - m.last;
|
||||
@@ -165,6 +172,7 @@ _INSTALL = """(() => {
|
||||
if (g > %(g1)d) m.gaps[1]++;
|
||||
}
|
||||
m.last = now; m.shown++;
|
||||
m.minH = Math.min(m.minH, v.videoHeight); m.maxH = Math.max(m.maxH, v.videoHeight);
|
||||
const p = document.getElementById('movie_player');
|
||||
if (p && p.classList.contains('ad-showing')) m.ad = true;
|
||||
v.requestVideoFrameCallback(tick);
|
||||
@@ -174,13 +182,14 @@ _INSTALL = """(() => {
|
||||
})()""" % {"g0": GAP_MS[0], "g1": GAP_MS[1]}
|
||||
|
||||
_RESET = "(() => { const m = window.__m0; m.shown = 0; m.last = null; m.maxGap = 0; m.gaps = [0, 0]; " \
|
||||
"m.waits = 0; m.ad = false; return true; })()"
|
||||
"m.waits = 0; m.pauses = 0; m.seeks = 0; m.ad = false; m.minH = m.maxH = m.v.videoHeight; return true; })()"
|
||||
|
||||
_SNAPSHOT = """(() => {
|
||||
const m = window.__m0, v = m.v, p = document.getElementById('movie_player');
|
||||
const q = v.getVideoPlaybackQuality();
|
||||
return {dropped: q.droppedVideoFrames, total: q.totalVideoFrames, shown: m.shown, max_gap_ms: m.maxGap,
|
||||
gaps: m.gaps, waits: m.waits, ad: m.ad || !!(p && p.classList.contains('ad-showing')),
|
||||
gaps: m.gaps, waits: m.waits, pauses: m.pauses, seeks: m.seeks, min_height: m.minH, max_height: m.maxH,
|
||||
ad: m.ad || !!(p && p.classList.contains('ad-showing')),
|
||||
paused: v.paused, ended: v.ended, time: v.currentTime, duration: v.duration,
|
||||
width: v.videoWidth, height: v.videoHeight,
|
||||
quality: p && p.getPlaybackQuality ? p.getPlaybackQuality() : null};
|
||||
@@ -321,10 +330,12 @@ def open_video_page(work: Path, url: str = VIDEO_URL, extra_args: tuple[str, ...
|
||||
# --------------------------------------------------------------------------
|
||||
# One measured window and the comparison.
|
||||
|
||||
def window_stats(before: dict, after: dict, seconds: float) -> dict:
|
||||
"""What the video did between two snapshots (``after`` also carries the shown-frame counters
|
||||
since the reset just before ``before``). A window with an ad, a pause, the end or a reload of the
|
||||
counters is kept but not counted (``valid`` False, with the reason)."""
|
||||
def window_stats(before: dict, after: dict, seconds: float, want: dict | None = None) -> dict:
|
||||
"""What the video did between two snapshots (``after`` also carries the counters kept since the
|
||||
reset just before ``before``). A window is kept but not counted (``valid`` False, with the
|
||||
reasons) when something other than the GPU could have changed it: an ad, a pause or a seek at
|
||||
any point, buffering, the end, a reload of the counters, or (with ``want``) another quality,
|
||||
height or a lower frame rate than the source's."""
|
||||
out: dict = {"seconds": round(seconds, 1)}
|
||||
reasons = []
|
||||
if after.get("total", 0) < before.get("total", 0) or after.get("dropped", 0) < before.get("dropped", 0):
|
||||
@@ -332,6 +343,10 @@ def window_stats(before: dict, after: dict, seconds: float) -> dict:
|
||||
for key, why in (("ad", "an ad was showing"), ("paused", "the video was paused"), ("ended", "the video ended")):
|
||||
if after.get(key):
|
||||
reasons.append(why)
|
||||
for key, why in (("pauses", "the video was paused during the window"),
|
||||
("seeks", "the video jumped during the window"), ("waits", "the video was buffering")):
|
||||
if after.get(key):
|
||||
reasons.append(f"{why} ({after[key]}x)")
|
||||
total = after.get("total", 0) - before.get("total", 0)
|
||||
dropped = after.get("dropped", 0) - before.get("dropped", 0)
|
||||
out.update(frames=total, dropped=dropped, shown=after.get("shown"),
|
||||
@@ -344,6 +359,17 @@ def window_stats(before: dict, after: dict, seconds: float) -> dict:
|
||||
quality=after.get("quality"), height=after.get("height"))
|
||||
if total <= 0 and not reasons:
|
||||
reasons.append("the video showed no frames")
|
||||
if want:
|
||||
got = {before.get("quality"), after.get("quality")}
|
||||
if got != {want["quality"]}:
|
||||
reasons.append(f"the quality was {'/'.join(sorted(str(q) for q in got))}, not {want['quality']}")
|
||||
heights = {before.get("height"), after.get("min_height"), after.get("max_height"), after.get("height")}
|
||||
heights.discard(None)
|
||||
if heights != {want["height"]}:
|
||||
reasons.append(f"the picture was {'/'.join(str(h) for h in sorted(heights))} lines high, "
|
||||
f"not {want['height']}")
|
||||
if out["fps"] is not None and total > 0 and out["fps"] < want["fps"] * MIN_FPS_SHARE:
|
||||
reasons.append(f"the video played {out['fps']} fps, not {want['fps']}")
|
||||
out["valid"] = not reasons
|
||||
if reasons:
|
||||
out["invalid_because"] = reasons
|
||||
@@ -367,8 +393,23 @@ def compare(rows: list[dict]) -> dict:
|
||||
return out
|
||||
|
||||
|
||||
def cap_problems(duty: dict, pids: list[int]) -> list[str]:
|
||||
"""Why a capped window did not run under the cap it claims: nothing to pause, no pause cycle,
|
||||
or a process that could not be paused or resumed at once."""
|
||||
out = []
|
||||
if not pids:
|
||||
out.append("the cap found no engine process to pause")
|
||||
elif not duty.get("cycles"):
|
||||
out.append("the cap paused nothing during the window")
|
||||
if duty.get("failed_processes"):
|
||||
out.append(f"{duty['failed_processes']} process(es) could not be paused or resumed at once")
|
||||
if duty.get("left_paused"):
|
||||
out.append(f"{duty['left_paused']} process(es) are still paused")
|
||||
return out
|
||||
|
||||
|
||||
def measure_window(page: VideoPage, work: Callable[[], dict] | None = None,
|
||||
seconds: float | None = None) -> tuple[dict, dict]:
|
||||
seconds: float | None = None, want: dict | None = WANT) -> tuple[dict, dict]:
|
||||
"""The video's stats over ``work()`` (or ``seconds`` of nothing), with the GPU's use meanwhile."""
|
||||
page.keep_room()
|
||||
page.reset()
|
||||
@@ -381,7 +422,7 @@ def measure_window(page: VideoPage, work: Callable[[], dict] | None = None,
|
||||
else:
|
||||
time.sleep(QUIET_S if seconds is None else seconds)
|
||||
after = page.snapshot()
|
||||
stats = window_stats(before, after, time.perf_counter() - t0)
|
||||
stats = window_stats(before, after, time.perf_counter() - t0, want)
|
||||
stats["gpu_util"] = util.summary()
|
||||
return stats, done
|
||||
|
||||
@@ -415,8 +456,10 @@ def measure(r: StageResult, s: "llm.Strata", preset: dict, context: int, stt_pyt
|
||||
if not start["started"]:
|
||||
r.error("video", start.get("error") or "the video did not start playing")
|
||||
return
|
||||
if start.get("quality") != quality:
|
||||
r.note(f"the player stayed at {start.get('quality')} instead of {quality}")
|
||||
if start.get("quality") != quality or start.get("height") != WANT["height"]:
|
||||
# Every window then plays something else; they are kept but none is counted.
|
||||
r.error("video", f"the player stayed at {start.get('quality')} ({start.get('height')} lines) "
|
||||
f"instead of {quality}")
|
||||
|
||||
def row(key: str, jarvis: str, cap: float | None = None) -> dict:
|
||||
x = {"key": key, "jarvis": jarvis, "gpu_cap": cap}
|
||||
@@ -472,8 +515,6 @@ def measure(r: StageResult, s: "llm.Strata", preset: dict, context: int, stt_pyt
|
||||
say(f" - Jarvis가 답하고 STT가 쉬지 않고 전사하는 중{' (GPU 95% 제한)' if cap else ''}")
|
||||
x = row(key, "busy", cap)
|
||||
pids = llm.cap_pids(s, stt) if cap else []
|
||||
if cap and not pids:
|
||||
r.error(f"video {key} gpu cap", "found no engine process to pause")
|
||||
|
||||
def work() -> dict:
|
||||
with gpucap.DutyCap(pids, cap or 1.0) as duty:
|
||||
@@ -487,8 +528,13 @@ def measure(r: StageResult, s: "llm.Strata", preset: dict, context: int, stt_pyt
|
||||
r.error(f"video {key}", err)
|
||||
if cap:
|
||||
x["gpu_cap"] = done["duty"]
|
||||
if x["gpu_cap"]["left_paused"]:
|
||||
r.error(f"video {key} gpu cap", f"{x['gpu_cap']['left_paused']} process(es) are still paused")
|
||||
problems = cap_problems(x["gpu_cap"], pids)
|
||||
for why in problems:
|
||||
r.error(f"video {key} gpu cap", why)
|
||||
if problems:
|
||||
# Not a capped window, so it must not count for the cap.
|
||||
stats["valid"] = False
|
||||
stats["invalid_because"] = stats.get("invalid_because", []) + problems
|
||||
keep(x, stats)
|
||||
busy = stt.finish()
|
||||
r["stt_busy"] = {k: busy.get(k) for k in ("status", "batch10_s", "single_s", "errors", "busy_share")
|
||||
|
||||
Reference in New Issue
Block a user