diff --git a/setup.py b/setup.py
index 40ec012d..2a9d1568 100644
--- a/setup.py
+++ b/setup.py
@@ -717,7 +717,7 @@ def main() -> int:
ap.add_argument("--experimental-speed-projection", metavar="on|off|GGUF",
help="EXPERIMENTAL, off by default: the control vector in data/experimental-speed-projection "
"(or another GGUF) as a projection on layers 4-44; see docs/DETAILS.md")
- ap.add_argument("--port", type=int, default=8080)
+ ap.add_argument("--port", type=int, help="the server's port (default: the one the install was set up with, 8080 for a new one)")
ap.add_argument("--host", help="where the server listens: 127.0.0.1 = this PC only (default), 0.0.0.0 = also other "
"devices on your network (issue #26; set --api-key too)")
ap.add_argument("--api-key", help="require this key from clients (recommended with --host 0.0.0.0)")
@@ -732,6 +732,7 @@ def main() -> int:
ap.add_argument("--check", action="store_true", help="only check this PC and exit")
ap.add_argument("--skip-build", action="store_true", help=argparse.SUPPRESS)
a = ap.parse_args()
+ port = a.port or 8080 # a new install's port (issue #32: --port for an existing one)
say("Strata - Qwen3.8-Flash-Next on a normal PC (NVIDIA GPU + system RAM + CPU)")
@@ -741,14 +742,14 @@ def main() -> int:
if not a.build:
update_installed_engine(a.prebuilt)
if len(have) == 1:
- return start(have[0], None)
+ return start(have[0], a.port)
say()
for i, c in enumerate(have, 1):
say(f" {i}) {json.loads(c.read_text(encoding='utf-8-sig')).get('model_name', c.stem)}")
say(f" {len(have) + 1}) install another model / change settings")
pick = int(ask("Which one?", [str(i) for i in range(1, len(have) + 2)], "1", a.yes))
if pick <= len(have):
- return start(have[pick - 1], None)
+ return start(have[pick - 1], a.port)
# ---- 1. the PC
step(1, "checking your PC")
@@ -986,7 +987,7 @@ def main() -> int:
"--cvec-mode", "project", "--cvec-dir", "per-layer"]
cfg = {"exe": str(eng / EXE), "args": args, "cwd": str(ROOT), "tokenizer": str(pack / "tokenizer"),
"model_name": f"{fam['name']}-{model.lower()}", "log": str(ROOT / f"strata-{tag.lower()}.log"),
- "lib_dirs": lib_dirs, "port": a.port}
+ "lib_dirs": lib_dirs, "port": port}
if a.host:
cfg["host"] = a.host
if a.api_key:
@@ -998,22 +999,22 @@ def main() -> int:
cfg["vision"]["threads"] = max(1, (os.cpu_count() or 8) // 2)
cfg_path = ROOT / f"strata-{tag.lower()}.json"
cfg_path.write_text(json.dumps(cfg, indent=1), encoding="utf-8")
- script = write_run_script(tag, cfg_path, a.port)
+ script = write_run_script(tag, cfg_path, port)
ok(f"start script: {script.name}")
say()
say("All set.")
- say(f" API (OpenAI): http://127.0.0.1:{a.port}/v1 (any API key; model name: anything)")
- say(f" API (Anthropic): http://127.0.0.1:{a.port}/v1/messages")
+ say(f" API (OpenAI): http://127.0.0.1:{port}/v1 (any API key; model name: anything)")
+ say(f" API (Anthropic): http://127.0.0.1:{port}/v1/messages")
if a.host and a.host not in ("127.0.0.1", "localhost"):
- say(f" Other devices: the server window prints this PC's address (http://:{a.port}/)"
+ say(f" Other devices: the server window prints this PC's address (http://:{port}/)"
+ ("" if a.api_key else " - no API key set: anyone on your network can use it"))
say(f" Next time: just run {'START-HERE.bat' if WIN else './setup.sh'} (or {script.name}) - it starts right away")
if vision != "none":
say(" Images: send them in the chat page, in chat.py (/image ) or over the API")
if a.no_start:
return 0
- return start(cfg_path, a.port)
+ return start(cfg_path, port)
if __name__ == "__main__":
diff --git a/setup.sh b/setup.sh
old mode 100644
new mode 100755
index 5ba074ce..c5b1249d
--- a/setup.sh
+++ b/setup.sh
@@ -2,10 +2,17 @@
# Strata for Linux: the first run installs everything and starts the model; later runs just start it.
# Needs only an NVIDIA driver. Python (with venv) is installed through apt/dnf if it is missing (asks for sudo).
cd "$(dirname "$0")" || exit 1
+# Python 3.10+ that can make a venv WITH pip: Debian/Ubuntu ship `venv` without `ensurepip` (that is the separate
+# python3-venv package), and a venv made without it has no pip
+ok_py() { "$1" -c 'import sys, venv, ensurepip; sys.exit(0 if sys.version_info >= (3, 10) else 1)' 2>/dev/null; }
+# a .venv from an earlier run that failed half-way has a python but no pip: start it again
+if [ -x .venv/bin/python ] && ! .venv/bin/python -m pip --version >/dev/null 2>&1; then
+ rm -rf .venv
+fi
if [ ! -x .venv/bin/python ]; then
PY=""
for c in python3 python; do
- if command -v $c >/dev/null 2>&1 && $c -c 'import sys, venv; sys.exit(0 if sys.version_info >= (3, 10) else 1)' 2>/dev/null; then
+ if command -v $c >/dev/null 2>&1 && ok_py $c; then
PY=$c; break
fi
done
@@ -19,12 +26,13 @@ if [ ! -x .venv/bin/python ]; then
sudo pacman -S --noconfirm python python-pip
fi
PY=python3
- if ! $PY -c 'import sys, venv; sys.exit(0 if sys.version_info >= (3, 10) else 1)' 2>/dev/null; then
- echo "Please install Python 3.10 or newer (with venv), then run ./setup.sh again."
+ if ! ok_py $PY; then
+ echo "Please install Python 3.10 or newer with venv (Ubuntu/Debian: sudo apt install python3-venv), then run"
+ echo "./setup.sh again."
exit 1
fi
fi
# a private environment inside this folder (system Python stays untouched; newer distros refuse global pip)
- $PY -m venv .venv || { echo "could not create .venv: sudo apt install python3-venv"; exit 1; }
+ $PY -m venv .venv || { rm -rf .venv; echo "could not create .venv: sudo apt install python3-venv"; exit 1; }
fi
exec .venv/bin/python setup.py "$@"
diff --git a/src/kernels/cpu/pool.cpp b/src/kernels/cpu/pool.cpp
index 87841231..c5f4075d 100644
--- a/src/kernels/cpu/pool.cpp
+++ b/src/kernels/cpu/pool.cpp
@@ -55,13 +55,38 @@ std::vector physical_cores(bool skip_first) {
}
}
#else
+ // The logical CPUs this process may run on, ONE PER PHYSICAL CORE (issue #40): SMT siblings share a core's
+ // load/store bandwidth, so a worker on each would put two workers on one core, as the Windows branch above
+ // explains. sysfs names each CPU's (package, core); the first allowed CPU of each pair is kept, so a taskset
+ // that leaves out the first sibling still gets its core. Without sysfs every allowed CPU counts, as before.
+ auto topo = [](int cpu, const char* what) -> long {
+ char path[96];
+ std::snprintf(path, sizeof path, "/sys/devices/system/cpu/cpu%d/topology/%s", cpu, what);
+ long v = -1;
+ if (std::FILE* f = std::fopen(path, "r")) {
+ if (std::fscanf(f, "%ld", &v) != 1) v = -1;
+ std::fclose(f);
+ }
+ return v;
+ };
+ std::vector allowed;
cpu_set_t set;
CPU_ZERO(&set);
if (sched_getaffinity(0, sizeof set, &set) == 0) {
for (int i = 0; i < CPU_SETSIZE; ++i)
- if (CPU_ISSET(i, &set)) cores.push_back(i);
+ if (CPU_ISSET(i, &set)) allowed.push_back(i);
} else {
- for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) cores.push_back((int) i);
+ for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) allowed.push_back((int) i);
+ }
+ std::vector> seen;
+ for (int cpu : allowed) {
+ const long pkg = topo(cpu, "physical_package_id"), core = topo(cpu, "core_id");
+ if (pkg >= 0 && core >= 0) {
+ const std::pair key{pkg, core};
+ if (std::find(seen.begin(), seen.end(), key) != seen.end()) continue; // an SMT sibling
+ seen.push_back(key);
+ }
+ cores.push_back(cpu);
}
#endif
if (skip_first && !cores.empty()) cores.erase(cores.begin());