Publish model

From ayutaz/piper-plus · View interactive version

Publish model is an AI agent skill from the GitHub repository ayutaz/piper-plus. 学習済み Lightning checkpoint (.ckpt) を ONNX export → sanity check → RTF benchmark → HuggingFace upload まで連鎖実行する read-mostly skill。 export 仕様 (FP16 / EMA / emb_lang unify / opset 15) を `docs/spec/onnx-export-contract.toml` から取得し、Python/Rust の load smoke と、対応可能な追加 runtime の検証を行う。

How to use this skill

Skill file

Model Publish Pipeline Skill

Lightning checkpoint から HuggingFace 公開までを 1 つの skill に集約。 現状 4 ステップ手動運用 (export → infer test → RTF bench → HF push) で、 工程間の引き継ぎミスが頻発する。

memory feedback_merge_caution.md に従い、 publish (HuggingFace への push) は確認後に明示実行。 デフォルトは export + sanity + bench までで停止。

引数

現在の状態

フェーズ 1: 事前検査

# Checkpoint 存在 / サイズ確認
ls -la "$1"
file "$1"  # PyTorch Lightning checkpoint であることを確認

# Contract gate (drift 検出して bump 前 fail)
uv run python scripts/check_onnx_export_contract.py 2>&1 | tail -3
uv run python scripts/check_phoneme_set_version.py 2>&1 | tail -3

フェーズ 2: ONNX export

CLAUDE.md の推奨設定 (FP16 + EMA + stochastic + emb_lang 自動統一) を使う:

CUDA_VISIBLE_DEVICES="" uv run python -m piper_train.export_onnx \
    "$CKPT_PATH" "$OUTPUT_ONNX"

出力後の verification:

# ONNX checker / shape inference
uv run python -c "import onnx; m=onnx.load('$OUTPUT_ONNX'); onnx.checker.check_model(m); onnx.shape_inference.infer_shapes(m)"

# Size 確認 (FP16 で ~50% 削減されているか)
ls -la "$OUTPUT_ONNX"

フェーズ 3: Inference sanity check

# JSONL 1 行入力で推論テスト
echo '{"phoneme_ids": [1, 2, 3, 4, 5], "speaker_id": 0}' | \
    CUDA_VISIBLE_DEVICES="" uv run python -m piper_train.infer_onnx \
        --model "$OUTPUT_ONNX" --output-dir /tmp/sanity

# 出力 wav の sanity 確認
ls -la /tmp/sanity/*.wav

無音 / クリップ / 形状不一致を catch。

フェーズ 4: RTF benchmark (optional)

uv run python scripts/benchmark_runtime.py \
    --runtime "$BENCHMARK_RUNTIME" \
    --cli-cmd "$BENCHMARK_CLI_CMD" \
    --model "$OUTPUT_ONNX" --config "$OUTPUT_ONNX.json" \
    --text-file tests/fixtures/benchmark-texts.json --text-key short \
    --warmup 5 --runs 30 \
    --output "/tmp/rtf_$(basename "$OUTPUT_ONNX" .onnx).json"

baseline (README.md の Benchmark 表、 Xeon E5-2650 v4 / 25 phoneme 英文 / 27ms) と比較し、 ±30% 以内なら OK、 大きい drift があれば warning。

フェーズ 5: HuggingFace upload (apply モードでのみ)

# config.json も同送 (model_resolution_vectors.json で alias を canonical 化)
uv run python scripts/upload_model_to_hf.py \
    --onnx "$OUTPUT_ONNX" \
    --config "$OUTPUT_ONNX.json" \
    --repo "$HF_REPO"

upload_model_to_hf.py に license 指定の引数はない (引数は --repo / --config / --onnx / --config-remote-name / --onnx-remote-name / --commit-message / --dry-run)。 license は HF repo の model card (README.md の YAML license:) 側で管理する。

upload 後、 docs/spec/model-sha256-manifest.toml に新 entry を追加するための diff 提案 (sha256sum 値含む)。

フェーズ 6: runtime load 確認 (optional / 軽量検証)

Python/Rust で「model を load できるか」を確認し、追加 runtime は対象モデル・実装が対応している場合だけ確認する (full inference は時間がかかる)。公開 zs-v1 の検証範囲は、独立 PyPI 2.0.0 consumer と source 6-runtime CI の記録を分けて扱う:

# Python
uv run python -c "from piper_plus import PiperVoice; v = PiperVoice.load('$OUTPUT_ONNX', '$OUTPUT_ONNX.json'); print('Python: OK')"

# Rust
(cd src/rust && cargo run --release -p piper-plus-cli -- --model $OUTPUT_ONNX --text 'test' --output-file /tmp/r.wav 2>&1 | tail -3)

# Go / C# / C++ / WASM / Swift / Kotlin はオプション

注意

使用例

# 通常のリリース前 publish
/publish-model /data/piper/output-tsukuyomi-finetune-6lang-v2/last.ckpt

# Benchmark をスキップして export + sanity だけ
/publish-model /data/piper/last.ckpt --skip-benchmark

# 確認後 HuggingFace へ実 publish
/publish-model /data/piper/last.ckpt --repo ayousanz/piper-plus-newvoice --apply

期待効果

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.