[GH-ISSUE #3188] [Benchmark] BENCH.bat / strata_bench.py crashes with NameError when it starts the server #1286

Closed
opened 2026-11-04 01:50:02 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @IVoyt on GitHub (Oct 19, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3188

Area

[Benchmark] (measurements and reports)

Desktop app, Terminal or source?

Source (START-HERE.bat, setup.sh or a build)

What happened

tools/strata_bench.py crashes with a NameError as soon as it has to start the server itself — which is the default path and the one BENCH.bat uses:

PS D:\Strata> .\.venv\Scripts\python.exe tools\strata_bench.py --config D:\Strata\strata-swift-iq3_s.json --out D:\Strata-data\ab\old --runs 3 --long
Traceback (most recent call last):
  File "D:\Strata\tools\strata_bench.py", line 1037, in <module>
    sys.exit(main())
  File "D:\Strata\tools\strata_bench.py", line 990, in main
    say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; the PC may be slow meanwhile) ...")
                                            ^^^^
NameError: name 'port' is not defined

The name port is never assigned in main(); only a.port and the local base exist. Three lines use the undefined name:

  • tools/strata_bench.py:987 — print(f"Port {port} is used by something that is not Strata: pass --port N.", ...)
  • tools/strata_bench.py:990 — say(f"Starting {cfg_path.name} on port {port} ...")
  • tools/strata_bench.py:991 — proc = start_server(cfg_path, port, a.gpu, log_path)

Line 990 is reached on every run that starts a server, so the tool fails immediately, before the model is loaded and before any measurement.

Smallest steps or command that reproduce it

python tools\strata_bench.py --config <a config with an installed model>

(or BENCH.bat, which calls the same tool with the same arguments). --url http://127.0.0.1:<port> works, because that path never reaches the broken lines.

Reproduction status

Reproduced locally.

Strata version

Strata 0.2.0-beta (build 0.1.45.3), git 3fa1b524 (v0.2.0-beta-7), source checkout.

Graphics card, memory and system

RTX 5090 32 GB - 96 GB RAM - Windows 11 (10.0.26300), i7-12700KF, driver 617.42, CUDA toolkit 13.1 (nvcc 13.1.115), Python 3.13.12.

Model, size and settings

Swift 1.5 Qwen3.8-Flash-Next IQ3_S, 524288 context, pictures off.

Expected behavior

The tool starts the server on the config's port (or --port), waits for the model, runs the suite and writes the results folder.

Actual behavior

NameError: name 'port' is not defined at tools/strata_bench.py:990, immediately.

Suggested fix

Bind the port once and use it in the three places:

port = a.port or int(cfg.get("port", 8080))
base = server_base(cfg.get("host"), port)

and use port at lines 987, 990 and 991.

Additional context

  • The same three lines are unchanged since at least v0.1.45, so this is not a regression of the 0.2.0 work; it is a long-standing break of the default benchmark path.
  • The tool's own tests never reach it: every main() test in tools/test_strata_bench.py calls the tool with --url (line 216: argv = ["--url", srv.base, "--out", out_dir, "--runs", "2", "--quiet", *extra]), so the "start the server" branch is never executed by the suite. A test that starts the server on a free port would have caught this.
  • The same branch also writes the engine log excerpt (engine-log-excerpt.txt); with --url that file is not produced, so the workaround loses the log excerpt as well.
  • Unrelated, found while running the suite: python tools\test_strata_bench.py fails on a PC whose account name is user, because the redaction placeholder is <user> and the test asserts the account name is absent from the redacted text (tools/test_strata_bench.py:186-187, len(user) >= 4). The test needs a name that is not a substring of the placeholder, or the placeholder needs to differ.
Originally created by @IVoyt on GitHub (Oct 19, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/3188 ## Area [Benchmark] (measurements and reports) ## Desktop app, Terminal or source? Source (START-HERE.bat, setup.sh or a build) ## What happened `tools/strata_bench.py` crashes with a `NameError` as soon as it has to **start** the server itself — which is the default path and the one `BENCH.bat` uses: ``` PS D:\Strata> .\.venv\Scripts\python.exe tools\strata_bench.py --config D:\Strata\strata-swift-iq3_s.json --out D:\Strata-data\ab\old --runs 3 --long Traceback (most recent call last): File "D:\Strata\tools\strata_bench.py", line 1037, in <module> sys.exit(main()) File "D:\Strata\tools\strata_bench.py", line 990, in main say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; the PC may be slow meanwhile) ...") ^^^^ NameError: name 'port' is not defined ``` The name `port` is never assigned in `main()`; only `a.port` and the local `base` exist. Three lines use the undefined name: - `tools/strata_bench.py:987` — `print(f"Port {port} is used by something that is not Strata: pass --port N.", ...)` - `tools/strata_bench.py:990` — `say(f"Starting {cfg_path.name} on port {port} ...")` - `tools/strata_bench.py:991` — `proc = start_server(cfg_path, port, a.gpu, log_path)` Line 990 is reached on every run that starts a server, so the tool fails immediately, before the model is loaded and before any measurement. ## Smallest steps or command that reproduce it ``` python tools\strata_bench.py --config <a config with an installed model> ``` (or `BENCH.bat`, which calls the same tool with the same arguments). `--url http://127.0.0.1:<port>` works, because that path never reaches the broken lines. ## Reproduction status Reproduced locally. ## Strata version Strata 0.2.0-beta (build 0.1.45.3), git `3fa1b524` (v0.2.0-beta-7), source checkout. ## Graphics card, memory and system RTX 5090 32 GB - 96 GB RAM - Windows 11 (10.0.26300), i7-12700KF, driver 617.42, CUDA toolkit 13.1 (nvcc 13.1.115), Python 3.13.12. ## Model, size and settings Swift 1.5 Qwen3.8-Flash-Next IQ3_S, 524288 context, pictures off. ## Expected behavior The tool starts the server on the config's port (or `--port`), waits for the model, runs the suite and writes the results folder. ## Actual behavior `NameError: name 'port' is not defined` at `tools/strata_bench.py:990`, immediately. ## Suggested fix Bind the port once and use it in the three places: ```python port = a.port or int(cfg.get("port", 8080)) base = server_base(cfg.get("host"), port) ``` and use `port` at lines 987, 990 and 991. ## Additional context - The same three lines are unchanged since at least v0.1.45, so this is not a regression of the 0.2.0 work; it is a long-standing break of the default benchmark path. - The tool's own tests never reach it: every `main()` test in `tools/test_strata_bench.py` calls the tool with `--url` (line 216: `argv = ["--url", srv.base, "--out", out_dir, "--runs", "2", "--quiet", *extra]`), so the "start the server" branch is never executed by the suite. A test that starts the server on a free port would have caught this. - The same branch also writes the engine log excerpt (`engine-log-excerpt.txt`); with `--url` that file is not produced, so the workaround loses the log excerpt as well. - Unrelated, found while running the suite: `python tools\test_strata_bench.py` fails on a PC whose account name is `user`, because the redaction placeholder is `<user>` and the test asserts the account name is absent from the redacted text (`tools/test_strata_bench.py:186-187`, `len(user) >= 4`). The test needs a name that is not a substring of the placeholder, or the placeholder needs to differ.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 19, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Fill in "Area".
  • Fill in "Desktop app, Terminal or source?".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6271965071 --> @github-actions[bot] commented on GitHub (Oct 19, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Fill in "Area". - [ ] Fill in "Desktop app, Terminal or source?". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@github-actions[bot] commented on GitHub (Oct 19, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6272059328 --> @github-actions[bot] commented on GitHub (Oct 19, 2026): Thanks, this follows the format now.
Author
Owner

@ZrDaniel07 commented on GitHub (Oct 19, 2026):

Confirmed on Windows 11 + RTX 5090 (CUDA, engine 0.1.45, repo v0.2.0-beta; the exact same lines are in today's main, fetched 2026-10-19).

Repro: setup finishes with the model installed and the server not started; answering y to "Run a quick benchmark now?" enters the start-its-own-server branch and crashes immediately:

File "...\tools\strata_bench.py", line 990, in main
    say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; the PC may be slow meanwhile) ...")
NameError: name 'port' is not defined

Root cause: the port is only computed inline into base (line 976: base = server_base(cfg.get("host"), a.port or int(cfg.get("port", 8080)))) and is never bound to a port variable; the server-start branch then references port three times (lines 987, 990, 991). Any run that needs the bench to start its own server hits this before measuring anything.

Fix applied locally (syntax-checked with py_compile, script loads fine):

     else:
         base = server_base(cfg.get("host"), a.port or int(cfg.get("port", 8080)))
+        port = a.port or int(cfg.get("port", 8080))

Workaround until fixed: keep the Strata server already running when BENCH.bat is launched — line 980 (is_strata(base, key)) detects it and benchmarks the running server, so the buggy branch never executes.

<!-- gh-comment-id:6274188230 --> @ZrDaniel07 commented on GitHub (Oct 19, 2026): **Confirmed on Windows 11 + RTX 5090 (CUDA, engine 0.1.45, repo v0.2.0-beta; the exact same lines are in today's `main`, fetched 2026-10-19).** **Repro:** setup finishes with the model installed and the server not started; answering `y` to "Run a quick benchmark now?" enters the start-its-own-server branch and crashes immediately: ``` File "...\tools\strata_bench.py", line 990, in main say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; the PC may be slow meanwhile) ...") NameError: name 'port' is not defined ``` **Root cause:** the port is only computed inline into `base` (line 976: `base = server_base(cfg.get("host"), a.port or int(cfg.get("port", 8080)))`) and is never bound to a `port` variable; the server-start branch then references `port` three times (lines 987, 990, 991). Any run that needs the bench to start its own server hits this before measuring anything. **Fix applied locally (syntax-checked with `py_compile`, script loads fine):** ```diff else: base = server_base(cfg.get("host"), a.port or int(cfg.get("port", 8080))) + port = a.port or int(cfg.get("port", 8080)) ``` **Workaround until fixed:** keep the Strata server already running when `BENCH.bat` is launched — line 980 (`is_strata(base, key)`) detects it and benchmarks the running server, so the buggy branch never executes.
Author
Owner

@JoShMiQueL commented on GitHub (Oct 19, 2026):

Reproduced on main e88ee39d (0.2.0-beta, 2026-10-19), Windows 11 build 26200, RTX 4060 Ti 16 GB, driver 616.92 — pointed at a port where nothing listens, so the command stops before starting anything:

python tools/strata_bench.py --config strata-coder-iq1_m.json --port 9 --runs 1 --quiet
Traceback (most recent call last):
  File "tools/strata_bench.py", line 1087, in <module>
    sys.exit(main())
  File "tools/strata_bench.py", line 1040, in main
    say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; the PC may be slow meanwhile) ...")
                                            ^^^^
NameError: name 'port' is not defined

Two details that may help whoever picks it up:

  • ruff check tools/strata_bench.py reports F821 Undefined name 'port' on all three lines (:1037, :1040, :1041), so a lint run would have caught it before the release.
  • The commit is 69fe4055 (#2330): it replaced port = a.port or int(cfg.get("port", 8080)) + base = f"http://127.0.0.1:{port}" with base = server_base(cfg.get("host"), a.port or int(cfg.get("port", 8080))) and left the three uses of port behind. The same lines are in the v0.2.0-beta tag, so anything running the tool from that tag is affected.

Why the test suites stay green on this revision: tools/test_strata_bench.py (17 tests on e88ee39d, 20 with the branch of #3250) only exercises the --url path against a fake server, never the branch that starts the server. So until this is fixed, a re-measure on 0.2.0-beta needs either this fix or --url against a server started by hand. Restore the dropped assignment and add one test that reaches the start-server branch with a stub start_server, and it should be covered.

I have not opened a pull request for it — happy to prepare the one-line fix plus that test if it is wanted.

<!-- gh-comment-id:6275908460 --> @JoShMiQueL commented on GitHub (Oct 19, 2026): **Reproduced on `main` `e88ee39d` (0.2.0-beta, 2026-10-19), Windows 11 build 26200, RTX 4060 Ti 16 GB, driver 616.92** — pointed at a port where nothing listens, so the command stops before starting anything: ``` python tools/strata_bench.py --config strata-coder-iq1_m.json --port 9 --runs 1 --quiet ``` ``` Traceback (most recent call last): File "tools/strata_bench.py", line 1087, in <module> sys.exit(main()) File "tools/strata_bench.py", line 1040, in main say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; the PC may be slow meanwhile) ...") ^^^^ NameError: name 'port' is not defined ``` Two details that may help whoever picks it up: - `ruff check tools/strata_bench.py` reports `F821 Undefined name 'port'` on all three lines (`:1037`, `:1040`, `:1041`), so a lint run would have caught it before the release. - The commit is `69fe4055` (#2330): it replaced `port = a.port or int(cfg.get("port", 8080))` + `base = f"http://127.0.0.1:{port}"` with `base = server_base(cfg.get("host"), a.port or int(cfg.get("port", 8080)))` and left the three uses of `port` behind. The same lines are in the `v0.2.0-beta` tag, so anything running the tool from that tag is affected. Why the test suites stay green on this revision: `tools/test_strata_bench.py` (17 tests on `e88ee39d`, 20 with the branch of #3250) only exercises the `--url` path against a fake server, never the branch that starts the server. So until this is fixed, a re-measure on 0.2.0-beta needs either this fix or `--url` against a server started by hand. Restore the dropped assignment and add one test that reaches the start-server branch with a stub `start_server`, and it should be covered. I have not opened a pull request for it — happy to prepare the one-line fix plus that test if it is wanted.
Author
Owner

@GoldenLeafBird commented on GitHub (Oct 20, 2026):

Hit this at v0.1.45 first and again at v0.2.1 (blob 3a9877f, still present on
main at 9ae93f7). Minimal local fix, three tokens in the server-start branch of
main(), port -> a.port:

-        print(f"Port {port} is used by something that is not Strata: pass --port N.", file=sys.stderr)
+        print(f"Port {a.port} is used by something that is not Strata: pass --port N.", file=sys.stderr)
-        say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; ...")
+        say(f"Starting {cfg_path.name} on port {a.port} (loading takes 1-3 minutes; ...")
-        proc = start_server(cfg_path, port, a.gpu, log_path)
+        proc = start_server(cfg_path, a.port, a.gpu, log_path)

(Lines 989/992/993 at v0.2.1. The say line is abbreviated above; the edit is
only the port token.)

Unrelated note from the same file: the module-level import shutil is unused
in the whole file at v0.2.1, so it can go with the same change.

Environment: Windows 10 build 19044, source checkout, RX 7900 XTX. Reproduced
2026-10-19 on 0.1.45 and confirmed present 2026-10-20 at v0.2.1.

<!-- gh-comment-id:6291640930 --> @GoldenLeafBird commented on GitHub (Oct 20, 2026): Hit this at v0.1.45 first and again at v0.2.1 (blob 3a9877f, still present on main at 9ae93f7). Minimal local fix, three tokens in the server-start branch of `main()`, `port` -> `a.port`: ```diff - print(f"Port {port} is used by something that is not Strata: pass --port N.", file=sys.stderr) + print(f"Port {a.port} is used by something that is not Strata: pass --port N.", file=sys.stderr) - say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; ...") + say(f"Starting {cfg_path.name} on port {a.port} (loading takes 1-3 minutes; ...") - proc = start_server(cfg_path, port, a.gpu, log_path) + proc = start_server(cfg_path, a.port, a.gpu, log_path) ``` (Lines 989/992/993 at v0.2.1. The `say` line is abbreviated above; the edit is only the `port` token.) Unrelated note from the same file: the module-level `import shutil` is unused in the whole file at v0.2.1, so it can go with the same change. Environment: Windows 10 build 19044, source checkout, RX 7900 XTX. Reproduced 2026-10-19 on 0.1.45 and confirmed present 2026-10-20 at v0.2.1.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#1286
No description provided.