All MicroEvals
import base64 import json import os import shutil import sub...
Create MicroEval
Header image for import base64
import json
import os
import shutil
import sub...

import base64 import json import os import shutil import sub...

Prompt

import base64 import json import os import shutil import subprocess import threading import time import uuid from pathlib import Path from typing import Any, Literal import modal MODEL_ID = "MiniMaxAI/MiniMax-H3" MODEL_DIR = Path("/models/MiniMax-H3") OUTPUT_DIR = Path("/outputs") VLLM_OMNI_DIR = Path("/opt/vllm-omni") PORT = 8000 app = modal.App("minimax-h3-openai-api") image = ( modal.Image.from_registry("vllm/vllm-omni:minimax-h3", add_python="3.12") .apt_install("git", "curl", "ffmpeg", "ca-certificates") .pip_install("huggingface_hub>=0.32.0", "fastapi>=0.115.0", "httpx>=0.28.0", "pydantic>=2.10.0") .run_commands( "git clone --depth 1 https://github.com/vllm-project/vllm-omni.git /opt/vllm-omni", "python -m pip install --no-cache-dir -e /opt/vllm-omni", ) ) model_volume = modal.Volume.from_name("minimax-h3-model", create_if_missing=True) output_volume = modal.Volume.from_name("minimax-h3-outputs", create_if_missing=True) def require_env(name: str) -> str: value = os.environ.get(name) if not value: raise RuntimeError(f"Missing required environment variable: {name}") return value def wait_for_server(process: subprocess.Popen[str], timeout_seconds: int) -> None: deadline = time.monotonic() + timeout_seconds while time.monotonic() < deadline: if process.poll() is not None: raise RuntimeError(f"vLLM-Omni exited during startup with code {process.returncode}") probe = subprocess.run( ["curl", "--fail", "--silent", "--show-error", f"http://127.0.0.1:{PORT}/health"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False, ) if probe.returncode == 0: return time.sleep(5) process.terminate() try: process.wait(timeout=30) except subprocess.TimeoutExpired: process.kill() raise TimeoutError("Timed out waiting for vLLM-Omni to become healthy") def download_model() -> None: from huggingface_hub import snapshot_download token = require_env("HF_TOKEN") required = [MODEL_DIR / "model_index.json", MODEL_DIR / "FL2VA", MODEL_DIR / "Ref2VA"] if all(path.exists() for path in required): return MODEL_DIR.parent.mkdir(parents=True, exist_ok=True) snapshot_download( repo_id=MODEL_ID, local_dir=str(MODEL_DIR), token=token, resume_download=True, ) model_volume.commit() @app.cls( gpu="H200", timeout=60 * 60, container_idle_timeout=300, scaledown_window=300, min_containers=0, max_containers=1, volumes={"/models": model_volume, "/outputs": output_volume}, secrets=[modal.Secret.from_name("minimax-h3-secrets")], image=image, ) class MiniMaxH3Server: @modal.enter() def start(self) -> None: download_model() OUTPUT_DIR.mkdir(parents=True, exist_ok=True) environment = os.environ.copy() environment.update( { "CUDA_VISIBLE_DEVICES": "0", "VLLM_WORKER_MULTIPROC_METHOD": "spawn", "VLLM_OMNI_VIDEO_SYNC_TIMEOUT": "1800", "PYTHONPATH": f"{VLLM_OMNI_DIR}:{environment.get('PYTHONPATH', '')}", } ) command = [ "vllm", "serve", str(MODEL_DIR), "--omni", "--task-type", "fl2va", "--host", "0.0.0.0", "--port", str(PORT), "--trust-remote-code", "--num-gpus", "1", "--enable-cpu-offload", "--diffusion-attention-backend", "FLASH_ATTN", "--init-timeout", "1800", ] self.process = subprocess.Popen(command, env=environment, stdout=None, stderr=None, text=True) wait_for_server(self.process, 1800) @modal.exit() def stop(self) -> None: if hasattr(self, "process") and self.process.poll() is None: self.process.terminate() try: self.process.wait(timeout=30) except subprocess.TimeoutExpired: self.process.kill() @modal.asgi_app(label="minimax-h3-openai", requires_proxy_auth=True) def api(self): import httpx from fastapi import FastAPI, File, Form, HTTPException, Request, UploadFile from fastapi.responses import FileResponse, JSONResponse, Response server = FastAPI(title="MiniMax-H3 OpenAI-Compatible Video API", version="1.0.0") client = httpx.AsyncClient(timeout=httpx.Timeout(3600.0, connect=30.0)) async def forward(request: Request, endpoint: str) -> Response: headers = {key: value for key, value in request.headers.items() if key.lower() not in {"host", "content-length"}} content = await request.body() try: upstream = await client.request( request.method, f"http://127.0.0.1:{PORT}{endpoint}", content=content, headers=headers, ) except httpx.HTTPError as exc: raise HTTPException(status_code=503, detail=str(exc)) from exc passthrough_headers = {} for key in ("content-type", "content-disposition", "content-length"): if key in upstream.headers: passthrough_headers[key] = upstream.headers[key] return Response(content=upstream.content, status_code=upstream.status_code, headers=passthrough_headers) @server.get("/health") async def health() -> JSONResponse: try: response = await client.get(f"http://127.0.0.1:{PORT}/health") response.raise_for_status() except httpx.HTTPError as exc: raise HTTPException(status_code=503, detail=str(exc)) from exc return JSONResponse({"status": "ok", "model": MODEL_ID}) @server.get("/v1/models") async def models() -> JSONResponse: return JSONResponse( { "object": "list", "data": [ { "id": MODEL_ID, "object": "model", "created": 0, "owned_by": "self-hosted", } ], } ) @server.api_route("/v1/videos", methods=["POST"]) async def videos(request: Request) -> Response: return await forward(request, "/v1/videos") @server.api_route("/v1/videos/sync", methods=["POST"]) async def videos_sync(request: Request) -> Response: return await forward(request, "/v1/videos/sync") @server.get("/v1/videos/{video_id}") async def video_status(video_id: str, request: Request) -> Response: query = f"?{request.url.query}" if request.url.query else "" return await forward(request, f"/v1/videos/{video_id}{query}") @server.get("/v1/files/{file_id}") async def retrieve_file(file_id: str, request: Request) -> Response: query = f"?{request.url.query}" if request.url.query else "" return await forward(request, f"/v1/files/{file_id}{query}") return server @app.local_entrypoint() def deploy() -> None: pass Send back the complete code with all the fixes. Fix each of the listed errors one by one, making sure to actually correct them so that there are 0 errors remaining. Keep the original imports, since the files exist. Write out every single character; do not abbreviate anything. Fix every error. There must be exactly one file. Do not write anything else; just output the complete code, and it must not contain any comments. Never, under any circumstances, use simplified, substitute, dummy, simulated, or fake code. Write the entire file as complete, unabridged, production-ready code in a single code block. It must be 100% error-free, a complete, error-free file, and must be submitted as a downloadable file. These requirements are mandatory and must be strictly adhered to. If no list of errors is provided, you must find all the errors and fix them. If there were comments in the original code, delete them. And most importantly: YOU MUST NEVER SIMPLIFY!