RLMF-m6APred-Web / space_runtime.py
Yu-star's picture
Deploy RLMF-m6APred Gradio prediction service on ZeroGPU
91e62c1 verified
Raw History Blame Contribute Delete
702 Bytes
"""Prepare the shared backbone before ZeroGPU starts an inference worker."""
from __future__ import annotations
import os
ON_SPACE = bool(os.environ.get("SPACE_ID"))
if ON_SPACE:
import spaces # Set up CUDA emulation before importing torch or the model.
from rlmf import get_predictor
def _predict(dataset: str, sequence: str):
return get_predictor().predict(dataset, sequence)
if ON_SPACE:
# Only the forward pass and fold checkpoint application need the GPU slot.
# Initialize in the parent process, before any decorated function runs.
get_predictor(device="cuda").prepare()
predict_sequence = spaces.GPU(duration=20)(_predict)
else:
predict_sequence = _predict