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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Installer downloads: report progress on whole 1 MiB chunks again (#15789)
Daniel Han64d0e777ff3f
diff --git a/studio/prebuilt_core.py b/studio/prebuilt_core.pyindex d83da798b20..20dbf638248 100644--- a/studio/prebuilt_core.py+++ b/studio/prebuilt_core.py@@ -751,7 +751,7 @@ def copy_response_body(*,total_bytes: int | None,progress: "DownloadProgress | None" = None,- chunk_size: int = 64 * 1024,+ chunk_size: int = 1024 * 1024,) -> int:"""Stream ``response`` into ``write`` and return the byte count. Raises StalledDownload when awindow passes with too few bytes, and TruncatedDownload when the body ends short of@@ -759,23 +759,27 @@ def copy_response_body(A real HTTPResponse is read with read1, which returns what one receive brings: read(n) waitsfor all n bytes, so a trickle would block it for hours and the window check would never run.- Anything else (file:// bodies, test doubles) keeps plain read."""- if isinstance(response, http.client.HTTPResponse):- read = response.read1- else:- read = response.read+ Anything else (file:// bodies, test doubles) keeps plain read. Each read1 stops at the next+ ``chunk_size`` boundary and progress is reported there, so the progress lines land where the+ whole-chunk reads put them while the stall window is still checked after every receive."""+ per_receive = isinstance(response, http.client.HTTPResponse)+ read = response.read1 if per_receive else response.readdownloaded = 0+ next_report = chunk_sizewindow_start = time.monotonic()window_bytes = 0while True:- chunk = read(chunk_size)+ chunk = read(next_report - downloaded if per_receive else chunk_size)if not chunk:breakwrite(chunk)downloaded += len(chunk)window_bytes += len(chunk)- if progress is not None:- progress.update(downloaded)+ if downloaded >= next_report or not per_receive:+ if progress is not None:+ progress.update(downloaded)+ while next_report <= downloaded:+ next_report += chunk_sizenow = time.monotonic()if now - window_start >= DOWNLOAD_STALL_WINDOW_SECONDS:if window_bytes < DOWNLOAD_STALL_MIN_BYTES and (diff --git a/tests/studio/install/test_download_truncation_and_stall.py b/tests/studio/install/test_download_truncation_and_stall.pyindex b5d783e2b06..3bd0a4767ef 100644--- a/tests/studio/install/test_download_truncation_and_stall.py+++ b/tests/studio/install/test_download_truncation_and_stall.py@@ -229,3 +229,47 @@ def test_download_file_reconnects_after_a_real_trickle(monkeypatch, tmp_path, whassert srv.requests == 2assert time.monotonic() - start < 5.0assert destination.read_bytes() == PAYLOAD+++def test_progress_on_a_real_response_lands_on_whole_chunks():+ """read1 returns receive-sized pieces; progress is still reported at each 1 MiB boundary, so+ the installers' percent lines match the whole-chunk reads they printed before."""+ import urllib.request++ class Recorder:+ def __init__(self):+ self.updates = []+ self.finished = None++ def update(self, n):+ self.updates.append(n)++ def finish(self, n):+ self.finished = n++ big = PAYLOAD * 4+ with _Server(short = 0) as srv:+ srv.httpd.RequestHandlerClass.do_GET = _serve_bytes(srv, big)+ with urllib.request.urlopen(srv.url, timeout = 10) as response:+ recorder = Recorder()+ sink = bytearray()+ n = CORE.copy_response_body(+ response, sink.extend, total_bytes = len(big), progress = recorder+ )+ assert n == len(big) and bytes(sink) == big+ assert recorder.updates == [(i + 1) << 20 for i in range(4)]+ assert recorder.finished == len(big)+++def _serve_bytes(srv, body):+ def do_GET(handler): # noqa: N802+ srv.requests += 1+ handler.send_response(200)+ handler.send_header("Content-Length", str(len(body)))+ handler.end_headers()+ for i in range(0, len(body), 48 * 1024):+ handler.wfile.write(body[i : i + 48 * 1024])+ handler.wfile.flush()+ handler.close_connection = True++ return do_GET