blessingmwiti Codex commited on
Commit
cd451e7
·
1 Parent(s): f18f414

Reduce Modal verifier credit usage

Browse files

Co-authored-by: Codex <codex@openai.com>

README.md CHANGED
@@ -93,6 +93,14 @@ modal deploy modal_backend/verifier.py
93
  modal deploy modal_backend/sandbox.py
94
  ```
95
 
 
 
 
 
 
 
 
 
96
  Set these Space secrets after deploy:
97
 
98
  | Secret | Value |
 
93
  modal deploy modal_backend/sandbox.py
94
  ```
95
 
96
+ The verifier is intentionally lazy to save Modal credits. It cold-starts only after a user generates code and the app calls `/verify`. For a live recording or judging window, you can warm it once:
97
+
98
+ ```bash
99
+ modal run modal_backend/verifier.py::warm_once
100
+ ```
101
+
102
+ Avoid scheduled keep-warm jobs unless you are actively demoing; keeping the 14B verifier warm can burn credits quickly.
103
+
104
  Set these Space secrets after deploy:
105
 
106
  | Secret | Value |
modal_backend/sandbox.py CHANGED
@@ -4,7 +4,7 @@ import modal
4
  app = modal.App("split-brain-sandbox")
5
 
6
 
7
- @app.function(timeout=30)
8
  def execute_python(code: str) -> dict:
9
  """Run code in a Modal sandbox and return stdout/stderr."""
10
  sandbox = modal.Sandbox.create(
@@ -12,7 +12,7 @@ def execute_python(code: str) -> dict:
12
  "-c",
13
  code,
14
  image=modal.Image.debian_slim().pip_install("numpy"),
15
- timeout=10,
16
  cpu=0.5,
17
  )
18
  sandbox.wait()
@@ -23,7 +23,10 @@ def execute_python(code: str) -> dict:
23
  }
24
 
25
 
26
- @app.function(image=modal.Image.debian_slim().pip_install("fastapi", "pydantic"))
 
 
 
27
  @modal.asgi_app()
28
  def sandbox_endpoint():
29
  from fastapi import FastAPI
 
4
  app = modal.App("split-brain-sandbox")
5
 
6
 
7
+ @app.function(timeout=20)
8
  def execute_python(code: str) -> dict:
9
  """Run code in a Modal sandbox and return stdout/stderr."""
10
  sandbox = modal.Sandbox.create(
 
12
  "-c",
13
  code,
14
  image=modal.Image.debian_slim().pip_install("numpy"),
15
+ timeout=8,
16
  cpu=0.5,
17
  )
18
  sandbox.wait()
 
23
  }
24
 
25
 
26
+ @app.function(
27
+ image=modal.Image.debian_slim().pip_install("fastapi", "pydantic"),
28
+ scaledown_window=30,
29
+ )
30
  @modal.asgi_app()
31
  def sandbox_endpoint():
32
  from fastapi import FastAPI
modal_backend/verifier.py CHANGED
@@ -50,9 +50,9 @@ llama_image = (
50
  image=llama_image,
51
  gpu="A10G",
52
  volumes={MODEL_DIR: model_volume},
53
- scaledown_window=300,
54
  )
55
- @modal.concurrent(max_inputs=10)
56
  class Verifier:
57
  @modal.enter()
58
  def load_model(self):
@@ -83,7 +83,7 @@ Respond ONLY with valid JSON. No markdown, no explanation outside the JSON."""
83
  {"role": "system", "content": system},
84
  {"role": "user", "content": user},
85
  ],
86
- max_tokens=2048,
87
  temperature=0.1,
88
  )
89
  raw = response["choices"][0]["message"]["content"].strip()
@@ -104,6 +104,7 @@ api_image = modal.Image.debian_slim(python_version="3.11").pip_install(
104
 
105
  @app.function(
106
  image=api_image,
 
107
  )
108
  @modal.asgi_app()
109
  def verifier_endpoint():
@@ -135,6 +136,7 @@ def verifier_endpoint():
135
  return web_app
136
 
137
 
138
- @app.function(schedule=modal.Cron("*/5 * * * *"))
139
- def keep_warm():
 
140
  Verifier().verify.remote("test", "print('hello')", "python")
 
50
  image=llama_image,
51
  gpu="A10G",
52
  volumes={MODEL_DIR: model_volume},
53
+ scaledown_window=60,
54
  )
55
+ @modal.concurrent(max_inputs=2)
56
  class Verifier:
57
  @modal.enter()
58
  def load_model(self):
 
83
  {"role": "system", "content": system},
84
  {"role": "user", "content": user},
85
  ],
86
+ max_tokens=1024,
87
  temperature=0.1,
88
  )
89
  raw = response["choices"][0]["message"]["content"].strip()
 
104
 
105
  @app.function(
106
  image=api_image,
107
+ scaledown_window=30,
108
  )
109
  @modal.asgi_app()
110
  def verifier_endpoint():
 
136
  return web_app
137
 
138
 
139
+ @app.function()
140
+ def warm_once():
141
+ """Manually warm the verifier before a live demo if you want lower first-hit latency."""
142
  Verifier().verify.remote("test", "print('hello')", "python")