From e2ed1492da221a16cd26795c905bb313abfafb53 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Sun, 16 Aug 2026 16:39:51 -0700 Subject: [PATCH 1/3] Enforce image height and width from 0-1024 pixels 0 is treated as model default, and anything over 1024 is an error. CLI, API, and WUI all enforce these and give useful errors. I went with 1024 as the upper limit since I have no evidence that any models are trained on larger inputs; if you want a bigger output use upscaling. --- README.md | 4 ++-- tests/test_api.py | 4 ++-- thenoise/api.py | 10 ++++++++++ thenoise/generate.py | 9 +++++++++ thenoise/ui/index.html | 2 ++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1c605c2..924ee3b 100644 --- a/README.md +++ b/README.md @@ -329,8 +329,8 @@ All fields except `prompt` are optional. Omitted fields use the loaded model's d |-------|------|---------|-------------| | `prompt` | `string` | *(required)* | Text prompt | | `negative_prompt` | `string` | `""` | Negative prompt | -| `width` | `int` | model default | Output width in pixels | -| `height` | `int` | model default | Output height in pixels | +| `width` | `int` | model default | Output width in pixels (0..1024) | +| `height` | `int` | model default | Output height in pixels (0..1024) | | `steps` | `int` | model default | Number of denoising steps | | `guidance_scale` | `float` | model default | CFG scale (≤ 1.0 disables CFG) | | `seed` | `int` | random | Random seed (`-1` for random) | diff --git a/tests/test_api.py b/tests/test_api.py index fff3ba0..22c63e3 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -56,12 +56,12 @@ def test_upscalers_available_without_model(): def test_text2image_passes_pixel_upscaler(tmp_path): runtime = _fake_runtime(tmp_path) app = create_app(runtime) - req = Text2ImageRequest(prompt="a fox", pixel_upscaler="RealESRGAN_x4") + req = Text2ImageRequest(prompt="a fox", width=512, height=512, pixel_upscaler="RealESRGAN_x4") res = _endpoint(app, "/text2image")(req) assert res.status_code == 200 assert runtime._pipeline.last_request.pixel_upscaler == "RealESRGAN_x4" def test_request_field_defaults_none(): - req = Text2ImageRequest(prompt="x") + req = Text2ImageRequest(prompt="x", width=512, height=512) assert req.pixel_upscaler is None diff --git a/thenoise/api.py b/thenoise/api.py index bf3b634..6864a7a 100644 --- a/thenoise/api.py +++ b/thenoise/api.py @@ -30,6 +30,16 @@ class Text2ImageRequest(BaseModel): negative_prompt: str = "" width: Optional[int] = None height: Optional[int] = None + + @property + def _max_dim(self) -> int: + return 1024 + + def model_post_init(self, __context) -> None: + max_dim = self._max_dim + for name, value in (("width", self.width), ("height", self.height)): + if value is not None and (value < 0 or value > max_dim): + raise ValueError(f"{name} must be between 0 and {max_dim} (got {value}).") steps: Optional[int] = None guidance_scale: Optional[float] = None seed: Optional[int] = None diff --git a/thenoise/generate.py b/thenoise/generate.py index 972cac6..e85146c 100644 --- a/thenoise/generate.py +++ b/thenoise/generate.py @@ -9,12 +9,21 @@ import logging import os import random +import sys logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) def run_generate(args) -> None: + _MAX_DIM = 1024 + if args.width is not None and (args.width < 0 or args.width > _MAX_DIM): + print(f"error: width must be between 0 and {_MAX_DIM} (got {args.width}).", file=sys.stderr) + sys.exit(1) + if args.height is not None and (args.height < 0 or args.height > _MAX_DIM): + print(f"error: height must be between 0 and {_MAX_DIM} (got {args.height}).", file=sys.stderr) + sys.exit(1) + from .models.config import GenerateRequest from .runtime import Settings, ModelPaths, Runtime settings = Settings(device=args.device) diff --git a/thenoise/ui/index.html b/thenoise/ui/index.html index c7d147e..e5678a2 100644 --- a/thenoise/ui/index.html +++ b/thenoise/ui/index.html @@ -242,11 +242,13 @@

TheNoise

+ Max 1024
+ Max 1024
From 07b78313ac44cc6b2c93684643c81a6214e49502 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Sun, 23 Aug 2026 13:45:34 -0700 Subject: [PATCH 2/3] address feedback WUI and CLI now reject dimensions larger than 4096. A 4096x1024 fox doesn't render correctly (it's a fox-like centipede) but it doesn't crash my GPU any more either. --- thenoise/api.py | 9 --------- thenoise/generate.py | 2 +- thenoise/ui/index.html | 16 ++++++++++++++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/thenoise/api.py b/thenoise/api.py index 6864a7a..5d47698 100644 --- a/thenoise/api.py +++ b/thenoise/api.py @@ -31,15 +31,6 @@ class Text2ImageRequest(BaseModel): width: Optional[int] = None height: Optional[int] = None - @property - def _max_dim(self) -> int: - return 1024 - - def model_post_init(self, __context) -> None: - max_dim = self._max_dim - for name, value in (("width", self.width), ("height", self.height)): - if value is not None and (value < 0 or value > max_dim): - raise ValueError(f"{name} must be between 0 and {max_dim} (got {value}).") steps: Optional[int] = None guidance_scale: Optional[float] = None seed: Optional[int] = None diff --git a/thenoise/generate.py b/thenoise/generate.py index e85146c..bf45050 100644 --- a/thenoise/generate.py +++ b/thenoise/generate.py @@ -16,7 +16,7 @@ def run_generate(args) -> None: - _MAX_DIM = 1024 + _MAX_DIM = 4096 if args.width is not None and (args.width < 0 or args.width > _MAX_DIM): print(f"error: width must be between 0 and {_MAX_DIM} (got {args.width}).", file=sys.stderr) sys.exit(1) diff --git a/thenoise/ui/index.html b/thenoise/ui/index.html index e5678a2..c3abb6c 100644 --- a/thenoise/ui/index.html +++ b/thenoise/ui/index.html @@ -242,13 +242,13 @@

TheNoise

- Max 1024 + Max 4096
- Max 1024 + Max 4096
@@ -746,6 +746,18 @@

TheNoise

const samplerVal = $('sampler').value; if (samplerVal) body.sampler = samplerVal; + const MAX_DIM = 4096; + for (const f of ['width', 'height']) { + const v = $(f).value === '' ? null : parseInt($(f).value, 10); + if (v !== null && (v < 0 || v > MAX_DIM)) { + btn.disabled = false; + clearInterval(timer); + overlay.classList.add('hidden'); + alert(`error: ${f} must be between 0 and ${MAX_DIM} (got ${v}).`); + return; + } + } + try { const res = await fetch('/text2image', { method: 'POST', From 133c7075ca9f01784ba8408e05a67303f30f05ad Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 24 Aug 2026 07:39:00 +0200 Subject: [PATCH 3/3] update limits in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 924ee3b..1d4bfd9 100644 --- a/README.md +++ b/README.md @@ -329,8 +329,8 @@ All fields except `prompt` are optional. Omitted fields use the loaded model's d |-------|------|---------|-------------| | `prompt` | `string` | *(required)* | Text prompt | | `negative_prompt` | `string` | `""` | Negative prompt | -| `width` | `int` | model default | Output width in pixels (0..1024) | -| `height` | `int` | model default | Output height in pixels (0..1024) | +| `width` | `int` | model default | Output width in pixels (0..4096) | +| `height` | `int` | model default | Output height in pixels (0..4096) | | `steps` | `int` | model default | Number of denoising steps | | `guidance_scale` | `float` | model default | CFG scale (≤ 1.0 disables CFG) | | `seed` | `int` | random | Random seed (`-1` for random) |