From 08e0612d6029ad871d5f6bf25fcbecf944b78ebf Mon Sep 17 00:00:00 2001 From: Aditya Sanjeev Date: Tue, 11 Aug 2026 23:15:47 -0700 Subject: [PATCH] ePAI: GPU-resident export path (lossless ~1.85x) via EPAI_SCRIPT_PATH hook Profiling showed ePAI's export/convert is ~158s of CPU resampling of the 26-channel logits back to native res -- as costly as inference. This adds scripts/epai_predict.py (+ .sh wrapper) that reuses the fork's own export_prediction_from_logits (seg AND the PDAC/cyst/PNET findings CSV) but with the probabilities resample moved to GPU: measured ~50-60x on that stage (158s -> ~0.3s), 99.99% voxel agreement vs CPU (boundary jitter only, no lesion-level change) -> ~1.85x whole pipeline, no accuracy loss. Includes the fork-specific fix for determine_do_sep_z_and_axis returning the anisotropy axis as a bare scalar (standard nnU-Net returns a 1-element list), which otherwise crashes resample_torch's len(axis) assert on the separate-z path. Wired via the existing EPAI_SCRIPT_PATH hook in _run_epai_inference -- no change to the dispatch. Enable in prod by setting EPAI_SCRIPT_PATH to scripts/epai_predict.sh after the end-to-end parity check (seg + findings CSV identical to the bare-CLI path). --- flask-server/scripts/epai_predict.py | 108 +++++++++++++++++++++++++++ flask-server/scripts/epai_predict.sh | 8 ++ 2 files changed, 116 insertions(+) create mode 100644 flask-server/scripts/epai_predict.py create mode 100644 flask-server/scripts/epai_predict.sh diff --git a/flask-server/scripts/epai_predict.py b/flask-server/scripts/epai_predict.py new file mode 100644 index 00000000..f42c0e0b --- /dev/null +++ b/flask-server/scripts/epai_predict.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python3 +"""Optimized ePAI inference: GPU-resident export + the fork's own findings CSV. + +Drop-in for the bare `nnUNetv2_predict_from_modelfolder` call in +services/auto_segmentor.py, wired in via the EPAI_SCRIPT_PATH hook (which invokes: +`bash