Taylor commited on
Commit
90bf42d
·
1 Parent(s): 5b5a680

fix: handle WASM OOM for LM head + show error details

Browse files

LM head matVec is 49152 x 960 = 188MB, which can exceed WASM
linear memory. Fall back to JS for matrices >100MB.

Also: read error body from Aether 500 responses to show
actual error message instead of generic 'Internal Server Error'.

Files changed (2) hide show
  1. aether-server.mjs +19 -9
  2. app.py +7 -0
aether-server.mjs CHANGED
@@ -61,15 +61,25 @@ async function loadSIMD() {
61
 
62
  return {
63
  matVec(matrix, vector, rows, cols) {
64
- const saved = wasm.getHeapPtr();
65
- const mPtr = wasm.allocate(matrix.byteLength);
66
- const vPtr = wasm.allocate(vector.byteLength);
67
- const rPtr = wasm.allocate(rows * 4);
68
- copyTo(mPtr, matrix); copyTo(vPtr, vector);
69
- wasm.matVecSimdBatch4(mPtr, vPtr, rPtr, rows, cols);
70
- const result = copyFrom(rPtr, rows);
71
- wasm.resetHeap(saved);
72
- return result;
 
 
 
 
 
 
 
 
 
 
73
  },
74
  rmsNorm(x, weight, eps) {
75
  const saved = wasm.getHeapPtr();
 
61
 
62
  return {
63
  matVec(matrix, vector, rows, cols) {
64
+ // Fall back to JS for huge matrices (LM head: 49152 x 960 = 188MB)
65
+ // that exceed WASM linear memory
66
+ if (matrix.byteLength > 100_000_000) {
67
+ return matVecJS(matrix, vector, rows, cols);
68
+ }
69
+ try {
70
+ const saved = wasm.getHeapPtr();
71
+ const mPtr = wasm.allocate(matrix.byteLength);
72
+ const vPtr = wasm.allocate(vector.byteLength);
73
+ const rPtr = wasm.allocate(rows * 4);
74
+ copyTo(mPtr, matrix); copyTo(vPtr, vector);
75
+ wasm.matVecSimdBatch4(mPtr, vPtr, rPtr, rows, cols);
76
+ const result = copyFrom(rPtr, rows);
77
+ wasm.resetHeap(saved);
78
+ return result;
79
+ } catch (e) {
80
+ // WASM OOM -- fall back to JS
81
+ return matVecJS(matrix, vector, rows, cols);
82
+ }
83
  },
84
  rmsNorm(x, weight, eps) {
85
  const saved = wasm.getHeapPtr();
app.py CHANGED
@@ -96,6 +96,13 @@ def gen_aether(prompt):
96
  result["tokens"],
97
  result["avgTokenMs"],
98
  )
 
 
 
 
 
 
 
99
  except Exception as e:
100
  return f"[Aether error: {e}]", 0, 0, 0
101
 
 
96
  result["tokens"],
97
  result["avgTokenMs"],
98
  )
99
+ except urllib.error.HTTPError as e:
100
+ body = e.read().decode() if e.fp else str(e)
101
+ try:
102
+ detail = json.loads(body).get("error", body[:200])
103
+ except Exception:
104
+ detail = body[:200]
105
+ return f"[Aether error: {detail}]", 0, 0, 0
106
  except Exception as e:
107
  return f"[Aether error: {e}]", 0, 0, 0
108