{ "nbformat": 4, "nbformat_minor": 5, "metadata": { "colab": {"name": "AIFlow Math Ink 0.6 LiteRT"}, "kernelspec": {"display_name": "Python 3", "name": "python3"} }, "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# AIFlow Math Ink 0.6 — LiteRT 변환\n", "\n", "공개 seed-17 composite 모델을 공식 LiteRT Torch 0.9.1로 변환하고 실제 대표 입력 76개의 PyTorch/LiteRT parity를 검사합니다. 출력 gate를 통과하기 전에는 Android 배포 artifact로 취급하지 않습니다." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip -q install litert-torch==0.9.1 pillow huggingface-hub\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import hf_hub_download\n", "from pathlib import Path\n", "from zipfile import ZipFile\n", "import hashlib, json\n", "\n", "repo = 'cwLeeDev/aiflow-math-ink-06-intermediate'\n", "archive = Path(hf_hub_download(repo_id=repo, filename='colab/aiflow_math_ink_06_litert_bundle.zip'))\n", "root = Path('/content/aiflow_math_ink_06_litert')\n", "root.mkdir(parents=True, exist_ok=True)\n", "with ZipFile(archive) as bundle:\n", " bundle.extractall(root)\n", "manifest = json.loads((root / 'LITERT_COLAB_BUNDLE_MANIFEST.json').read_text(encoding='utf-8'))\n", "for row in manifest['files']:\n", " payload = (root / row['path']).read_bytes()\n", " assert len(payload) == row['bytes']\n", " assert hashlib.sha256(payload).hexdigest() == row['sha256']\n", "print('bundle verified:', len(manifest['files']), 'files')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%cd /content/aiflow_math_ink_06_litert\n", "!PYTHONPATH=src python scripts/export_math_ink_06_litert.py \\\n", " --checkpoint artifacts/base_378.pt \\\n", " --adapter-checkpoint artifacts/online_adapter.pt \\\n", " --representative-inputs artifacts/representative_inputs.pt \\\n", " --convert-litert --output outputs\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "report = json.loads((root / 'outputs/export_manifest.json').read_text(encoding='utf-8'))\n", "assert report['torch_export_gate_passed']\n", "assert report['litert']['online']['gate_passed']\n", "assert report['litert']['raster']['gate_passed']\n", "total_bytes = report['litert']['online']['bytes'] + report['litert']['raster']['bytes']\n", "assert total_bytes <= 25 * 1024 * 1024\n", "print('LiteRT gate passed, total bytes:', total_bytes)\n", "report\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from google.colab import files\n", "import shutil\n", "shutil.make_archive('/content/aiflow_math_ink_06_litert_outputs', 'zip', root / 'outputs')\n", "files.download('/content/aiflow_math_ink_06_litert_outputs.zip')\n" ] } ] }