26 lines
828 B
Python
26 lines
828 B
Python
"""SAM3 engine control routes (REQ-192)."""
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
from backend import jobs
|
|
|
|
router = APIRouter(prefix="/api/sam3", tags=["sam3"])
|
|
|
|
|
|
@router.post("/release")
|
|
def release() -> dict:
|
|
"""Free the SAM3 model's VRAM now — never while the card is busy.
|
|
|
|
The same non-blocking `gpu_lock` rule as an interactive assist (REQ-065):
|
|
a job or assist in flight wins, and the caller is told to try again.
|
|
"""
|
|
if not jobs.gpu_lock.acquire(blocking=False):
|
|
raise HTTPException(409, "GPU busy — assist or job in flight, try again in a moment")
|
|
try:
|
|
from backend import sam3_engine
|
|
|
|
released = sam3_engine.release_engine()
|
|
return {"released": released, "model_loaded": sam3_engine.engine_is_loaded()}
|
|
finally:
|
|
jobs.gpu_lock.release()
|