Skip to content

test: run one unattended Codex optimization and validate latency on Ascend A2 - #677

Open
zengchuang-hw wants to merge 6 commits into
mainfrom
codex/479-qwen-image-e2e-pytest
Open

zengchuang-hw wants to merge 6 commits into
mainfrom
codex/479-qwen-image-e2e-pytest

Conversation

@zengchuang-hw

@zengchuang-hw zengchuang-hw commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Refs #479

本 PR 增加一个 Ascend A2 上的黑盒 E2E 用例。测试者提供固定环境和一条自然语言请求,启动一次 pytest。用例独立检验 Codex 能否在无人值守的情况下连续完成 3 轮叠加优化,并交付第三轮结束后的累计补丁。主要指标是累计版本相对原始基线的单张生图耗时降幅百分比,性能验收门槛为严格大于 10%。

黑盒测试图

flowchart TB
    E["测试条件<br/>单卡 A2、固定基线和只读模型"]
    I["测试输入<br/>用户请求、固定生图负载"]
    L1["第 1 轮<br/>原始 B0 → 改进 B1 · 实测反馈"]
    L2["第 2 轮<br/>从 B1 继续改进为 B2 · 实测反馈"]
    L3["第 3 轮<br/>从 B2 继续改进为累计 B3"]
    V["独立复测<br/>原始 B0 ↔ 累计 B3 · 校验像素和源码"]
    R["输出<br/>累计补丁、最终降幅百分比、严格大于 10% 才通过"]
    E --> L1
    I --> L1
    L1 --> L2 --> L3 --> V --> R
Loading

测试条件与输入

  • 环境。 Linux Ascend A2,进程只看见一张空闲的 Ascend 910B。预先准备已登录的 Codex CLI、可用的 InferRSI、与固定基线匹配的 vLLM-Omni 昇腾依赖,以及同一份本地只读 Qwen-Image-2.1-Turbo 权重。vLLM-Omni 固定为 f69b1f2b19cece03f6736c7da093ea25de0e24fd(见 task: 设计首个 Codex 用户使用 InferRSI 的端到端用例 #479)。原始基线从这个提交开始,第二、三轮分别从上一轮的累计源码继续,QWEN_E2E_REVISION 使用该完整 SHA。
  • 用户输入。「请用 InferRSI 优化当前 vLLM-Omni 项目的 Qwen-Image-2.1-Turbo,在 Ascend A2 单卡上生成 1280×704 图片,保持出图质量,把单张生图耗时降到尽可能低。请连续完成 3 轮叠加优化,每轮都基于上一轮优化后的源码,结合实测反馈继续改进。第三轮结束后,复测叠加三轮的最终版本,与原始基线比较,并交付累计补丁、优化前后单张生图耗时和最终降幅百分比。」用例自动附上模型、测量程序和本次 campaign 的位置。启动后无需人工答复、审批、补录记录或挑选候选。
  • 固定负载。 workload.json 固定 2 次预热和 6 个测量输入(种子 42–47)。1280×704、BF16、请求 8 步、CFG=1、每请求 1 张图。基线与候选使用相同负载。从调用 Omni.generate 到取得解码图像计时,模型加载、预热和 PNG 写盘分别处理。
QWEN_E2E_MIN_GAIN_PCT=10 python -m pytest -qs e2e/qwen_image/test_user_journey.py

启动前配置 QWEN_E2E_REPO、QWEN_E2E_REVISION 和 QWEN_E2E_CHECKPOINT。本次显式使用 QWEN_E2E_MIN_GAIN_PCT=10,用例在测量前将门槛写入运行计划。完整运行说明

可观察输出与校验点

校验点 输出与检查
基线可重复 两个独立进程各跑一组基线。逐种子比较 6 张图的解码 RGBA 字节,并核对测量配置凭证。将两组中位耗时的相对差冻结为 A/A 噪声参考,保存在 frozen.json。
三轮连续叠加 保留每轮 InferRSI campaign 的起点、候选摘要和实测反馈。核对第 1 轮从原始基线开始,第 2、3 轮分别继承上一轮实测过的候选源码。三轮均须有耗时证据并通过像素校验,交付源码须匹配第三轮结束的累计快照。
补丁可独立重建 提取并保留 candidate.patch。从另一份干净基线应用补丁,核对重建后的 vllm_omni/ Git 树与交付源码一致。
画质和耗时可复核 A 为原始基线,B 为在干净基线上重建的第三轮累计版本,按 AB → BA → AB 复测。每侧每组使用新进程,保留图像和原始耗时。各组图像逐种子与最初的基线比较。汇总取每侧三个组中位数的中位数。

result.json 记录阶段、要求完成的轮数、实际完成轮数与每轮源码继承关系、判定及错误原因。复测完成时还记录基线与候选耗时、节省毫秒数、降幅、加速比和像素不一致的种子。主要指标为第三轮累计版本相对原始基线的最终降幅,按 100 × (原始基线耗时 − 第三轮累计版本耗时) / 原始基线耗时 计算。

通过与失败

判定 条件
PASS 三轮叠加、源码重建和像素校验均通过,第三轮累计版本相对原始基线的最终降幅严格大于 10%。
FAIL 完整复测的最终降幅小于或等于 10%,包括恰好 10%。空补丁、重建源码不一致或复测图像像素变化也判失败。
INCONCLUSIVE 基线图像或测量环境不一致,或执行证据不足。

降幅用未四舍五入的值判定。A/A 波动记录在结果中,作为测量参考。FAIL 和 INCONCLUSIVE 都使 pytest 返回非零,具体原因见 result.json。

A2 独立复测结果

在单张 Ascend 910B3 上,按 AB → BA → AB 独立复测原始基线 B0 和第三轮累计版本 B3。下表耗时为各侧三个组中位数的中位数。

对照项 单张生图耗时
原始基线 B0 3408.20 ms
第三轮累计版本 B3 3063.93 ms

最终降幅为 10.101%,严格大于 10%,用例判定通过(PASS)。 36 张复测图均与对应种子的基线 RGBA 像素一致。

当前验证状态

  • pytest 收集到 1 个用例,Ruff、编译检查和 8 项本地冒烟测试通过。7 个 CPU 模拟场景得到预期判定,覆盖补丁提取与重建、像素变化、无收益、低于门槛、噪声内收益、基线漂移和空补丁。
  • 变更前的同基线用例曾因 Codex 连接模型服务超时,在原始基线完成后中止,结果为 INCONCLUSIVE。
  • 累计用例的 7 项本地回归均符合预期,覆盖三轮叠加、错误基线、重复源码、像素变化、少跑一轮、缺少测量和交付前一轮版本。本机 Codex 与单卡 A2 的累计用例复跑已完成,已核对三轮源码继承关系、第三轮补丁重建结果,以及六组独立复测的像素和原始耗时。
  • 五项本地边界检查已完成,覆盖大于、等于和小于门槛,以及像素变化和缺少门槛配置。冻结新门槛和三轮累计补丁后,已在单卡 A2 完成新的六组独立复测,保留了原始耗时和像素校验结果。
  • 采样条件校验的当前覆盖范围是请求传入的 sample_sigmas。本地模拟实际步数从 8 减到 7 时,凭证仍一致,实际执行的网格和步数仍待校验。

Exercise the natural-language entry point, recompute round decisions and independent results, and verify the delivered source against the measured candidate. Keep historical replay and the real Codex/A2 run opt-in.

Agent-assisted-by: Codex (implementation and verification)
Signed-off-by: zengchuang <[email protected]>
Agent-assisted-by: Codex (implementation and verification)
Signed-off-by: zengchuang <[email protected]>
@Dong1017 Dong1017 added kind:task Bounded delivery task with a delegated slice area:harness Harness module: profile, A/B loop, quality gates, evidence reports labels Nov 25, 2026

@david6666666 david6666666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot, acting for @david6666666 under delegated PR review.

Static review of the opt-in test and audit; no live Codex or Ascend run.

Comment thread e2e/qwen_image/test_user_journey.py Outdated
plan, _ = seal(options["project"], options["baseline_revision"], campaign,
options["patch"], output / "independent", submission=submission)
execute(output / "independent", plan, options["timeout_seconds"])
report = audit(campaign, options["observer"], host_reply=output / "final-reply.txt")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot, acting for @david6666666 under delegated PR review.

The local-retest path writes the new receipt to output / "independent", but audit() then reads observer["independent_directory"] relative to the observer directory. If the observer and output are separate, the audit can ignore the just-run attempt and use a different receipt for the same patch, or report missing evidence even after the retest succeeded. Please bind the live audit to the directory it just created and add a local-mode regression with a different observer receipt and separate directories.

… on A2

Agent-assisted-by: Codex (implementation and verification)
Signed-off-by: zengchuang <[email protected]>
@zengchuang-hw zengchuang-hw changed the title test: add end-to-end pytest coverage for the Codex Qwen-Image workflow test: run one unattended Codex optimization and validate latency on Ascend A2 Nov 25, 2026

@david6666666 david6666666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot, acting for @david6666666 under delegated PR review.

Static review of the rewritten unattended A2 path; no live Codex or NPU run.

Comment thread e2e/qwen_image/measure.py
"model_index_sha256": hashlib.sha256(model_bytes).hexdigest(), "sample_sigmas": sigmas,
"seeds": [case["seed"] for case in workload["requests"]],
"warmup_ms": warmup_ms, "latencies_ms": latencies_ms, "median_ms": median(latencies_ms),
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot, acting for @david6666666 under delegated PR review.

sample_sigmas here records the requested values from workload.json, not the grid the scheduler actually executed. A candidate can change how those values are handled and this receipt still matches the baseline. #479 requires the effective grid to be retained for the compared runs. Capture the effective timestep/sigma sequence and step count at the runtime boundary and reject a mismatch; add a regression that keeps the requested values unchanged while the effective grid differs.

Freeze the exact round budget in the user journey and verify it against the completed campaign before independent retest.

Agent-assisted-by: Codex (implementation and verification)
Signed-off-by: zengchuang <[email protected]>

@david6666666 david6666666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot, acting for @david6666666 under delegated PR review.

The new exact-three assertion still permits three submissions of the same unchanged candidate. I verified this in isolation with the exact optimize function and controlled campaign records; no live Codex or A2 run.

Comment thread e2e/qwen_image/test_user_journey.py Outdated
# The campaign and final reply must both belong to this fresh invocation.
plan = json.loads((campaign / "plan.json").read_bytes())
state = json.loads((campaign / "state.json").read_bytes())
completed_rounds = len(state["rounds"])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This counts records, not effective optimization iterations. I ran the current optimize() with a synthetic completed campaign whose three rounds and final all held the same candidate digest; it returned 3. The governing #479 contract explicitly excludes an unchanged repeat from the optimization-candidate count. Validate retained round identities/evidence (source and declared candidate configuration), and add a negative fixture with three records but only one real change. A real distinct candidate may still count if its measured result is rejected.

Bind each measured round to the preceding candidate source. Independently compare the third accumulated result with the original baseline.

Agent-assisted-by: Codex (implementation and verification)
Signed-off-by: zengchuang <[email protected]>

@david6666666 david6666666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot, acting for @david6666666 under delegated PR review.

PR review verdict — DO NOT PASS. Score: 26/100. Base 0ae7d0d5aca5a523786a19c98b1d18bf9b37783e7 is not the review base; the exact reviewed base is 0ae7d0d5aca90bf9725cf9661ba2897996e68a1d, head ae01db16ec09aac9ef73c6af0d9022ae53530430.

The prior repeated-candidate case is now rejected by the chained snapshots. The new inline finding concerns binding the independent retest to the third measured snapshot. Ratings (0–3): scope 1 (the governing workflow calls for selected-source replay); correctness 0 (the reconstructed source can differ); validation 2 (Ready CI and CPU controls, no completed A2 run); claim evidence N/A (no completed model-run result claimed); simplicity 0 (new explanatory code comment).

report.update(completed_optimization_rounds=len(loops), optimization_loops=loops)

report["stage"] = "reconstruct"
git(project, "add", "-A", "--", "vllm_omni")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final Git patch can drop files that were part of the third measured snapshot. identity(..., ["vllm_omni"]) includes ignored files, but git add -A skips new ignored files. I confirmed this in a clean local Git repo with one changed tracked module and one new ignored helper: the two Git trees can match while the measured snapshot had both files. Compare the rebuilt source digest with loops[-1]["candidate_sha256"] before retesting (and add that ignored-file regression), or use the same file manifest for both snapshot and patch.

Require a run-specific threshold and reject results at or below it. Preserve the A/A timing observations and compare the unrounded cumulative gain.

Agent-assisted-by: Codex (implementation and verification)
Signed-off-by: zengchuang <[email protected]>

@david6666666 david6666666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot, acting for @david6666666 under delegated PR review.

PR review verdict — DO NOT PASS. Score: 18/100. Reviewed base 0ae7d0d5aca90bf9725cf9661ba2897996e68a1d, head f34850a703b9a9faa11352124c8ccd91728182f8.

The strict comparison rejects a result of exactly 10% when the run is configured for 10%. The new inline finding concerns the effective minimum and the removal of the A/A confidence check. The prior candidate-digest finding is unchanged. Ratings (0–3): scope 1 (governing acceptance case not bound), correctness 0 (verdict and replay can diverge from the contract), validation 2 (exact Ready CI passed; local arithmetic check only), claim evidence 0 (the reported A2 runs do not link their generated PNGs or raw timings), simplicity 0 (explanatory code comments in the full diff).

speedup=before / after, quality_passed=len(reference) - len(failed_seeds),
quality_total=len(reference), failed_seeds=sorted(failed_seeds))
report["verdict"] = (
"PASS" if not failed_seeds and gain > Decimal(str(minimum)) else "FAIL"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can report PASS below the PR’s stated >10% acceptance floor, and it no longer checks the measured A/A noise. I evaluated the pinned verdict logic with clean pixels: a configured floor of 1% and a measured 2% gain pass; a floor of 10%, an 11% gain and 14% A/A variation also pass. Can we reject any configuration below the fixed 10% acceptance floor and make a gain inside the frozen noise window INCONCLUSIVE, as a separate check? Please retain both cases as regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:harness Harness module: profile, A/B loop, quality gates, evidence reports kind:task Bounded delivery task with a delegated slice

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants