"""PP-OSR-H на Modal: serverless GPU, $30 кредита в месяц на Starter. Подготовка (один раз): pip install modal modal token new # откроется браузер, логин modal secret create hf HF_TOKEN=hf_твой_токен Запуск: modal run modal_pposr.py # обучение modal run modal_pposr.py --images 30000 --steps 12000 """ from __future__ import annotations import os import modal APP = modal.App("pposr") VOL = modal.Volume.from_name("pposr-vol", create_if_missing=True) GPU = os.environ.get("MODAL_GPU", "T4") # T4 дешевле; L4 может требовать карту image = ( modal.Image.debian_slim(python_version="3.11") .pip_install("torch==2.5.1", "transformers>=4.44,<5", "datasets>=2.20", "pillow", "huggingface_hub>=0.24", "numpy", "pyyaml") ) CODE_REPO = "AdminHugging/ppai-code" MODEL_REPO = "AdminHugging/PP-OSR-Hydrogen" @APP.function(image=image, gpu=GPU, timeout=60 * 60 * 4, volumes={"/vol": VOL}, secrets=[modal.Secret.from_name("hf")]) def train(images: int = 30000, steps: int = 12000, hours: float = 3.5) -> str: import os import subprocess import sys os.environ["OSR_ROOT"] = "/vol/pposr" os.environ["OSR_IMAGES"] = str(images) os.environ["OSR_STEPS"] = str(steps) os.environ["OSR_HOURS"] = str(hours) from huggingface_hub import snapshot_download code = snapshot_download(CODE_REPO, repo_type="dataset", local_dir="/vol/code") print("код:", code, flush=True) script = os.path.join(code, "ppai", "colab_pposr.py") rc = subprocess.run([sys.executable, script]).returncode VOL.commit() return f"exit={rc}" @APP.local_entrypoint() def main(images: int = 30000, steps: int = 12000, hours: float = 3.5) -> None: print(train.remote(images=images, steps=steps, hours=hours))