Spaces:
Sleeping
Sleeping
Add optional adapted-model GPU inference diagnostic
Browse files
app.py
CHANGED
|
@@ -23,13 +23,34 @@ if not (source / "models" / "base" / "config.json").exists():
|
|
| 23 |
subprocess.run([sys.executable, str(source / "scripts" / "download_model.py")], check=True)
|
| 24 |
|
| 25 |
import gradio as gr
|
|
|
|
| 26 |
from fastapi import FastAPI
|
| 27 |
from interval.server import app as research_app, status
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
with gr.Blocks() as diagnostics:
|
| 30 |
gr.Markdown("# Interval runtime\nEmbedded model and numerical-service status. The research workspace is available at the root URL.")
|
| 31 |
output = gr.JSON(value=status())
|
| 32 |
gr.Button("Refresh runtime status").click(status, outputs=output, api_name="runtime_status")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
app = gr.mount_gradio_app(FastAPI(), diagnostics, path="/runtime-status")
|
| 35 |
app.mount("/", research_app)
|
|
|
|
| 23 |
subprocess.run([sys.executable, str(source / "scripts" / "download_model.py")], check=True)
|
| 24 |
|
| 25 |
import gradio as gr
|
| 26 |
+
import spaces
|
| 27 |
from fastapi import FastAPI
|
| 28 |
from interval.server import app as research_app, status
|
| 29 |
|
| 30 |
+
|
| 31 |
+
@spaces.GPU(duration=30)
|
| 32 |
+
def check_gpu_planner(request):
|
| 33 |
+
"""Optional GPU inference check; the research workspace executes on CPU."""
|
| 34 |
+
if not isinstance(request, str) or not 3 <= len(request) <= 1500:
|
| 35 |
+
raise gr.Error("Enter a research request of 3–1500 characters.")
|
| 36 |
+
import torch
|
| 37 |
+
from interval.planner import load_model, score_candidates
|
| 38 |
+
tokenizer, model = load_model()
|
| 39 |
+
model.to("cuda")
|
| 40 |
+
scores = score_candidates(tokenizer, model, request)
|
| 41 |
+
return {"recipe": max(scores, key=scores.get), "candidate_scores": scores,
|
| 42 |
+
"device": str(next(model.parameters()).device),
|
| 43 |
+
"scope": "Diagnostic inference only; numerical execution is available in the main workspace."}
|
| 44 |
+
|
| 45 |
+
|
| 46 |
with gr.Blocks() as diagnostics:
|
| 47 |
gr.Markdown("# Interval runtime\nEmbedded model and numerical-service status. The research workspace is available at the root URL.")
|
| 48 |
output = gr.JSON(value=status())
|
| 49 |
gr.Button("Refresh runtime status").click(status, outputs=output, api_name="runtime_status")
|
| 50 |
+
gr.Markdown("## Optional GPU planner check\nRun the same adapted model on an allocated GPU. This checks procedure selection; it does not launch numerical experiments.")
|
| 51 |
+
request = gr.Textbox(value="Compare the background estimators on this study", label="Research request")
|
| 52 |
+
gpu_output = gr.JSON(label="GPU procedure proposal")
|
| 53 |
+
gr.Button("Check adapted planner on GPU").click(check_gpu_planner, inputs=request, outputs=gpu_output, api_name="gpu_planner_check")
|
| 54 |
|
| 55 |
app = gr.mount_gradio_app(FastAPI(), diagnostics, path="/runtime-status")
|
| 56 |
app.mount("/", research_app)
|