| fix(modal): deploy under modal>=1.4 + numpy<2 ABI + JSON-safe handlers Applied while standing up the BioDesignBench leaderboard's reference MCP on romero-lab Modal workspace. The existing deploy/modal_app.py was last tested with Modal <1.4 and hit eight independent issues on a modern Modal client. These changes make modal deploy succeed end to end and the live endpoint serve JSON-correct tool results. Modal API renames (2025 migration) * container_idle_timeout=300 -> scaledown_window=300 * @modal.web_endpoint(...) -> @modal.fastapi_endpoint(...) * .env(...) must run BEFORE .add_local_python_source(...) -- Modal now rejects any build step after add_local_*. pip dependency resolution * Use extra_index_url (not index_url) for the pytorch cu118 wheels so pip can still pull wheel/setuptools from the default PyPI. * Add fastapi[standard] to the ESM+MCP pip_install layer -- @fastapi_endpoint requires FastAPI to be in the image, not just the local driver env. * Pin numpy<2 on every subsequent .pip_install(...) layer. torch 2.0.1 was compiled against numpy 1.x's C API; any later layer pulling numpy 2.x triggers Failed to initialize NumPy: _ARRAY_API not found and every .numpy() call on the tensor raises "Numpy is not available" at runtime. * Remove the colabfold[alphafold] install. The source never imports colabfold or alphafold directly (structure prediction uses ESMFold via pipelines.esmfold), and colabfold[alphafold] 1.6.1 hard-pins numpy>=2.0.2, which is unsatisfiable alongside torch 2.0.1's numpy<2 requirement. Runtime JSON serialization * New _json_safe() wrapper around every handler result. Tool pipelines return numpy arrays (aa_log_probs, pLDDT grids, etc.) that FastAPI's pydantic serializer rejects with PydanticSerializationError: Unable to serialize unknown type: <class 'numpy.ndarray'>. The wrapper does a json.dumps/loads roundtrip with a numpy-aware default encoder to guarantee plain-python output. * The exception handler now also returns the traceback (last 1.5 KB) as a traceback field to speed up future remote debugging. Smoke-tested on the romero-lab Modal deployment with score_stability on a 48-residue peptide: endpoint returns sequence_score, per_residue_scores, aa_log_probs (48 x 20), sequence_length. No serialization errors. | 4 个月前 |