cmvr-visual/inference/scripts/verify_reference_profile.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
Restructure backend and frontend modules; add story, library, and editor schema migrations.

Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews.

Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
2026-11-14 14:07:26 +08:00

119 lines
4.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""只读校验Edit权重/版本/token预算;不下载、不启动模型、不开放能力。"""
import argparse
import json
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from llm_services.reference_profiles import DEFAULT_PROFILE, PROFILES, get_profile
from scripts import download_models as downloader
def verify_checkpoint(profile, model, metadata):
model = Path(model).resolve(strict=True)
metadata = json.loads(Path(metadata).read_text(encoding="utf-8"))
manifest = json.loads((model / ".deployment-manifest.json").read_text(encoding="utf-8"))
if (
metadata.get("sha") != profile.revision
or manifest.get("revision") != profile.revision
or manifest.get("repo") != profile.repo
):
raise ValueError("Checkpoint revision/repository differs from the explicit profile")
selected = downloader.select_files(metadata["siblings"], "plain")
names = {item["rfilename"] for item in selected}
required = {
"model_index.json",
"tokenizer/vocab.json",
"tokenizer/tokenizer_config.json",
"processor/preprocessor_config.json",
"scheduler/scheduler_config.json",
"text_encoder/config.json",
"transformer/config.json",
"vae/config.json",
}
if required - names or any(
not any(
name.startswith(component + "/") and name.endswith(".safetensors") for name in names
)
for component in ("text_encoder", "transformer", "vae")
):
raise ValueError("Checkpoint component set is incomplete")
listed = {entry["path"] for entry in manifest.get("files", [])}
if names - listed:
raise ValueError("Deployment manifest omits canonical checkpoint files")
total = 0
for item in selected:
path = (model / item["rfilename"]).resolve()
if not path.is_relative_to(model) or not (
item.get("lfs", {}).get("sha256") or item.get("blobId")
):
raise ValueError("Checkpoint checksum metadata or path is invalid")
if not downloader.matches_checkpoint_file(path, item):
raise ValueError("Checkpoint checksum mismatch: " + item["rfilename"])
total += path.stat().st_size
index = json.loads((model / "model_index.json").read_text(encoding="utf-8"))
if index.get("_class_name") != "QwenImageEditPlusPipeline":
raise ValueError("Checkpoint is not the expected EditPlus pipeline")
return {
"profile": profile.name,
"repo": profile.repo,
"revision": profile.revision,
"verified_files": len(selected),
"bytes": total,
"available": False,
"reason": "Offline integrity alone does not certify runtime, resources, preemption or quality",
}
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--profile", choices=sorted(PROFILES), default=DEFAULT_PROFILE)
parser.add_argument("--model-directory", type=Path)
parser.add_argument("--metadata", type=Path)
parser.add_argument(
"--tokenize", help="Optional actual local tokenizer prompt preflight; CPU only"
)
parser.add_argument("--negative-prompt", default="")
parser.add_argument("--image-count", type=int, default=3)
args = parser.parse_args()
profile = get_profile(args.profile)
model = args.model_directory or Path(profile.directory)
metadata = args.metadata or Path("/workspace/projects/llm-services/config/metadata") / (
model.name + ".json"
)
report = verify_checkpoint(profile, model, metadata)
if args.tokenize is not None:
from transformers import Qwen2Tokenizer
from llm_services.adapters import reference_omni_inputs
tokenizer = Qwen2Tokenizer.from_pretrained(
str(model), subfolder="tokenizer", local_files_only=True
)
reference_omni_inputs(
{
"input": {
"prompt": args.tokenize,
"negative_prompt": args.negative_prompt,
"image_paths": ["token-budget-only"] * args.image_count,
},
"parameters": {
"profile": profile.name,
"height": 704,
"width": 1280,
"seed": 42,
"num_inference_steps": 40,
"guidance_scale": 1.0,
"true_cfg_scale": 4.0,
"max_sequence_length": profile.max_sequence_length,
},
},
tokenizer,
)
report["token_budget_passed"] = True
print(json.dumps(report, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()