zmeeks commited on
Commit
6492713
·
verified ·
1 Parent(s): 77ee837

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -5,6 +5,7 @@ import torch
5
  import pandas as pd
6
  import inspect
7
  import os
 
8
 
9
  import torch, transformers
10
  print(f"PyTorch: {torch.__version__}")
@@ -84,6 +85,7 @@ class BasicAgent:
84
  self.agent = CodeAgent(
85
  tools=[self.search_tool],
86
  model=self.model,
 
87
  additional_authorized_imports=[
88
  'math', 'statistics', 're', # Basic computation
89
  'requests', 'json', # Web requests and JSON
@@ -117,7 +119,8 @@ class BasicAgent:
117
  print(f"🔧 Available tools: {[tool.__class__.__name__ for tool in self.agent.tools]}")
118
 
119
  # Run the agent
120
- result = self.agent.run(formatted_question)
 
121
 
122
  print(f"Raw result: {result}")
123
 
@@ -148,6 +151,14 @@ class BasicAgent:
148
  return self._fallback_implementation(question)
149
 
150
 
 
 
 
 
 
 
 
 
151
  def run_and_submit_all( profile: gr.OAuthProfile | None):
152
  """
153
  Fetches all questions, runs the BasicAgent on them, submits all answers,
@@ -203,6 +214,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
203
  answers_payload = []
204
  print(f"Running agent on {len(questions_data)} questions...")
205
  for item in questions_data:
 
206
  task_id = item.get("task_id")
207
  question_text = item.get("question")
208
  if not task_id or question_text is None:
 
5
  import pandas as pd
6
  import inspect
7
  import os
8
+ import gc
9
 
10
  import torch, transformers
11
  print(f"PyTorch: {torch.__version__}")
 
85
  self.agent = CodeAgent(
86
  tools=[self.search_tool],
87
  model=self.model,
88
+ max_steps=30,
89
  additional_authorized_imports=[
90
  'math', 'statistics', 're', # Basic computation
91
  'requests', 'json', # Web requests and JSON
 
119
  print(f"🔧 Available tools: {[tool.__class__.__name__ for tool in self.agent.tools]}")
120
 
121
  # Run the agent
122
+ with torch.no_grad():
123
+ result = self.agent.run(formatted_question)
124
 
125
  print(f"Raw result: {result}")
126
 
 
151
  return self._fallback_implementation(question)
152
 
153
 
154
+ def cleanup_memory():
155
+ """Centralized memory cleanup function"""
156
+ if torch.cuda.is_available():
157
+ torch.cuda.empty_cache()
158
+ torch.cuda.synchronize()
159
+ gc.collect()
160
+
161
+
162
  def run_and_submit_all( profile: gr.OAuthProfile | None):
163
  """
164
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
214
  answers_payload = []
215
  print(f"Running agent on {len(questions_data)} questions...")
216
  for item in questions_data:
217
+ cleanup_memory()
218
  task_id = item.get("task_id")
219
  question_text = item.get("question")
220
  if not task_id or question_text is None: