From 81e5511d283f5d8b7dfab30d13a814f3747a7b13 Mon Sep 17 00:00:00 2001 From: Jeongkyu Shin Date: Sun, 15 Nov 2026 18:06:22 +0900 Subject: [PATCH] chore(python): raise the client's Python floor to 3.11 CI stopped testing 3.9 and 3.10 when #3013 moved the matrix to 3.11, 3.13 and 3.14 on ubuntu-latest, so the declared `requires-python = ">=3.9"` floor was untested. The floor now matches the oldest tested interpreter: `requires-python`, ruff `target-version` and mypy `python_version` move to 3.11, the classifiers list 3.11, 3.13 and 3.14, and the README, client docs and CHANGELOG say 3.11. Ruff's py311 target flagged one `asyncio.TimeoutError` alias in a test, replaced with the builtin `TimeoutError` (the same class on 3.11). The UP006/UP007/UP035/UP045 ignores stay, so existing annotations are not rewritten. Ruff lint and format, mypy on `python/src`, and the unit tests pass on 3.11 and 3.14 (140 passed). Refs #3012, #3013 --- .github/workflows/python.yml | 3 +-- CHANGELOG.md | 1 + docs/python-client.md | 2 +- python/README.md | 2 +- python/pyproject.toml | 16 ++++++++-------- python/tests/test_async_shutdown.py | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index eaf04d892..1c1b9c823 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -55,8 +55,7 @@ jobs: fail-fast: false matrix: # 3.14 is the default python3 on Ubuntu 26.04 (ubuntu-latest). - # actions/setup-python has no CPython 3.9 build for 26.04, so the - # requires-python floor (>=3.9) is not exercised here. + # 3.11 is the requires-python floor (>=3.11). python-version: ['3.11', '3.13', '3.14'] steps: - uses: actions/checkout@v7 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a9812d09..ee32418a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Changed +- **The Python client now requires Python 3.11 or newer** (#3013). `requires-python` moves from `>=3.9` to `>=3.11`, matching the oldest interpreter CI tests on `ubuntu-latest` (3.11, 3.13, 3.14); 3.9 is past end of life and 3.10 was never tested after #3013. Installs on 3.9 or 3.10 are now refused by pip instead of running untested. - **Held the single-sequence XLA decode step's KV cache in module globals so a step updates it in place** (#3043). The graph returned the two cache tensors as results, so IREE lowered every step as two 16 MiB `stream.cmd.copy` ops, 32 MiB of device traffic that the 4-bit 1B decode does not otherwise need. The decode module now declares `util.global private mutable @kcache` and `@vcache`, the step loads them, writes its own row and stores them back, so the update is a read-write binding into one persistent buffer with no copy and no change to the ops or the results; a private global is not host-visible, so a new `decode_step.kv_import` entry seeds it from the prefill result once per request, and every graph that does not export it (Gemma3n's fixed-schedule CUDA decode, an older compiled cache) keeps the previous full-cache ABI. The decode compile also turns on `--iree-dispatch-creation-enable-aggressive-fusion`, which cuts the decode flow from 309 to 277 dispatches by fusing two elementwise pairs per layer; prefill compiles keep the default. On `gfx1151` with llama-3.2-1b-instruct-4bit, native quant, context capacity 512 and `n=128`, one interleaved six-round A/B of the old and new binaries measures a median 196.06 tok/s against 179.78 for the old path (5.10 against 5.56 ms per step), ahead in all six paired rounds, with greedy output identical to the old binary on the same prompt. The same A/B on a GB10 host over CUDA, where native quant is HIP-only so both arms run the f16 path, measures a median 24.47 tok/s against 22.59 (5.22 against 5.66 ms per step), also ahead in all six paired rounds with identical greedy output, so the in-place update is not a HIP-only lowering effect. Those f16 figures are comparable only with the other CUDA arm, not with the native 4-bit figures above. - **Reused the single-sequence XLA decode step's scalar inputs and token readback** (#3028). Each step used to allocate three input buffer views and one host staging buffer for the 4-byte token readback, and on HIP each host-visible transfer is a pinned `hipHostMalloc`/`hipHostFree` pair; a microbenchmark on `gfx1151` puts the free alone at 122 us, which showed up as GPU-idle gaps at every step boundary. The three inputs and the readback slot are now allocated once per context as host-local, device-visible page-locked memory, mapped for the context's lifetime and written in place, and the readback is a device-to-device copy into the persistent slot. A device whose allocator cannot serve that heap logs one status line and keeps the per-step path, and `test-support` counters assert both the reuse and the fallback. On `gfx1151` with llama-3.2-1b-instruct-4bit, native quant, context capacity 512 and `n=256`, two interleaved four-round A/Bs of the old and new binaries measure a combined median 150.1 tok/s against 140.7 for the old path (6.66 against 7.11 ms per step), with the new path ahead in 7 of 8 paired rounds and byte-identical greedy output. - **Split XLA load timing and excluded engine load from `xla_batch_bench` throughput** (#2961). `MLXCEL_XLA_LOAD_TIMING` now reports `language-module-load` (instance, device, session and vmfb creation) apart from `language-weight-upload`, and `language-weight-upload-parts` appends the tensor count, uploaded bytes, host dequantize time, f16 pack time and device copy time, so an f16 ragged load can be attributed instead of guessed; a capacity bucket prints the parts line with zero counters because it shares the base context's weights. `xla_batch_bench` loads the engine outside its timed window and prints the two load times separately, so its `tok/s` and `BENCH` lines report decode throughput instead of decode plus a one-time weight upload. diff --git a/docs/python-client.md b/docs/python-client.md index ca4947742..c9142fa00 100644 --- a/docs/python-client.md +++ b/docs/python-client.md @@ -11,7 +11,7 @@ pip install ./python # from a repo checkout pip install "./python[dev]" # adds pytest, ruff, mypy ``` -Requires Python 3.9 or newer. Runtime dependencies are `openai>=1.40` and `httpx>=0.27`. Managed mode additionally needs the `mlxcel` binary; the client finds it via the `binary=` argument, the `MLXCEL_BIN` environment variable, or `mlxcel` on `PATH`, in that order. See [Installation](installation.md) for building the binary. +Requires Python 3.11 or newer. Runtime dependencies are `openai>=1.40` and `httpx>=0.27`. Managed mode additionally needs the `mlxcel` binary; the client finds it via the `binary=` argument, the `MLXCEL_BIN` environment variable, or `mlxcel` on `PATH`, in that order. See [Installation](installation.md) for building the binary. ## Managed mode diff --git a/python/README.md b/python/README.md index 7168e21a3..df11e7bf1 100644 --- a/python/README.md +++ b/python/README.md @@ -11,7 +11,7 @@ pip install ./python # from a repo checkout pip install "./python[dev]" # with pytest, ruff, mypy for development ``` -Requires Python 3.9+. The client itself is pure Python (`openai>=1.40`, `httpx>=0.27`). Managed mode additionally needs the `mlxcel` binary on `PATH`, or pass `binary=` / set `MLXCEL_BIN`. +Requires Python 3.11+. The client itself is pure Python (`openai>=1.40`, `httpx>=0.27`). Managed mode additionally needs the `mlxcel` binary on `PATH`, or pass `binary=` / set `MLXCEL_BIN`. ## Usage diff --git a/python/pyproject.toml b/python/pyproject.toml index 61e98ffcc..e21b464fe 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -7,7 +7,7 @@ name = "mlxcel" version = "0.1.0" description = "Python client for the mlxcel OpenAI-compatible inference server" readme = "README.md" -requires-python = ">=3.9" +requires-python = ">=3.11" license = "Apache-2.0" authors = [ { name = "Lablup Inc." }, @@ -19,9 +19,9 @@ classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "Topic :: Scientific/Engineering :: Artificial Intelligence", "Typing :: Typed", ] @@ -53,24 +53,24 @@ testpaths = ["tests"] [tool.ruff] line-length = 100 -target-version = "py39" +target-version = "py311" src = ["src", "tests", "examples"] [tool.ruff.lint] select = ["E", "F", "I", "UP", "B", "W"] ignore = [ - "UP006", # keep typing.List etc. usable on 3.9 where needed - "UP007", # keep Optional[...] / Union[...] for 3.9 runtime compatibility - "UP035", # allow typing imports under requires-python 3.9 + "UP006", # keep typing.List etc. (existing style, not rewritten) + "UP007", # keep Optional[...] / Union[...] (existing style) + "UP035", # allow typing imports (existing style) "UP037", # keep quoted self-referential annotations - "UP045", # keep Optional[...] over X | None for 3.9 clarity + "UP045", # keep Optional[...] over X | None (existing style) ] [tool.ruff.lint.per-file-ignores] "tests/fake_server.py" = ["B008"] [tool.mypy] -python_version = "3.9" +python_version = "3.11" strict = true warn_unused_configs = true disallow_untyped_defs = true diff --git a/python/tests/test_async_shutdown.py b/python/tests/test_async_shutdown.py index 532ee61ee..3d6ef4eb6 100644 --- a/python/tests/test_async_shutdown.py +++ b/python/tests/test_async_shutdown.py @@ -148,7 +148,7 @@ async def close(): # an assertion failure in a deliberately broken implementation. try: await asyncio.wait_for(asyncio.shield(task), 4.0) - except (asyncio.CancelledError, RuntimeError, asyncio.TimeoutError): + except (TimeoutError, asyncio.CancelledError, RuntimeError): pass elif not task.cancelled(): task.exception()