Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

fix(server): pause GLiClass graph recording after an out-of-memory first replay (#434)

svonava1f5426d72d95
diff --git a/packages/sie_server/README.md b/packages/sie_server/README.md
index 39f10e9c5..0ae38a9fb 100644
--- a/packages/sie_server/README.md
+++ b/packages/sie_server/README.md
@@ -249,8 +249,9 @@ seconds, so a model records at most 16 graphs in quick succession, one after
another, then about one every 2 seconds. If recording a graph runs out of
memory, the request still gets its eager answer; the model drops its graphs and
records nothing for a minute. If the new graph's first replay runs out of
-memory, the model drops its graphs and the request fails with that error, as an
-eager forward that runs out of memory does.
+memory, the model also drops its graphs and records nothing for a minute, but
+the request fails with that error, as an eager forward that runs out of memory
+does.
Both limits are approximate. The free-memory check reads the device once,
before recording, so a model loading at the same moment can still meet one
diff --git a/packages/sie_server/src/sie_server/adapters/gliclass/cuda_graphs.py b/packages/sie_server/src/sie_server/adapters/gliclass/cuda_graphs.py
index 3ff970d03..8eb40af59 100644
--- a/packages/sie_server/src/sie_server/adapters/gliclass/cuda_graphs.py
+++ b/packages/sie_server/src/sie_server/adapters/gliclass/cuda_graphs.py
@@ -85,9 +85,10 @@ states are scored before the next replay. Only the recording thread's forward
is diverted while a graph records; the diversion is per thread, so an eager
forward of the same model on another thread runs unchanged. Anything
unsupported, larger than the token bound, or whose shape failed to record runs
-eagerly. A shape whose recording or first replay fails for any reason but
-memory is not recorded again, and after three such shapes the runner turns
-graphs off for the process. The scoring head is not part of that count: it
+eagerly. A recording or first replay that runs out of memory drops every
+graph and pauses recording for a minute. A shape whose recording or first
+replay fails for any reason but memory is not recorded again, and after three
+such shapes the runner turns graphs off for the process. The scoring head is not part of that count: it
reads the forward's own inputs, so its errors fail that forward alone, as they
would eagerly. The runner
counts every forward it is offered (``CudaGraphStats``) and logs the counts
@@ -441,14 +442,17 @@ class CudaGraphRunner:
return None, "recording_failed"
# The graph answers the forward that recorded it, replayed before
# the budget check below can drop it. Its first replay is part of
- # recording it: a failure other than memory runs the forward
- # eagerly and the graph is not kept.
+ # recording it, and the graph is not kept if it fails. Running out
+ # of memory drops the graphs and pauses recording, as it does
+ # while recording, and the error reaches the forward's
+ # out-of-memory recovery; any other failure runs the forward
+ # eagerly.
try:
hidden = self._replay_graph(key, entry, inputs)
except Exception as exc:
+ self._recording_failed(key, exc)
if is_oom_error(exc):
raise
- self._recording_failed(key, exc)
return None, "recording_failed"
self._keep(key, entry, input_ids.device)
self.stats.recorded += 1
diff --git a/packages/sie_server/tests/adapters/test_gliclass_cuda_graphs.py b/packages/sie_server/tests/adapters/test_gliclass_cuda_graphs.py
index 3092251dd..38827f42f 100644
--- a/packages/sie_server/tests/adapters/test_gliclass_cuda_graphs.py
+++ b/packages/sie_server/tests/adapters/test_gliclass_cuda_graphs.py
@@ -552,6 +552,27 @@ class TestRecordingPolicy:
assert runner.stats.recording_failures == 0
assert not cuda_graphs_module._RECORDING_LOCK.locked()
+ def test_a_first_replay_that_runs_out_of_memory_drops_graphs_and_pauses_recording(self) -> None:
+ runner = _Runner()
+ runner.run(_inputs(1, 100), 4, "bucketed")
+ runner.replay_error = torch.cuda.OutOfMemoryError("CUDA out of memory")
+
+ with pytest.raises(torch.cuda.OutOfMemoryError):
+ runner.run(_inputs(1, 200), 4, "bucketed")
+
+ runner.replay_error = None
+ assert runner.graph_count == 0
+ assert not runner.disabled
+ assert runner.stats.drops == 1
+ assert runner.stats.recording_failures == 0 # memory is not the shape's fault
+ # Recording pauses for a minute, as after a recording that runs out of memory.
+ runner.now += 59.0
+ assert runner.run(_inputs(1, 300), 4, "bucketed") is None
+ assert runner.stats.eager["recording_paused"] == 1
+ runner.now += 2.0
+ assert runner.run(_inputs(1, 300), 4, "bucketed") is not None
+ assert runner.recorded[-1] == (1, 320)
+
def test_running_out_of_memory_while_recording_pauses_recording(self) -> None:
runner = _Runner()
runner.run(_inputs(1, 100), 4, "bucketed")