Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,4 @@ Available Tasks
Value Set Completion (VSAC) <tasks/pyhealth.tasks.ValueSetCompletion>
Time-to-event survival (GBSG and SUPPORT) <tasks/pyhealth.tasks.survival_time_to_event>
TCGA RNA-seq Survival Prediction <tasks/pyhealth.tasks.TCGASurvivalPrediction>
Multimodal Mortality Prediction (MIMIC-IV) <tasks/pyhealth.tasks.multimodal_mimic4>
19 changes: 19 additions & 0 deletions docs/api/tasks/pyhealth.tasks.multimodal_mimic4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pyhealth.tasks.multimodal_mimic4
================================

Mortality prediction from MIMIC-IV labs and admission-context notes.

.. autoclass:: pyhealth.tasks.multimodal_mimic4.BaseMultimodalMIMIC4Task
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.tasks.multimodal_mimic4.NotesLabsMIMIC4
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.tasks.multimodal_mimic4.LabsMIMIC4
:members:
:undoc-members:
:show-inheritance:
38 changes: 38 additions & 0 deletions examples/benchmark_perf/benchmark_workers_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class RunResult:
base_cache_bytes: int
task_cache_bytes: int
peak_rss_bytes: int
peak_pss_bytes: int | None # None where PSS is unavailable
open_fds: int # after the run; should stay flat across runs (-1 if unsupported)


Expand Down Expand Up @@ -110,6 +111,7 @@ def __init__(self, poll_interval_s: float = 0.1) -> None:
self._stop = threading.Event()
self._lock = threading.Lock()
self._peak = 0
self._peak_pss = None # no valid PSS sample yet
self._thread = threading.Thread(target=self._run, daemon=True)

def start(self) -> None:
Expand All @@ -118,14 +120,44 @@ def start(self) -> None:
def reset(self) -> None:
with self._lock:
self._peak = 0
self._peak_pss = None

def stop(self) -> None:
self._stop.set()

def peak_pss_bytes(self) -> int | None:
with self._lock:
return self._peak_pss

def peak_bytes(self) -> int:
with self._lock:
return self._peak

def _total_pss_bytes(self) -> int | None:
"""Proportional set size across the process tree.

Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total is additive.
Returns None where PSS is unavailable for any process in the tree
(non-Linux, or no perms): that sample is not a PSS total, so the
peak column is left empty for the run rather than holding RSS.
"""
total = 0
try:
procs = [self._proc] + self._proc.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return None
for p in procs:
try:
total += p.memory_full_info().pss
except AttributeError:
return None
except psutil.NoSuchProcess:
pass
except psutil.AccessDenied:
return None
return total

def _total_rss_bytes(self) -> int:
total = 0
try:
Expand All @@ -142,9 +174,14 @@ def _total_rss_bytes(self) -> int:
def _run(self) -> None:
while not self._stop.is_set():
rss = self._total_rss_bytes()
pss = self._total_pss_bytes()
with self._lock:
if rss > self._peak:
self._peak = rss
if pss is not None and (
self._peak_pss is None or pss > self._peak_pss
):
self._peak_pss = pss
time.sleep(self._poll_interval_s)


Expand Down Expand Up @@ -335,6 +372,7 @@ def main() -> None:
base_cache_bytes=base_cache_bytes,
task_cache_bytes=task_cache_bytes,
peak_rss_bytes=peak_rss_bytes,
peak_pss_bytes=tracker.peak_pss_bytes(),
open_fds=open_fds,
)
)
Expand Down
38 changes: 38 additions & 0 deletions examples/benchmark_perf/benchmark_workers_n_drug_recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RunResult:
base_cache_bytes: int
task_cache_bytes: int
peak_rss_bytes: int
peak_pss_bytes: int | None # None where PSS is unavailable


def format_size(size_bytes: int) -> str:
Expand Down Expand Up @@ -108,6 +109,7 @@ def __init__(self, poll_interval_s: float = 0.1) -> None:
self._stop = threading.Event()
self._lock = threading.Lock()
self._peak = 0
self._peak_pss = None # no valid PSS sample yet
self._thread = threading.Thread(target=self._run, daemon=True)

def start(self) -> None:
Expand All @@ -116,14 +118,44 @@ def start(self) -> None:
def reset(self) -> None:
with self._lock:
self._peak = 0
self._peak_pss = None

def stop(self) -> None:
self._stop.set()

def peak_pss_bytes(self) -> int | None:
with self._lock:
return self._peak_pss

def peak_bytes(self) -> int:
with self._lock:
return self._peak

def _total_pss_bytes(self) -> int | None:
"""Proportional set size across the process tree.

Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total is additive.
Returns None where PSS is unavailable for any process in the tree
(non-Linux, or no perms): that sample is not a PSS total, so the
peak column is left empty for the run rather than holding RSS.
"""
total = 0
try:
procs = [self._proc] + self._proc.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return None
for p in procs:
try:
total += p.memory_full_info().pss
except AttributeError:
return None
except psutil.NoSuchProcess:
pass
except psutil.AccessDenied:
return None
return total

def _total_rss_bytes(self) -> int:
total = 0
try:
Expand All @@ -140,9 +172,14 @@ def _total_rss_bytes(self) -> int:
def _run(self) -> None:
while not self._stop.is_set():
rss = self._total_rss_bytes()
pss = self._total_pss_bytes()
with self._lock:
if rss > self._peak:
self._peak = rss
if pss is not None and (
self._peak_pss is None or pss > self._peak_pss
):
self._peak_pss = pss
time.sleep(self._poll_interval_s)


Expand Down Expand Up @@ -331,6 +368,7 @@ def main() -> None:
base_cache_bytes=base_cache_bytes,
task_cache_bytes=task_cache_bytes,
peak_rss_bytes=peak_rss_bytes,
peak_pss_bytes=tracker.peak_pss_bytes(),
)
)

Expand Down
38 changes: 38 additions & 0 deletions examples/benchmark_perf/benchmark_workers_n_length_of_stay.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RunResult:
base_cache_bytes: int
task_cache_bytes: int
peak_rss_bytes: int
peak_pss_bytes: int | None # None where PSS is unavailable


def format_size(size_bytes: int) -> str:
Expand Down Expand Up @@ -108,6 +109,7 @@ def __init__(self, poll_interval_s: float = 0.1) -> None:
self._stop = threading.Event()
self._lock = threading.Lock()
self._peak = 0
self._peak_pss = None # no valid PSS sample yet
self._thread = threading.Thread(target=self._run, daemon=True)

def start(self) -> None:
Expand All @@ -116,14 +118,44 @@ def start(self) -> None:
def reset(self) -> None:
with self._lock:
self._peak = 0
self._peak_pss = None

def stop(self) -> None:
self._stop.set()

def peak_pss_bytes(self) -> int | None:
with self._lock:
return self._peak_pss

def peak_bytes(self) -> int:
with self._lock:
return self._peak

def _total_pss_bytes(self) -> int | None:
"""Proportional set size across the process tree.

Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total is additive.
Returns None where PSS is unavailable for any process in the tree
(non-Linux, or no perms): that sample is not a PSS total, so the
peak column is left empty for the run rather than holding RSS.
"""
total = 0
try:
procs = [self._proc] + self._proc.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return None
for p in procs:
try:
total += p.memory_full_info().pss
except AttributeError:
return None
except psutil.NoSuchProcess:
pass
except psutil.AccessDenied:
return None
return total

def _total_rss_bytes(self) -> int:
total = 0
try:
Expand All @@ -140,9 +172,14 @@ def _total_rss_bytes(self) -> int:
def _run(self) -> None:
while not self._stop.is_set():
rss = self._total_rss_bytes()
pss = self._total_pss_bytes()
with self._lock:
if rss > self._peak:
self._peak = rss
if pss is not None and (
self._peak_pss is None or pss > self._peak_pss
):
self._peak_pss = pss
time.sleep(self._poll_interval_s)


Expand Down Expand Up @@ -331,6 +368,7 @@ def main() -> None:
base_cache_bytes=base_cache_bytes,
task_cache_bytes=task_cache_bytes,
peak_rss_bytes=peak_rss_bytes,
peak_pss_bytes=tracker.peak_pss_bytes(),
)
)

Expand Down
38 changes: 38 additions & 0 deletions examples/benchmark_perf/legacy_ver/benchmark_legacy_drug_rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class RunResult:
total_s: float
base_cache_bytes: int
peak_rss_bytes: int
peak_pss_bytes: int | None # None where PSS is unavailable
num_samples: int


Expand Down Expand Up @@ -186,6 +187,7 @@ def __init__(self, poll_interval_s: float = 0.1) -> None:
self._stop = threading.Event()
self._lock = threading.Lock()
self._peak = 0
self._peak_pss = None # no valid PSS sample yet
self._thread = threading.Thread(target=self._run, daemon=True)

def start(self) -> None:
Expand All @@ -194,14 +196,44 @@ def start(self) -> None:
def reset(self) -> None:
with self._lock:
self._peak = 0
self._peak_pss = None

def stop(self) -> None:
self._stop.set()

def peak_pss_bytes(self) -> int | None:
with self._lock:
return self._peak_pss

def peak_bytes(self) -> int:
with self._lock:
return self._peak

def _total_pss_bytes(self) -> int | None:
"""Proportional set size across the process tree.

Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total is additive.
Returns None where PSS is unavailable for any process in the tree
(non-Linux, or no perms): that sample is not a PSS total, so the
peak column is left empty for the run rather than holding RSS.
"""
total = 0
try:
procs = [self._proc] + self._proc.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return None
for p in procs:
try:
total += p.memory_full_info().pss
except AttributeError:
return None
except psutil.NoSuchProcess:
pass
except psutil.AccessDenied:
return None
return total

def _total_rss_bytes(self) -> int:
total = 0
try:
Expand All @@ -218,9 +250,14 @@ def _total_rss_bytes(self) -> int:
def _run(self) -> None:
while not self._stop.is_set():
rss = self._total_rss_bytes()
pss = self._total_pss_bytes()
with self._lock:
if rss > self._peak:
self._peak = rss
if pss is not None and (
self._peak_pss is None or pss > self._peak_pss
):
self._peak_pss = pss
time.sleep(self._poll_interval_s)


Expand Down Expand Up @@ -411,6 +448,7 @@ def main() -> None:
total_s=total_s,
base_cache_bytes=base_cache_bytes,
peak_rss_bytes=peak_rss_bytes,
peak_pss_bytes=tracker.peak_pss_bytes(),
num_samples=num_samples,
)
)
Expand Down
Loading
Loading