Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Slot-clamp lint: accept the allow marker on any line of a wrapped assignment (#17384)

Daniel Handb0367a328ab
diff --git a/scripts/lint_no_parallel_clamp.py b/scripts/lint_no_parallel_clamp.py
index a3a3e0e2f05..50353c0e691 100644
--- a/scripts/lint_no_parallel_clamp.py
+++ b/scripts/lint_no_parallel_clamp.py
@@ -25,7 +25,7 @@ Parameter defaults, class-body annotations, `self.<attr>` assignments and
`max(1, ...)` / `getattr(..., 1)` floors are structurally distinct and pass.
A genuine capability or resource limit is allowed with a trailing
-`# allow-slot-clamp: <reason>` comment on the assignment line.
+`# allow-slot-clamp: <reason>` comment on the assignment (any line it spans).
Exit codes: 0 = clean, 1 = findings, 2 = usage error.
Run from repo root: python3 scripts/lint_no_parallel_clamp.py
@@ -113,7 +113,10 @@ def _findings_for_tree(
what = "pinned to a single slot by an expression"
else:
continue
- if ALLOW_MARKER in lines[node.lineno - 1]:
+ # The formatter moves a trailing comment inside the parentheses when it wraps a long
+ # assignment, so the marker counts on any line the statement spans.
+ span = lines[node.lineno - 1 : (node.end_lineno or node.lineno)]
+ if any(ALLOW_MARKER in line for line in span):
continue
found.append((filename, node.lineno, what))
return found
@@ -151,6 +154,11 @@ _SELF_TEST_CASES: tuple[tuple[str, int], ...] = (
("def load():\n n_parallel: int = 1 # allow-slot-clamp: ok\n", 0),
("def load(x):\n n_parallel: int = x\n", 0),
("def load():\n n_parallel = 1 # allow-slot-clamp: no --kv-unified\n", 0),
+ (
+ "def load():\n n_parallel = (\n 1 # allow-slot-clamp: wrapped by the formatter\n )\n",
+ 0,
+ ),
+ ("def load():\n n_parallel = (\n 1\n )\n", 1),
("def load():\n n_parallel = _mtp_clamped_slots\n", 1),
("def load(n):\n n_parallel = min(n, 1)\n", 1),
("def load(n, mtp):\n n_parallel = 1 if mtp else n\n", 1),
diff --git a/tests/test_lint_no_parallel_clamp.py b/tests/test_lint_no_parallel_clamp.py
index 3e9337aa66f..bceea5a54b3 100644
--- a/tests/test_lint_no_parallel_clamp.py
+++ b/tests/test_lint_no_parallel_clamp.py
@@ -34,10 +34,16 @@ CLAMPS = (
"def load():\n n_parallel = _mtp_clamped_slots\n",
"async def load():\n n_parallel = 1\n",
"def load():\n if mtp:\n n_parallel = 1\n",
+ # Wrapped by the formatter and unmarked: still a clamp.
+ "def load():\n n_parallel = (\n 1\n )\n",
+ # A marker on the next statement does not excuse this one.
+ "def load():\n n_parallel = 1\n x = 2 # allow-slot-clamp: elsewhere\n",
)
ALLOWED = (
"def load():\n n_parallel = 1 # allow-slot-clamp: no --kv-unified\n",
+ # The formatter moves the trailing marker inside the parentheses when it wraps the line.
+ "def load():\n n_parallel = (\n 1 # allow-slot-clamp: --fit on keeps layers over slots\n )\n",
"def load():\n n_parallel: int = 1 # allow-slot-clamp: no --kv-unified\n",
"def load(fit):\n n_parallel = fit.slots\n",
"def load(n):\n n_parallel = min(n, 1) # allow-slot-clamp: no --kv-unified\n",