shrishSVaidya commited on
Commit
d7a12a1
Β·
1 Parent(s): 16e286c

adding RAM utilization logs

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -18,6 +18,15 @@ from gguf_engine import (
18
  exclude_thinking_component,
19
  LLM_LORA_PATHS,
20
  )
 
 
 
 
 
 
 
 
 
21
 
22
 
23
  # ==========================================
@@ -30,7 +39,9 @@ def _stream_generate(prompt: str, max_tokens: int = 800):
30
  Generator that yields incremental text from the base model (no LoRA).
31
  Used exclusively for the orchestrator's final answer.
32
  """
 
33
  model = _load_text_model("default")
 
34
  formatted = _format_gemma_prompt(prompt)
35
  accumulated = ""
36
  for chunk in model(
@@ -42,6 +53,7 @@ def _stream_generate(prompt: str, max_tokens: int = 800):
42
  top_p = 1.0,
43
  stream = True,
44
  ):
 
45
  token = chunk["choices"][0]["text"]
46
  accumulated += token
47
  yield exclude_thinking_component(accumulated)
@@ -84,6 +96,7 @@ def process_patient_data(
84
  user_query, lab_values, behaviour_changes, wsi_image,
85
  progress=gr.Progress(track_tqdm=True)
86
  ):
 
87
  # ── Assemble clinical text ─────────────────────────────────────────────
88
  parts = []
89
  if lab_values.strip():
@@ -146,6 +159,7 @@ def process_patient_data(
146
  # Simpler: just run the full agent and grab intermediate results.
147
  progress(0.2, desc="Module 2 Β· Risk Stratification LoRA…")
148
  final_state = full_agent.invoke(initial_state)
 
149
 
150
  # ── Unpack results ─────────────────────────────────────────────────────
151
  ran_m2 = bool(final_state.get("module2_risk_score", "").strip())
 
18
  exclude_thinking_component,
19
  LLM_LORA_PATHS,
20
  )
21
+ import psutil
22
+ import os
23
+
24
+ def check_memory():
25
+ process = psutil.Process(os.getpid())
26
+ # RAM usage in GB
27
+ return process.memory_info().rss / 1024**3
28
+
29
+
30
 
31
 
32
  # ==========================================
 
39
  Generator that yields incremental text from the base model (no LoRA).
40
  Used exclusively for the orchestrator's final answer.
41
  """
42
+ print(f"[BEFORE MODEL LOAD] RAM Usage: {check_memory():.2f} GB")
43
  model = _load_text_model("default")
44
+ print(f"[AFTER MODEL LOAD] RAM Usage: {check_memory():.2f} GB")
45
  formatted = _format_gemma_prompt(prompt)
46
  accumulated = ""
47
  for chunk in model(
 
53
  top_p = 1.0,
54
  stream = True,
55
  ):
56
+ print(f"[STREAM] RAM Usage: {check_memory():.2f} GB")
57
  token = chunk["choices"][0]["text"]
58
  accumulated += token
59
  yield exclude_thinking_component(accumulated)
 
96
  user_query, lab_values, behaviour_changes, wsi_image,
97
  progress=gr.Progress(track_tqdm=True)
98
  ):
99
+ print(f"[START] RAM Usage: {check_memory():.2f} GB")
100
  # ── Assemble clinical text ─────────────────────────────────────────────
101
  parts = []
102
  if lab_values.strip():
 
159
  # Simpler: just run the full agent and grab intermediate results.
160
  progress(0.2, desc="Module 2 Β· Risk Stratification LoRA…")
161
  final_state = full_agent.invoke(initial_state)
162
+ print(f"[AFTER AGENT] RAM Usage: {check_memory():.2f} GB")
163
 
164
  # ── Unpack results ─────────────────────────────────────────────────────
165
  ran_m2 = bool(final_state.get("module2_risk_score", "").strip())