Skip to content

GLM-5.3-Flash EXL3 on 2x DGX Spark with TensorFold

Python

Hermes endpoint guide and synthetic benchmark harness (from PR #52 by @kerpopule), without the bullerwins recipe, pin change and v1.5 numbers

Steve Darlow9f08dd5ab3af
diff --git a/docs/hermes-agent.md b/docs/hermes-agent.md
new file mode 100644
index 0000000..4042354
--- /dev/null
+++ b/docs/hermes-agent.md
@@ -0,0 +1,36 @@
+# Hermes Agent
+
+[Hermes Agent](https://hermes-agent.nousresearch.com/) (Nous Research) can use this server as a custom endpoint. The
+server is OpenAI-compatible, so no recipe change is needed. Hermes setup and the synthetic timing harness here were
+written by [Steve Darlow (@kerpopule)](https://github.com/kerpopule), who authored the work in PR #52.
+
+## Hermes custom endpoint
+
+Use `hermes model`, choose Custom endpoint, and point it at the TensorFold API. Equivalent model settings in the
+selected profile's `config.yaml`:
+
+```yaml
+model:
+ provider: custom
+ base_url: http://127.0.0.1:8888/v1
+ default: GLM-5.3-Flash-EXL3
+ context_length: 1048576
+```
+
+`default` is `SERVED_NAME` (`GLM-5.3-Flash-EXL3` unless changed). Verify `/v1/models` and the model field of actual
+replies rather than trusting a requested alias. Keep the endpoint loopback or private (`HOST=127.0.0.1`); an
+unauthenticated OpenAI-compatible API must not be exposed publicly. The context value is configured capacity, not a
+full-window stress qualification. Current Hermes guidance:
+https://hermes-agent.nousresearch.com/docs/integrations/providers/.
+
+## Reproduce the synthetic timings
+
+Use an idle endpoint and arrange a bounded exclusive test window outside the harness. It never stops or restarts
+engines. It rejects an unexpected served model; `--exclusive` also rejects telemetry showing overlapping inference.
+
+```bash
+python3 tools/hermes_benchmark.py --model GLM-5.3-Flash-EXL3 --exclusive > run.jsonl
+python3 -m unittest tests/test_hermes_benchmark.py
+```
+
+The output includes synthetic generated code and full health snapshots; inspect it before sharing.
diff --git a/tests/test_hermes_benchmark.py b/tests/test_hermes_benchmark.py
new file mode 100644
index 0000000..b4c2cd9
--- /dev/null
+++ b/tests/test_hermes_benchmark.py
@@ -0,0 +1,42 @@
+"""Offline tests. Fixtures are never reported as inference results."""
+import importlib.util
+import io
+import contextlib
+from pathlib import Path
+import unittest
+from unittest.mock import patch
+
+p=Path(__file__).resolve().parents[1]/'tools/hermes_benchmark.py'
+s=importlib.util.spec_from_file_location('benchmark',p)
+assert s is not None and s.loader is not None
+b=importlib.util.module_from_spec(s)
+s.loader.exec_module(b)
+
+class HarnessTests(unittest.TestCase):
+ def test_import_does_not_run_inference(self):
+ self.assertIsNone(b.MODEL)
+ self.assertEqual(b.BASE,'http://127.0.0.1:8888/v1')
+
+ def test_unrecognized_model_rejected_before_network(self):
+ with patch.object(b.opener,'open') as request:
+ with contextlib.redirect_stderr(io.StringIO()):
+ with self.assertRaises(SystemExit):
+ b.main(['--model','wrong-model'])
+ request.assert_not_called()
+
+ def test_exact_matched_prompt_set(self):
+ self.assertEqual(len(b.jobs),8)
+ self.assertEqual(len(set(n for n,_,_ in b.jobs)),8)
+ self.assertEqual(b.jobs[0][1],b.jobs[3][1])
+ self.assertEqual(b.jobs[1][1],b.jobs[2][1])
+ self.assertTrue(b.jobs[5][2])
+
+ def test_wrong_response_model_is_rejected(self):
+ rows=[b'data: {"model":"wrong","choices":[{"delta":{"content":"fixture"}}]}\n', b'data: [DONE]\n']
+ with patch.object(b,'jobs',[('fixture','fixture',False)]), patch.object(b,'get_health',return_value={'backend':'tensorfold','busy':False}), patch.object(b,'memory',return_value=99), patch.object(b.opener,'open') as request:
+ request.return_value.__enter__.return_value=iter(rows)
+ with self.assertRaises(AssertionError):
+ b.main(['--model','GLM-5.3-Flash-EXL3'])
+ setattr(b,'MODEL',None)
+
+if __name__=='__main__': unittest.main()
diff --git a/tools/hermes_benchmark.py b/tools/hermes_benchmark.py
new file mode 100644
index 0000000..a78707a
--- /dev/null
+++ b/tools/hermes_benchmark.py
@@ -0,0 +1,133 @@
+"""Synthetic GLM reproducibility benchmark for the existing TensorFold API.
+No restarts, config writes, private conversation reads, or model switching. Run only against an idle serving endpoint; arrange exclusivity outside this tool.
+"""
+import json
+import time
+import threading
+import urllib.request
+import statistics
+import os
+import argparse
+MODEL=None
+
+BASE = 'http://127.0.0.1:8888/v1'
+HEALTH = 'http://127.0.0.1:8888/health'
+opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
+
+def get_health():
+ with opener.open(HEALTH, timeout=10) as r:
+ return json.load(r)
+
+def memory():
+ for line in open('/proc/meminfo'):
+ if line.startswith('MemAvailable:'):
+ return int(line.split()[1]) / 1048576
+
+jobs = [
+ ('prose-1', 'Write a detailed practical guide to maintaining a bicycle, including cleaning, inspecting brakes, adjusting gears, and fixing a flat. Use complete explanatory paragraphs.', False),
+ ('code-1', 'Write a complete Python standard-library implementation of an LRU cache with TTL, thread safety, a fake clock, and unittest tests. Explain the invariants in comments.', False),
+ ('code-repeat', 'Write a complete Python standard-library implementation of an LRU cache with TTL, thread safety, a fake clock, and unittest tests. Explain the invariants in comments.', False),
+ ('prose-repeat', 'Write a detailed practical guide to maintaining a bicycle, including cleaning, inspecting brakes, adjusting gears, and fixing a flat. Use complete explanatory paragraphs.', False),
+ ('synthetic-context', '\n'.join('Record %d: warehouse has %d blue bolts and %d green nuts.' % (i, i % 97, i % 83) for i in range(1800)) + '\nWrite a Python parser and tests for these records. Do not reproduce the records.', False),
+ ('thinking-code', 'Design and implement a robust Python standard-library bounded work queue with cancellation, timeouts, and graceful shutdown. Analyze the race conditions before giving code.', True),
+]
+
+jobs = jobs + [(n+'-repeat2', p, t) for n,p,t in jobs[:2]]
+def main(argv=None):
+ global BASE, HEALTH, MODEL
+ parser=argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--model', required=True, choices=('GLM-5.3-Flash-EXL3','GLM-5.3-Flash-EXL3-Abliterated'))
+ parser.add_argument('--base-url', default=BASE)
+ parser.add_argument('--health-url', default=HEALTH)
+ parser.add_argument('--exclusive', action='store_true', help='Reject telemetry showing concurrent inference')
+ args=parser.parse_args(argv)
+ MODEL=args.model; BASE=args.base_url.rstrip('/'); HEALTH=args.health_url
+ if args.exclusive: os.environ['BENCH_EXCLUSIVE']='1'
+ results = []
+ initial = get_health()
+ assert initial['backend'] == 'tensorfold' and not initial['busy'], initial
+ for name, prompt, thinking in jobs:
+ before = get_health()
+ if before['busy']:
+ raise RuntimeError('Other work is active; refusing benchmark contention')
+ body = {'model': MODEL, 'messages': [{'role': 'user', 'content': prompt}],
+ 'temperature': 0, 'max_tokens': 4096, 'stream': True,
+ 'stream_options': {'include_usage': True},
+ 'reasoning_effort': 'medium' if thinking else 'none',
+ 'chat_template_kwargs': {'enable_thinking': thinking}}
+ samples = []
+ stop = threading.Event()
+ def monitor():
+ while not stop.wait(0.5):
+ try:
+ h = get_health()
+ samples.append({'t': time.monotonic(), 'tokens': h['completion_tokens_total'],
+ 'streams': h['streams'], 'requests': h['requests_running'],
+ 'mem_available_gib': memory()})
+ except Exception as exc:
+ samples.append({'error': str(exc)})
+ thread = threading.Thread(target=monitor, daemon=True)
+ thread.start()
+ start = time.monotonic()
+ first = None
+ chunks = 0
+ visible = []
+ reason_chars = 0
+ usage = None
+ models = set()
+ done = False
+ req = urllib.request.Request(BASE + '/chat/completions', data=json.dumps(body).encode(), headers={'Content-Type': 'application/json'})
+ try:
+ with opener.open(req, timeout=600) as response:
+ for raw in response:
+ if not raw.startswith(b'data: '):
+ continue
+ data = raw[6:].decode().strip()
+ if data == '[DONE]':
+ done = True
+ break
+ event = json.loads(data)
+ if event.get('model'):
+ models.add(event['model'])
+ if event.get('usage'):
+ usage = event['usage']
+ for choice in event.get('choices', []):
+ delta = choice.get('delta', {})
+ content = delta.get('content') or ''
+ reasoning = delta.get('reasoning_content') or ''
+ if content or reasoning:
+ if first is None:
+ first = time.monotonic()
+ chunks += 1
+ visible.append(content)
+ reason_chars += len(reasoning)
+ finally:
+ end = time.monotonic()
+ stop.set()
+ thread.join(timeout=12)
+ after = get_health()
+ assert done and first and ''.join(visible) + ('x' if reason_chars else ''), name
+ assert models == {MODEL}, models
+ delta_keys = ('prompt_tokens_total', 'completion_tokens_total', 'prefill_seconds_total', 'decode_seconds_total', 'cached_tokens_total', 'drafted_total', 'accepted_total')
+ deltas = {k: after[k] - before[k] for k in delta_keys}
+ tokens = usage['completion_tokens'] if usage else deltas['completion_tokens_total']
+ rates = [(b['tokens'] - a['tokens']) / (b['t'] - a['t']) for a, b in zip(samples, samples[1:]) if 't' in a and 't' in b]
+ result = {'name': name, 'thinking': thinking, 'models': sorted(models), 'usage': usage,
+ 'wall_seconds': end - start, 'first_generated_token_seconds': first - start,
+ 'client_decode_tok_s': max(tokens - 1, 0) / (end - first),
+ 'end_to_end_tok_s': tokens / (end - start), 'health_deltas': deltas,
+ 'engine_active_decode_tok_s': deltas['completion_tokens_total'] / deltas['decode_seconds_total'] if deltas['decode_seconds_total'] else None,
+ 'half_second_sample_peak_tok_s': max(rates) if rates else None,
+ 'sse_content_events': chunks, 'reasoning_chars': reason_chars,
+ 'visible_prefix': ''.join(visible)[:160], 'visible_output': ''.join(visible),
+ 'min_available_gib': min([s['mem_available_gib'] for s in samples if 'mem_available_gib' in s], default=memory()),
+ 'max_decoding_streams': max([s['streams']['decoding'] for s in samples if 'streams' in s], default=0),
+ 'sampling_errors': [s for s in samples if 'error' in s]}
+ results.append(result)
+ if os.environ.get('BENCH_EXCLUSIVE') == '1':
+ assert result['max_decoding_streams'] <= 1, 'Concurrent inference contaminated the sample'
+ assert deltas['completion_tokens_total'] == tokens, 'Unowned tokens contaminated the sample'
+ print(json.dumps({'run': result}), flush=True)
+ print(json.dumps({'summary': {'model': MODEL, 'runs': len(results), 'median_client_decode_tok_s': statistics.median(r['client_decode_tok_s'] for r in results), 'max_client_decode_tok_s': max(r['client_decode_tok_s'] for r in results), 'initial_health': initial, 'final_health': get_health(), 'results': results}}), flush=True)
+
+if __name__=='__main__': main()