Skip to content

armgit / PS5LM

Public Imported from GitHub
0

llama.cpp on a jailbroken PS5: run any GGUF model natively on the console, starting with Qwen 3.8

v0.8.0: downloads that survive lost connections, Downloads page, busy screen

Abhiramfa0653dff707
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e2b6064..b0e8cb8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,60 @@ v0.1.x are the upstream payload releases by cobanov.
## [Unreleased]
+## [0.8.0] - 2026-10-13
+
+### Added
+- Downloads page (the fifth on L1/R1): a queue kept in
+ `/data/PS5LM/downloads.json`, each entry with its speed, time left and
+ state. Cross pauses or resumes (or tries a failed one again), Square twice
+ cancels and deletes the partial file, or clears a finished one.
+- Downloads survive a dropped connection, a pause and the app restarting: the
+ file is fetched in 32 MiB pieces on two connections, the part done from its
+ start is saved with the queue, and a lost connection is retried on its own
+ (4, 8, 16, 32, then 60 s apart, up to 20 times in a row). The SHA-256 is
+ checked once the file is whole.
+- Get models: Square checks whether the file under the cursor fits, and the
+ row says CHECKING while its header is read.
+- A busy screen (a spinner and what is happening) while a model is switched or
+ unloaded, before the restart for "unload and download", and while the
+ models are planned again after a context or cache change.
+- README rewritten around the app: features, the payloads it needs, controls.
+ The payload's README moved to `docs/PAYLOAD.md`.
+
+### Fixed
+- A download that lost its connection failed and threw away what it had
+ (2.0 of 10.4 GB, `sceHttp2ReadData 0x804101a3`); now it carries on.
+- A connection that went quiet could hang a download: requests now time out
+ after 30 s without data and are asked again.
+- Settings froze the app for seconds on every change, each one reading every
+ model's header again. Only the context and cache settings re-plan now, in
+ the background behind the busy screen; the others apply at once.
+
+### Measured (download speed on the console)
+- The PC on the same network: 19.6 MB/s from Hugging Face on one connection.
+- libSceHttp2 (HTTP/2), one connection: 2.8 to 5.9 MB/s, varying more from run
+ to run than with any setting. Reads of 256 KiB gave 0.65 MB/s (each read
+ waits about half a second), 4 MiB and larger 3 to 6 MB/s. Four requests on
+ one template share one connection (3.5 to 6 MB/s); on four templates, made
+ one at a time, 2.8 MB/s; on two, 4.2 MB/s. Made in four threads at once,
+ the templates crashed the app.
+- libSceHttp2 takes at most 4 requests (512 KiB pool); 8 or 16 are refused
+ (`0x817b121c`).
+- libSceHttp (HTTP/1.1): 0.44 MB/s per connection whatever the read or receive
+ block size, adding up with more connections (4: 1.6, 8: 2.5 MB/s, one of
+ the eight refused).
+- In the app, two pieces at once on their own templates: 7.0 to 9.8 MB/s for
+ a 1.9 GiB file (v0.7: 3.8 MB/s), still well under the PC's speed. Going
+ further needs sockets and TLS of our own, for a later release.
+
+### Checked on the console
+- A 1.9 GiB download: paused (the partial file stopped growing), resumed from
+ the saved 128 MiB, closed and relaunched mid-download (carried on from
+ 905 MiB), finished with its SHA-256 matching.
+- Get models during a download: search, listing and fit checks work.
+- The busy screen on a context change; the library re-planned behind it.
+- Payloads stayed up throughout.
+
## [0.7.0] - 2026-10-10
### Added
diff --git a/README.md b/README.md
index c6cde64..0e40c09 100644
--- a/README.md
+++ b/README.md
@@ -2,17 +2,17 @@
# PS5LM
-**llama.cpp on a jailbroken PlayStation 5, on its GPU.** Run GGUF language models on the console itself, from a native app with a dashboard on the TV.
+**llama.cpp on a jailbroken PlayStation 5, on its GPU.** A native app that runs GGUF language models on the console itself, with a dashboard on the TV, a model store, and a chat and OpenAI-compatible API for every device on your network.
-> **This is a fork.** PS5LM was created by **[Mert Cobanov](https://github.com/cobanov)** ([cobanov/PS5LM](https://github.com/cobanov/PS5LM), [ps5lm.cobanov.dev](https://ps5lm.cobanov.dev)): the llama.cpp port, the payload, its model library and the research all come from there. This fork, by [Abhiram](https://github.com/abhi245y), adds the **native GPU app** (v0.2.0 and later), offered back upstream in [cobanov/PS5LM#12](https://github.com/cobanov/PS5LM/pull/12).
+> **This is a fork.** PS5LM was created by **[Mert Cobanov](https://github.com/cobanov)** ([cobanov/PS5LM](https://github.com/cobanov/PS5LM), [ps5lm.cobanov.dev](https://ps5lm.cobanov.dev)): the llama.cpp port, the payload, its model library and the research all come from there. This fork, by [Abhiram](https://github.com/abhi245y), adds the **native GPU app** (v0.2.0 and later), offered back upstream in [cobanov/PS5LM#12](https://github.com/cobanov/PS5LM/pull/12). The original payload's README is kept in [docs/PAYLOAD.md](docs/PAYLOAD.md).
<p align="center">
<img src="docs/media/app/dashboard-generating.jpg" width="820" alt="The PS5LM dashboard on the TV while Gemma 4 generates">
</p>
-## The native app
+## What it does
-A payload gets about 6 GiB of memory and no GPU; a native app (a title) gets the console's 12 GiB of direct memory and the GPU. The app runs llama-server with ggml's Vulkan backend on Mihawk-99's RADV port, with one 11.44 GiB device heap, and serves the chat at `http://<console IP>:8081` (llama.cpp's web UI and the OpenAI API). Coding tools such as opencode, codex and Claude Code can use it as their model: see [docs/CLI.md](docs/CLI.md).
+A payload gets about 6 GiB of memory and no GPU. A native app (a title) gets the console's 12 GiB of direct memory and the GPU, so PS5LM runs as one: llama-server with ggml's Vulkan backend on Mihawk-99's RADV port, in one 11.44 GiB device heap.
| Model (on the PS5 GPU) | Context | Generation |
|---|---|---|
@@ -34,154 +34,139 @@ For comparison, the 27B on the CPU as a payload, streamed from disk, made about
</tr>
</table>
-- **Dashboard:** generation speed, GPU and CPU use (one USAGE card, Cross for the full view), SoC power with energy per token (POWER card, Cross for min/avg/max and every temperature sensor), the CPU clock, the memory pool and how the model, KV cache and the rest split it, context in use, storage, temperatures and fan, the loaded model (Cross for every argument it runs with), and load progress.
-- **Pages on L1/R1:** Settings (load a model at launch, which one, the longest context, KV cache type, sounds; kept in `settings.json`) and Logs (`app.log` and `llama.log`, with an errors-only filter).
-- **Get models:** search Hugging Face from the TV, see which files fit before downloading, and download to internal storage or USB (SHA-256 checked).
-- **Chat tools and images:** the browser chat's model can read, write and search files in `/data/PS5LM/scratch` (it cannot reach outside it), and vision models such as Gemma 4 take pictures when their `mmproj` file sits beside them.
-- **Sensors:** a title may not read the temperature and fan sensors, so the app carries [ps5-exporter](https://github.com/Marice/ps5-exporter) (Marice, GPL-3.0) and hands it to elfldr when it is not running. Without elfldr the THERMALS tile stays empty.
-- **Model library:** every `.gguf` in `/data/PS5LM/models` and in `PS5LM/models` on a USB drive, in two sections. Cross loads or unloads. A model on USB loads straight from the drive.
-- **Planner:** picks the longest context and the best KV cache type that fit the memory free, for each model.
-- **Presets:** sampling settings for Qwen 3.5/3.6/3.8, Gemma 4, gpt-oss, Granite, Nemotron, Mistral and Llama.
-
-### Install the app
+## Features
-You need a jailbroken PS5 on firmware 7.00 to 13.60 with [ShadowMountPlus](https://github.com/drakmor/ShadowMountPlus) (it registers titles from `/data/homebrew`) and an FTP server such as [ftpsrv](https://github.com/ps5-payload-dev/ftpsrv).
+**On the TV** (five pages, L1/R1 to move between them)
-1. Download `ps5lm-app-vX.Y.Z.zip` from this fork's [releases](https://github.com/abhi245y/PS5LM/releases) and check it against its `.sha256`.
-2. Unzip it and copy the `PPSA99581` folder to `/data/homebrew/PPSA99581` over FTP. ShadowMountPlus adds **PS5LM** to the home screen.
-3. Copy a model to `/data/PS5LM/models`, or put it in `PS5LM/models` on a USB drive (exFAT).
-4. Start PS5LM, choose the model in the library, and open `http://<console IP>:8081` on a phone or computer once it says Ready.
+- **Dashboard:** generation speed with its history, GPU and CPU use, SoC power and energy per token, temperatures and fan, the memory pool and how the model, KV cache and the rest split it, context in use, storage on every drive, and the loaded model. Cross expands the USAGE, POWER and MODEL cards.
+- **Model library:** every `.gguf` on internal storage, an M.2 drive or a USB drive, grouped by drive. Each shows the context and KV cache it would get and whether it fits; Cross loads it. A model on USB or M.2 loads straight from the drive.
+- **Settings:** load a model at launch and which one, the longest context, the KV cache type, the chat's file tools and when to warn about their folder, sounds, and which drive downloads go to. Saved to `/data/PS5LM/settings.json`.
+- **Logs:** `app.log` and `llama.log` on the TV, with an errors-only filter.
+- **Get models:** Hugging Face's GGUF repositories, most downloaded or by family. Each file shows its size and whether it fits this console (Square checks one on demand, read from the first 16 MiB of the file). Cross downloads it.
+- **Downloads:** a queue that survives a dropped connection, a pause and the app restarting. Each download resumes where it stopped, retries on its own, and shows speed and time left. Cross pauses or resumes, Square cancels. Files are checked against their SHA-256.
+- **Busy screen:** anything that takes a while (switching or unloading a model, re-planning after a settings change) says what it is doing, so a pause never looks like a crash.
-Which models fit is in [docs/MODELS.md](docs/MODELS.md); anything llama.cpp runs works if the library shows LOAD.
+**Safety checks**
-### What it took
+- Downloads check free space first (the file plus 1 GiB spare) and offer another drive when one has room.
+- A download while a model holds the memory asks first, and can unload it for you.
+- The chat's file tools are confined to `/data/PS5LM/scratch`, with a size warning and a Clear button.
-The full notes are in [docs/CONSOLE.md](docs/CONSOLE.md). In short:
+**On your network**
-- **CPU first:** Qwen 3.8 27B ran as a payload on the Zen 2 CPU, streamed from disk at about a token a minute: proof that llama.cpp works on the console, and that the GPU was needed.
-- **A title, not a payload:** llama-server linked into an fSELF `eboot.bin` with a clean-room `libc.prx`, registered through ShadowMountPlus. Titles may not `exit()`, have some libc imports resolve to nothing, and need a working `getaddrinfo`, `accept4` and `HOME`; each was found by a crash.
-- **The GPU:** ggml-vulkan on [PS5_Vulkan](https://github.com/mihawk-99/PS5_Vulkan)'s RADV with no Vulkan loader, and RADV's unified heap for 11.44 GiB in one heap.
-- **The screen:** [ps5-homebrew-ui](https://github.com/blackbearreloaded/ps5-homebrew-ui) through ps5-opengl, in the same process as RADV (the two Mesa builds share 4,399 symbol names, so the GL stack is linked with only its API visible).
-- **Switching models:** unloading in place leaves about 5 GiB of the pool held, so the app restarts itself for each switch.
-
-### Versions and branches
-
-- Releases follow [semver](https://semver.org): tags `vX.Y.Z`, notes in [CHANGELOG.md](CHANGELOG.md), version set in `ps5/app/version.hpp` and shown on the dashboard. v0.1.x are upstream's payload releases.
-- `main` is this fork's integration branch. Each feature is built on its own branch (`feature/...`, `docs/...`) and merged into `main`; the plans are in [docs/plans](docs/plans).
-- `native-gpu-app` is the branch of the upstream pull request.
+- **Chat:** llama.cpp's web UI at `http://<console IP>:8081`, with file tools and, for vision models such as Gemma 4, images (put the model's `mmproj` file beside it).
+- **API:** OpenAI Chat Completions and Responses, and Anthropic Messages, on the same port. opencode, codex, Claude Code and aider work against it: see [docs/CLI.md](docs/CLI.md).
-## The payload (upstream v0.1)
+**Under the hood**
-The original PS5LM is a payload that needs no install: one `ps5lm.elf` opens a model library in the PS5's browser, for small models (up to 1.6 GB, Qwen3.5 0.8B and 2B). See [docs/ROADMAP.md](docs/ROADMAP.md) and [docs/CONSOLE.md](docs/CONSOLE.md).
+- **Planner:** picks the longest context and the best KV cache type that fit the memory free, per model.
+- **Presets:** sampling settings for Qwen 3.5/3.6/3.8, Gemma 4, gpt-oss, Granite, Nemotron, Mistral and Llama.
+- **Sensors and storage:** a title may not read the temperature, fan or power sensors, or the real free space of a drive, so the app carries [ps5-exporter](https://github.com/Marice/ps5-exporter) (Marice, GPL-3.0) and hands it to elfldr when it is not running.
-<p align="center">
- <a href="https://ps5lm.cobanov.dev"><img src="docs/media/ps5lm-demo.gif" width="640" alt="Qwen3.5 0.8B answering in the PS5's browser, typed with a DualSense"></a>
-</p>
+## What you need
-### Install the payload
+A PS5 you own, on firmware 7.00 to 13.60, jailbroken, with these payloads loaded before you start the app:
-You need a PS5 you own on firmware 7.00 to 13.60, jailbroken, with a payload loader (Payload Manager from WebKit Autoloader, or elfldr on port 9021).
+| Payload | Needed for | |
+|---|---|---|
+| [kstuff-lite](https://github.com/EchoStretch/kstuff-lite) | the kernel patches homebrew titles run on | required |
+| [etaHEN](https://github.com/etaHEN/etaHEN) | homebrew support (see the note below) | required |
+| [ShadowMountPlus](https://github.com/drakmor/ShadowMountPlus) | registers PS5LM from `/data/homebrew` on the home screen | required |
+| [elfldr](https://github.com/ps5-payload-dev/elfldr) (port 9021) | lets the app start ps5-exporter: thermals, fan, power and real free space | strongly recommended |
+| [ftpsrv](https://github.com/ps5-payload-dev/ftpsrv) (port 2121) | installing and updating the app, copying models from a PC | recommended |
+| [klogsrv](https://github.com/ps5-payload-dev/klogsrv) (port 3232) | the console's log over the network, for troubleshooting | optional |
-**From Payload Manager**, which also brings updates:
+ps5-exporter comes inside the app; you do not load it yourself.
-1. *Settings*: turn on **Multiple Payload Sources**.
-2. Add the source `https://ps5lm.cobanov.dev/payloads.json`.
-3. Install **PS5LM** from the list and load it.
+On one console the app crashed at launch with only kstuff-lite, ShadowMountPlus and a DNS payload loaded, and started fine once etaHEN, ftpsrv and klogsrv were added. Which of the three it needed was not isolated, so load at least etaHEN, and all three if the app does not start. Without elfldr the app still works, but the THERMALS and POWER cards stay empty and free space shows as unknown.
-**Or by hand**: download `ps5lm.elf` from the [latest release](https://github.com/cobanov/PS5LM/releases/latest) and load it like any payload (upload it in Payload Manager, or send it to an ELF loader on port 9021).
+## Install
-Once it runs, the PS5's browser opens the PS5LM library. Press **Download** on a model, then **Run**, then **Open chat**. Type with the DualSense.
+1. Download `ps5lm-app-vX.Y.Z.zip` from this fork's [releases](https://github.com/abhi245y/PS5LM/releases) and check it against its `.sha256`.
+2. Unzip it and copy the `PPSA99581` folder to `/data/homebrew/PPSA99581` over FTP. ShadowMountPlus adds **PS5LM** to the home screen.
+3. Start PS5LM. Pick a model in **Get models** (R1 three times), or copy a `.gguf` to `/data/PS5LM/models`, or to `PS5LM/models` on a USB drive (exFAT) or the M.2 drive.
+4. Choose the model in the library. Once the dashboard says Ready, open `http://<console IP>:8081` on a phone or computer.
-The library also works from a phone or computer on the same network at `http://<console IP>:8082`, and the chat at port 8081 speaks the OpenAI API. Models are stored in `/data/PS5LM/models`; a GGUF copied there over FTP shows up too.
+To update, close the app and copy the new `PPSA99581` folder over the old one. Settings, models and downloads stay in `/data/PS5LM`.
-Limits for now: a payload can only keep about 1.6 GB of model locked in memory without starving the home screen, so the catalog has Qwen3.5 0.8B (13 to 21 tok/s) and Qwen3.5 2B (about 9 tok/s). Bigger models need a native app ([#4](https://github.com/cobanov/PS5LM/issues/4)).
+Which models fit is in [docs/MODELS.md](docs/MODELS.md); anything llama.cpp runs works if the library shows LOAD.
-## Why llama.cpp
+## Controls
-Earlier PS5 LLM work hand-writes GPU kernels for one model at a time. PS5LM ports llama.cpp itself, so every architecture and every quantization llama.cpp supports comes along: Qwen, Llama, Mistral, Gemma, from 1-bit to 8-bit. Qwen 3.8's smallest open model is 27B, and only the 2 to 3 bit quants fit in the console's memory, which llama.cpp already has.
+| Where | Button | Does |
+|---|---|---|
+| Everywhere | L1 / R1 | previous / next page |
+| Dashboard | D-pad, Cross | move between cards, expand one; Cross on MODEL opens the library |
+| Library | Cross | load the model under the cursor (the app restarts into it) |
+| Get models | L2 / R2 | change the search (Popular, Qwen, Gemma, ...) |
+| Get models | Square | check whether the file fits |
+| Get models | Cross | open a repository; on a file, download it |
+| Downloads | Cross | pause, resume, or try a failed one again |
+| Downloads | Square | cancel (press twice; the partial file is deleted), or clear a finished one |
+| Logs | Square, Triangle | switch log, errors only |
+
+## How it was built
-## Layout
+The full notes are in [docs/CONSOLE.md](docs/CONSOLE.md). In short:
-| Path | What |
-|---|---|
-| `third_party/llama.cpp` | upstream llama.cpp, pinned as a submodule |
-| `ps5/compat` | the few libc functions the console lacks |
-| `ps5/app` | the native app: llama-server on the GPU through RADV, its icon and `param.json` |
-| `patches/` | PS5 changes to llama.cpp's source, kept small |
-| `probes/` | `memprobe` and `threadprobe`: what a payload gets on the console |
-| `scripts/` | SDK setup, the llama.cpp cross build, sending payloads |
-| `docs/` | [roadmap](docs/ROADMAP.md), [models that fit](docs/MODELS.md), [porting notes](docs/PORTING.md), [research](docs/RESEARCH.md) |
+- **CPU first:** Qwen 3.8 27B ran as a payload on the Zen 2 CPU, streamed from disk at about a token a minute: proof that llama.cpp works on the console, and that the GPU was needed.
+- **A title, not a payload:** llama-server linked into an fSELF `eboot.bin` with a clean-room `libc.prx`, registered through ShadowMountPlus. Titles may not `exit()`, have some libc imports resolve to nothing, and need a working `getaddrinfo`, `accept4` and `HOME`; each was found by a crash.
+- **The GPU:** ggml-vulkan on [PS5_Vulkan](https://github.com/mihawk-99/PS5_Vulkan)'s RADV with no Vulkan loader, and RADV's unified heap for 11.44 GiB in one heap.
+- **The screen:** [ps5-homebrew-ui](https://github.com/blackbearreloaded/ps5-homebrew-ui) through ps5-opengl, in the same process as RADV (the two Mesa builds share 4,399 symbol names, so the GL stack is linked with only its API visible).
+- **Switching models:** unloading in place leaves about 5 GiB of the pool held, so the app restarts itself for each switch.
+- **HTTPS:** downloads use the system's own libSceHttp2 and libSceSsl, so the app carries no TLS library or certificates.
+- **What a title cannot do:** read sensors, see real free space (`statvfs` in a title is a stub), or start processes. ps5-exporter, a payload, covers the first two.
-## Building from source
+## Building the app
-Needs the [ps5-payload-dev SDK](https://github.com/ps5-payload-dev/sdk) and a host LLVM.
+The app links llama.cpp with ggml-vulkan against [PS5_Vulkan](https://github.com/mihawk-99/PS5_Vulkan)'s RADV build. Set up PS5_Vulkan and its forks in `.deps/src` (`PS5_Vulkan`, `PS5_Mesa` and `PS5_PayloadSDK` at the revisions PS5_Vulkan pins), then:
```sh
-# macOS
-brew install llvm@21 lld socat cmake ninja
-# Debian / Ubuntu
-sudo apt install clang-18 lld-18 socat cmake ninja-build
-
git clone --recursive https://github.com/abhi245y/PS5LM
cd PS5LM
-scripts/setup-sdk.sh
-source scripts/env.sh
-
-make -C probes/memprobe # Phase 0 probe
-scripts/build-llama.sh # llama-cli, llama-server, llama-bench for the PS5
-```
-
-## Running on the console
-
-You need a PS5 you own on firmware 7.00 to 13.60, jailbroken, with an ELF loader listening on port 9021 ([elfldr](https://github.com/ps5-payload-dev/elfldr)).
-
-```sh
-scripts/host-relapse.sh # serves the Relapse exploit page; open it in the PS5's browser
-export PS5_HOST=192.168.1.50 # your console
-scripts/console-setup.sh # FTP, kernel log and shell payloads
-scripts/send.sh probes/memprobe/memprobe.elf
-```
-
-The probe streams its results back and also writes them to `/data/PS5LM/memprobe.txt` on the console.
-
-With [ftpsrv](https://github.com/ps5-payload-dev/ftpsrv) running too (port 2121), `scripts/run.sh` uploads a llama.cpp tool and starts it with arguments:
-
-```sh
-# copy a model to /data/PS5LM/models first (FTP or USB)
-scripts/run.sh llama-cli -m /data/PS5LM/models/model.gguf -p "Hello from a PS5" -n 64
-scripts/run.sh llama-server -m /data/PS5LM/models/model.gguf --host 0.0.0.0 --port 8081
+(cd .deps/src/PS5_Vulkan && tools/setup-native-dependencies.sh && tools/build-radv.sh release && make app)
+scripts/build-app.sh # build/app-ps5/title/PPSA99581
+scripts/release-app.sh # build/release/ps5lm-app-vX.Y.Z.zip and its .sha256
```
-## Building the GPU app
-
-The app links llama.cpp with ggml-vulkan against [PS5_Vulkan](https://github.com/mihawk-99/PS5_Vulkan)'s RADV build. Set up PS5_Vulkan and its forks in `.deps/src` (`PS5_Vulkan`, `PS5_Mesa` and `PS5_PayloadSDK` at the revisions PS5_Vulkan pins), then:
+From the PC, with the app on the console:
```sh
-(cd .deps/src/PS5_Vulkan && tools/setup-native-dependencies.sh && tools/build-radv.sh release && make app)
-scripts/build-app.sh # build/app-ps5/title/PPSA99581
+scripts/preview-app-ui.sh # render every screen to build/app-preview/*.png (Mesa, no console)
+PS5_HOST=<console IP> scripts/ps5lm-app.sh cycle # close, deploy, launch; also close|deploy|launch
+PS5_HOST=<console IP> scripts/ps5lm-app.sh press r1 # press a button on the console
+PS5_HOST=<console IP> scripts/ps5lm-app.sh screenshot out.bmp
```
-Copy `build/app-ps5/title/PPSA99581` to `/data/homebrew/PPSA99581` and a model to `/data/PS5LM/models`, then start **PS5LM** from the home screen. The chat is at `http://<console IP>:8081` once the model is on the GPU (about 90 s).
+The app closes itself on request (`/data/PS5LM/quit`), so nothing is killed while it draws. Launching uses [ps5-homebrew-dev-protocol](https://github.com/blackbearreloaded/ps5-homebrew-dev-protocol)'s launch payload, cloned into `.deps/src`. `/data/PS5LM/app-args.txt` (one argument per line) overrides the planner.
-**On the TV** the app shows a dashboard drawn with [ps5-homebrew-ui](https://github.com/blackbearreloaded/ps5-homebrew-ui) (a submodule in `third_party/`): generation speed, how busy the GPU is, CPU use, the memory pool the GPU and CPU share and how the model, its KV cache and the rest split it, context in use, and the model. Cross on the Model tile opens the **model library**: every `.gguf` in `/data/PS5LM/models` and on USB drives (`/mnt/usbN` or `/mnt/usbN/PS5LM/models`), each with the context and KV cache type the planner (`ps5/app/model_plan.cpp`) picks for the memory free, and the sampling settings of its family when it is a model we know (Qwen 3.5/3.6/3.8, Gemma 4, gpt-oss, Granite, Nemotron, Mistral, Llama). It lists internal storage and USB drives in separate sections; Cross loads a model from either. llama.cpp reads the whole file into GPU memory (no mmap), so a model on USB loads at the drive's speed and the drive is not touched afterwards.
+| Path | What |
+|---|---|
+| `ps5/app` | the native app: dashboard, planner, store, downloads, llama-server on the GPU |
+| `third_party/llama.cpp` | upstream llama.cpp, pinned as a submodule |
+| `third_party/ps5-homebrew-ui` | the UI toolkit |
+| `patches/` | PS5 changes to llama.cpp, kept small (tool confinement, Anthropic system messages, ...) |
+| `ps5/compat`, `probes/` | the payload build's libc additions and memory probes (see [docs/PAYLOAD.md](docs/PAYLOAD.md)) |
+| `scripts/` | build, release, deploy and console tools |
+| `docs/` | [coding tools](docs/CLI.md), [models that fit](docs/MODELS.md), [console notes](docs/CONSOLE.md), [porting](docs/PORTING.md), [research](docs/RESEARCH.md), [plans](docs/plans) |
-`/data/PS5LM/app-args.txt` (one argument per line) overrides the planner. The app logs to `/data/PS5LM/app.log` and `llama.log`.
+## Versions and branches
-From the PC:
+- Releases follow [semver](https://semver.org): tags `vX.Y.Z`, notes in [CHANGELOG.md](CHANGELOG.md), version set in `ps5/app/version.hpp` and shown on the dashboard. v0.1.x are upstream's payload releases.
+- `main` is this fork's integration branch. Each feature is built on its own branch (`feature/...`, `docs/...`) and merged into `main`.
+- `native-gpu-app` is the branch of the upstream pull request.
-```sh
-scripts/preview-app-ui.sh # render the dashboard to build/app-preview/*.png (Mesa, no console)
-PS5_HOST=<console IP> scripts/ps5lm-app.sh cycle # close, deploy, launch; also close|deploy|launch
-```
+## Why llama.cpp
-The app closes itself on request (`/data/PS5LM/quit`), so nothing is killed while it draws; launching uses [ps5-homebrew-dev-protocol](https://github.com/blackbearreloaded/ps5-homebrew-dev-protocol)'s launch payload, cloned into `.deps/src`.
+Earlier PS5 LLM work hand-writes GPU kernels for one model at a time. PS5LM ports llama.cpp itself, so every architecture and every quantization llama.cpp supports comes along: Qwen, Llama, Mistral, Gemma, from 1-bit to 8-bit.
## Credits
- **[Mert Cobanov](https://github.com/cobanov)**, who created PS5LM ([cobanov/PS5LM](https://github.com/cobanov/PS5LM)): the llama.cpp port to the PS5, the payload and its library, the build scripts and the research this fork builds on.
- [llama.cpp / ggml](https://github.com/ggml-org/llama.cpp), which does the actual work.
- [PS5_Vulkan](https://github.com/mihawk-99/PS5_Vulkan) (Mihawk-99) for RADV on the PS5, and [ps5-homebrew-ui](https://github.com/blackbearreloaded/ps5-homebrew-ui), [ps5-opengl](https://github.com/blackbearreloaded/ps5-opengl) and ps5-homebrew-dev-protocol (BlackBearReloaded) for the app's screen and tooling.
-- [ps5-payload-dev](https://github.com/ps5-payload-dev) (John Törnblom) for the SDK and the ELF loader.
+- [ps5-exporter](https://github.com/Marice/ps5-exporter) (Marice) for the sensors and drive space the app shows.
+- [ps5-payload-dev](https://github.com/ps5-payload-dev) (John Törnblom) for the SDK, the ELF loader, ftpsrv and klogsrv.
- [PS5SX2](https://github.com/Swordpdf/PS5SX2), [ProsperoAI](https://github.com/blackbearreloaded/ProsperoAI) and [PS5_Vulkan](https://github.com/mihawk-99/PS5_Vulkan), whose notes on the console's memory and GPU this project leans on.
## Licence
diff --git a/docs/PAYLOAD.md b/docs/PAYLOAD.md
new file mode 100644
index 0000000..431d62d
--- /dev/null
+++ b/docs/PAYLOAD.md
@@ -0,0 +1,72 @@
+# The PS5LM payload (archived)
+
+This is the README of the original PS5LM payload by [Mert Cobanov](https://github.com/cobanov),
+kept as it was when this fork moved to the native app. The payload still works and is
+maintained upstream at [cobanov/PS5LM](https://github.com/cobanov/PS5LM); this fork's
+README covers the native app.
+
+## The payload (upstream v0.1)
+
+The original PS5LM is a payload that needs no install: one `ps5lm.elf` opens a model library in the PS5's browser, for small models (up to 1.6 GB, Qwen3.5 0.8B and 2B). See [docs/ROADMAP.md](ROADMAP.md) and [docs/CONSOLE.md](CONSOLE.md).
+
+<p align="center">
+ <a href="https://ps5lm.cobanov.dev"><img src="media/ps5lm-demo.gif" width="640" alt="Qwen3.5 0.8B answering in the PS5's browser, typed with a DualSense"></a>
+</p>
+
+### Install the payload
+
+You need a PS5 you own on firmware 7.00 to 13.60, jailbroken, with a payload loader (Payload Manager from WebKit Autoloader, or elfldr on port 9021).
+
+**From Payload Manager**, which also brings updates:
+
+1. *Settings*: turn on **Multiple Payload Sources**.
+2. Add the source `https://ps5lm.cobanov.dev/payloads.json`.
+3. Install **PS5LM** from the list and load it.
+
+**Or by hand**: download `ps5lm.elf` from the [latest release](https://github.com/cobanov/PS5LM/releases/latest) and load it like any payload (upload it in Payload Manager, or send it to an ELF loader on port 9021).
+
+Once it runs, the PS5's browser opens the PS5LM library. Press **Download** on a model, then **Run**, then **Open chat**. Type with the DualSense.
+
+The library also works from a phone or computer on the same network at `http://<console IP>:8082`, and the chat at port 8081 speaks the OpenAI API. Models are stored in `/data/PS5LM/models`; a GGUF copied there over FTP shows up too.
+
+Limits for now: a payload can only keep about 1.6 GB of model locked in memory without starving the home screen, so the catalog has Qwen3.5 0.8B (13 to 21 tok/s) and Qwen3.5 2B (about 9 tok/s). Bigger models need a native app ([#4](https://github.com/cobanov/PS5LM/issues/4)).
+
+## Building from source
+
+Needs the [ps5-payload-dev SDK](https://github.com/ps5-payload-dev/sdk) and a host LLVM.
+
+```sh
+# macOS
+brew install llvm@21 lld socat cmake ninja
+# Debian / Ubuntu
+sudo apt install clang-18 lld-18 socat cmake ninja-build
+
+git clone --recursive https://github.com/abhi245y/PS5LM
+cd PS5LM
+scripts/setup-sdk.sh
+source scripts/env.sh
+
+make -C probes/memprobe # Phase 0 probe
+scripts/build-llama.sh # llama-cli, llama-server, llama-bench for the PS5
+```
+
+## Running on the console
+
+You need a PS5 you own on firmware 7.00 to 13.60, jailbroken, with an ELF loader listening on port 9021 ([elfldr](https://github.com/ps5-payload-dev/elfldr)).
+
+```sh
+scripts/host-relapse.sh # serves the Relapse exploit page; open it in the PS5's browser
+export PS5_HOST=192.168.1.50 # your console
+scripts/console-setup.sh # FTP, kernel log and shell payloads
+scripts/send.sh probes/memprobe/memprobe.elf
+```
+
+The probe streams its results back and also writes them to `/data/PS5LM/memprobe.txt` on the console.
+
+With [ftpsrv](https://github.com/ps5-payload-dev/ftpsrv) running too (port 2121), `scripts/run.sh` uploads a llama.cpp tool and starts it with arguments:
+
+```sh
+# copy a model to /data/PS5LM/models first (FTP or USB)
+scripts/run.sh llama-cli -m /data/PS5LM/models/model.gguf -p "Hello from a PS5" -n 64
+scripts/run.sh llama-server -m /data/PS5LM/models/model.gguf --host 0.0.0.0 --port 8081
+```
diff --git a/ps5/app/dashboard.cpp b/ps5/app/dashboard.cpp
index 4aa25ec..e60e197 100644
--- a/ps5/app/dashboard.cpp
+++ b/ps5/app/dashboard.cpp
@@ -159,7 +159,7 @@ Color state_color(ServerState s) {
constexpr float kRowH = 78.0f;
constexpr Rect kLibrary{ 360.0f, 150.0f, 1200.0f, 800.0f };
-constexpr const char * kPageNames[Dashboard::kPages] = { "Dashboard", "Settings", "Logs", "Get models" };
+constexpr const char * kPageNames[Dashboard::kPages] = { "Dashboard", "Settings", "Logs", "Get models", "Downloads" };
// The market's searches, switched with L2/R2: Hugging Face's most downloaded
// GGUF repositories, then the families the presets know.
@@ -232,7 +232,9 @@ Rect Dashboard::ring_rect() const {
return scaled(tile_rect(focus_), 1.0f + kLift).inset(-5.0f);
}
-void Dashboard::update(const hui::InputFrame & input, float dt, ui::Feedback & feedback) {
+void Dashboard::update(const hui::InputFrame & raw, float dt, ui::Feedback & feedback) {
+ const hui::InputFrame none{};
+ const hui::InputFrame & input = busy() ? none : raw; // busy: the screen says so, buttons wait
age_ += dt;
clock_ += dt;
page_age_ += dt;
@@ -263,6 +265,8 @@ void Dashboard::update(const hui::InputFrame & input, float dt, ui::Feedback & f
update_settings(input, feedback);
} else if (page_ == kLogsPage) {
update_logs(input, feedback);
+ } else if (page_ == kDownloadsPage) {
+ update_downloads(input, feedback);
} else {
update_market(input, feedback);
}
@@ -693,8 +697,8 @@ void Dashboard::update_market(const hui::InputFrame & input, ui::Feedback & feed
}
}
market_dir_.clear();
- if (f.fits == 0 || market_.download_progress >= 0) {
- feedback.play(hui::audio::Cue::error); // too big, or one download already runs
+ if (f.fits == 0) {
+ feedback.play(hui::audio::Cue::error); // too big
} else if (!to || (to->total > 0 && to->free < need)) { // unknown space (no exporter) does not block
market_space_ = true;
market_dir_ = other ? other->models : "";
@@ -704,12 +708,22 @@ void Dashboard::update_market(const hui::InputFrame & input, ui::Feedback & feed
}
}
}
+ // Square: read this file's header now and say whether it fits.
+ if (input.is_pressed(Action::west) && market_files_ && open && cursor < files) {
+ const MarketFile & f = open->files[(size_t) cursor];
+ if (f.fits == -1 || f.fits == -2) {
+ request_ = { Request::market_plan, "", market_.open, cursor };
+ feedback.play(hui::audio::Cue::select);
+ } else {
+ feedback.play(hui::audio::Cue::error, 1.0f, 0.0f, 0.6f); // checked already
+ }
+ }
if (input.is_pressed(Action::back) && market_files_) {
market_files_ = false;
feedback.play(hui::audio::Cue::back);
}
// The first file of a freshly opened repository gets planned too.
- if (request_.kind == Request::none && market_files_ && files > 0 && market_file_ == 0 && open->files[0].fits == -1 &&
+ if (request_.kind == Request::none && market_files_ && files > 0 && market_file_ == 0 && open->files[0].fits == -1 && !open->files[0].checking &&
!market_.busy) {
request_ = { Request::market_plan, "", market_.open, 0 };
}
@@ -824,6 +838,31 @@ std::string gib(double v) {
return t;
}
+// "2.1 of 10.4 GiB · 3.8 MB/s · 37 min left", or the note of one that waits.
+std::string download_line(const Download & d) {
+ char t[200];
+ const double done = d.done / 1073741824.0, all = d.bytes / 1073741824.0;
+ if (d.state == DownloadState::running && d.mbps > 0.05) {
+ const double left_s = (double) (d.bytes - std::min(d.done, d.bytes)) / (d.mbps * 1e6);
+ if (left_s >= 3600) {
+ std::snprintf(t, sizeof(t), "%.1f of %.1f GiB \xC2\xB7 %.1f MB/s \xC2\xB7 %.0f h %02.0f min left", done, all,
+ d.mbps, std::floor(left_s / 3600), std::fmod(left_s / 60, 60));
+ } else {
+ std::snprintf(t, sizeof(t), "%.1f of %.1f GiB \xC2\xB7 %.1f MB/s \xC2\xB7 %.0f min left", done, all, d.mbps,
+ std::ceil(left_s / 60));
+ }
+ return t;
+ }
+ std::snprintf(t, sizeof(t), "%.1f of %.1f GiB", done, all);
+ if (d.state == DownloadState::running) {
+ return std::string(t) + " \xC2\xB7 starting";
+ }
+ if (!d.note.empty() && d.state != DownloadState::done) {
+ return std::string(t) + " \xC2\xB7 " + d.note;
+ }
+ return d.state == DownloadState::done ? d.note : d.state == DownloadState::queued ? std::string(t) + " \xC2\xB7 waiting its turn" : t;
+}
+
} // namespace
// ---- tiles ------------------------------------------------------------------------
@@ -1631,13 +1670,13 @@ void Dashboard::draw_market(gfx::DrawList & list) const {
}
const size_t slash = mf.name.find_last_of('/');
const std::string short_name = mf.name.substr(slash == std::string::npos ? 0 : slash + 1);
- ui::text(list, cur ? f.semibold : f.regular, f.regular.font->fit(short_name, 20, rw - 230), rx + 12, y + 26,
+ ui::text(list, cur ? f.semibold : f.regular, f.regular.font->fit(short_name, 20, rw - 270), rx + 12, y + 26,
20, kInk.with_alpha(mf.fits == 0 ? 0.45f : 1.0f));
- ui::text(list, f.regular, f.regular.font->fit(mf.plan.empty() ? "Not planned yet" : mf.plan, 16, rw - 230),
+ ui::text(list, f.regular, f.regular.font->fit(mf.checking ? std::string("Reading its header to plan the context it would get") : mf.plan.empty() ? std::string("Not checked yet: Square checks whether it fits") : mf.plan, 16, rw - 270),
rx + 12, y + 50, 16, kInk.with_alpha(kFaint));
std::snprintf(text, sizeof(text), "%.1f GiB", mf.bytes / 1073741824.0);
- ui::text(list, f.mono, text, rx + rw - 110, y + 36, 18, kInk.with_alpha(0.85f), gfx::Align::right);
- const char * tag = mf.fits == 1 ? "FITS" : mf.fits == 0 ? "TOO BIG" : mf.fits == -2 ? "UNKNOWN" : "CHECK";
+ ui::text(list, f.mono, text, rx + rw - 150, y + 36, 18, kInk.with_alpha(0.85f), gfx::Align::right);
+ const char * tag = mf.checking ? "CHECKING" : mf.fits == 1 ? "FITS" : mf.fits == 0 ? "TOO BIG" : mf.fits == -2 ? "UNKNOWN" : "UNCHECKED";
const Color tc = mf.fits == 1 ? kLime : mf.fits == 0 ? kRose : kInk.with_alpha(kMuted);
caps(list, f, tag, rx + rw - 8, y + 36, 14, tc, gfx::Align::right);
}
@@ -1704,18 +1743,122 @@ void Dashboard::draw_market(gfx::DrawList & list) const {
// The download, under both panes.
const float by = p.y + p.h - 64;
list.rounded_rect({ p.x + kPad, by - 24, p.w - 2 * kPad, 1 }, 0, kInk.with_alpha(0.1f));
- if (M.download_progress >= 0) {
- std::snprintf(text, sizeof(text), "Downloading %s \xC2\xB7 %.0f%% \xC2\xB7 %.1f MB/s", M.download_file.c_str(),
- M.download_progress * 100.0f, M.download_mbps);
- ui::text(list, f.regular, f.regular.font->fit(text, 20, p.w - 2 * kPad - 420), p.x + kPad, by + 6, 20, kInk);
- bar(list, { p.x + p.w - kPad - 380, by - 4, 380, 12 }, M.download_progress, kLime);
+ const Download * active = nullptr;
+ int waiting = 0;
+ for (const auto & d : M.downloads) {
+ if ((d.state == DownloadState::running || d.state == DownloadState::retrying) && !active) {
+ active = &d; // the worker runs one at a time; the first is it
+ } else if (d.state == DownloadState::queued) {
+ ++waiting;
+ }
+ }
+ if (active) {
+ std::string line = active->file + " \xC2\xB7 " + download_line(*active);
+ if (waiting > 0) {
+ line += " \xC2\xB7 " + std::to_string(waiting) + " more queued";
+ }
+ ui::text(list, f.regular, f.regular.font->fit(line, 20, p.w - 2 * kPad - 420), p.x + kPad, by + 6, 20, kInk);
+ bar(list, { p.x + p.w - kPad - 380, by - 4, 380, 12 },
+ active->bytes ? (float) ((double) active->done / (double) active->bytes) : 0.0f,
+ active->state == DownloadState::retrying ? kAmber : kLime);
} else {
- const std::string note = !M.download_result.empty() ? M.download_result
- : "Downloads go to " + settings_.download_dir + " \xC2\xB7 change in Settings";
+ const std::string note = !M.note.empty() ? M.note + " \xC2\xB7 R1 for Downloads"
+ : "Downloads go to " + settings_.download_dir + " \xC2\xB7 change in Settings";
ui::text(list, f.regular, f.regular.font->fit(note, 20, p.w - 2 * kPad), p.x + kPad, by + 6, 20, kInk.with_alpha(kMuted));
}
}
+void Dashboard::update_downloads(const hui::InputFrame & input, ui::Feedback & feedback) {
+ const int rows = (int) market_.downloads.size();
+ dl_cursor_ = std::clamp(dl_cursor_, 0, std::max(0, rows - 1));
+ if (input.nav == Direction::up || input.nav == Direction::down) {
+ const int next = dl_cursor_ + (input.nav == Direction::down ? 1 : -1);
+ if (next >= 0 && next < rows) {
+ dl_cursor_ = next;
+ dl_confirm_ = -1;
+ feedback.play(hui::audio::Cue::focus, 1.0f + 0.02f * (float) next);
+ } else if (!input.nav_repeat) {
+ feedback.play(hui::audio::Cue::error, 1.0f, 0.0f, 0.6f);
+ }
+ }
+ if (rows == 0) {
+ return;
+ }
+ const Download & d = market_.downloads[(size_t) dl_cursor_];
+ if (input.is_pressed(Action::confirm)) {
+ if (d.state == DownloadState::running || d.state == DownloadState::retrying || d.state == DownloadState::queued) {
+ request_ = { Request::download_pause, "", dl_cursor_ };
+ feedback.play(hui::audio::Cue::select);
+ } else if (d.state == DownloadState::paused || d.state == DownloadState::failed) {
+ request_ = { Request::download_resume, "", dl_cursor_ };
+ feedback.play(hui::audio::Cue::complete);
+ } else {
+ feedback.play(hui::audio::Cue::error, 1.0f, 0.0f, 0.6f);
+ }
+ }
+ // Square: a finished one leaves the list; any other is cancelled and its
+ // partial file deleted, after a second press.
+ if (input.is_pressed(Action::west)) {
+ if (d.state == DownloadState::done || dl_confirm_ == dl_cursor_) {
+ request_ = { Request::download_remove, "", dl_cursor_ };
+ dl_confirm_ = -1;
+ feedback.play(hui::audio::Cue::back);
+ } else {
+ dl_confirm_ = dl_cursor_;
+ feedback.play(hui::audio::Cue::modal_open);
+ }
+ }
+}
+
+void Dashboard::draw_downloads(gfx::DrawList & list) const {
+ const ui::Fonts & f = fonts_;
+ const Rect & p = kLogPanel;
+ draw_panel(list, p, kRadius, 0.0f, kLime);
+ caps(list, f, "DOWNLOADS", p.x + kPad, p.y + kLabelY, kLabelSize, kLime);
+ double left = 0;
+ for (const auto & d : market_.downloads) {
+ if (d.state != DownloadState::done) {
+ left += (double) (d.bytes - std::min(d.done, d.bytes));
+ }
+ }
+ char text[160];
+ std::snprintf(text, sizeof(text), "%zu in the list \xC2\xB7 %.1f GiB to go \xC2\xB7 they carry on after a lost connection or a restart",
+ market_.downloads.size(), left / 1073741824.0);
+ ui::text(list, f.regular, text, p.x + p.w - kPad, p.y + kLabelY, 18, kInk.with_alpha(kMuted), gfx::Align::right);
+ if (market_.downloads.empty()) {
+ ui::text(list, f.regular, "Nothing downloading. Get models (L1) lists what fits; Cross on a file adds it here.",
+ p.cx(), p.cy(), 24, kInk.with_alpha(kFaint), gfx::Align::center);
+ return;
+ }
+ constexpr float kRow = 112.0f;
+ constexpr int kShown = 6;
+ const int first = std::max(0, dl_cursor_ - (kShown - 1));
+ for (int i = first; i < (int) market_.downloads.size() && i < first + kShown; ++i) {
+ const Download & d = market_.downloads[(size_t) i];
+ const Rect r{ p.x + kPad, p.y + 84 + (float) (i - first) * kRow, p.w - 2 * kPad, kRow - 14 };
+ if (i == dl_cursor_) {
+ list.glow(r, 18, 18, kLime.with_alpha(0.2f));
+ list.bordered_rect(r, 18, kLime.with_alpha(0.08f), 2.0f, kLime.with_alpha(0.7f));
+ }
+ const bool retrying = d.state == DownloadState::retrying;
+ const char * tag = d.state == DownloadState::running ? "DOWNLOADING" : retrying ? "RECONNECTING"
+ : d.state == DownloadState::queued ? "QUEUED" : d.state == DownloadState::paused ? "PAUSED"
+ : d.state == DownloadState::failed ? "FAILED" : "DONE";
+ const Color tc = d.state == DownloadState::running ? kLime : retrying ? kAmber : d.state == DownloadState::failed ? kRose
+ : d.state == DownloadState::done ? kCyan : kInk.with_alpha(kMuted);
+ ui::text(list, f.semibold, f.semibold.font->fit(d.file, 24, r.w - 420), r.x + 20, r.y + 34, 24, kInk);
+ caps(list, f, tag, r.x + r.w - 20, r.y + 34, 15, tc, gfx::Align::right);
+ std::string sub = d.repo + " \xC2\xB7 " + drive_name(d.dir) + " \xC2\xB7 " + download_line(d);
+ if (dl_confirm_ == i) {
+ sub = "Square again cancels it and deletes the " + gib(d.done / 1073741824.0) + " GiB downloaded so far";
+ }
+ ui::text(list, f.regular, f.regular.font->fit(sub, 18, r.w - 40), r.x + 20, r.y + 62, 18,
+ dl_confirm_ == i ? kRose : kInk.with_alpha(kMuted));
+ bar(list, { r.x + 20, r.y + 78, r.w - 40, 8 }, d.bytes ? (float) ((double) d.done / (double) d.bytes) : 0.0f,
+ d.state == DownloadState::done ? kCyan : retrying ? kAmber : d.state == DownloadState::failed ? kRose : kLime);
+ }
+}
+
void Dashboard::draw_logs(gfx::DrawList & list) const {
const ui::Fonts & f = fonts_;
const Rect & p = kLogPanel;
@@ -1798,8 +1941,21 @@ void Dashboard::draw_hints(DashboardFrame & frame) const {
// The dialog carries its own buttons.
} else if (page_ == kMarketPage) {
const ui::Hint browse[] = { { ui::Button::l2, "Search" }, { ui::Button::dpad, "Choose" }, { ui::Button::cross, "Open" } };
- const ui::Hint files[] = { { ui::Button::dpad, "Choose" }, { ui::Button::cross, "Download" }, { ui::Button::circle, "Back" } };
- ui::draw_hints(frame.scene, fonts_, style, market_files_ ? files : browse, 3, kGridX + kGridW, true);
+ const ui::Hint files[] = { { ui::Button::dpad, "Choose" }, { ui::Button::square, "Check fit" }, { ui::Button::cross, "Download" },
+ { ui::Button::circle, "Back" } };
+ ui::draw_hints(frame.scene, fonts_, style, market_files_ ? files : browse, market_files_ ? 4 : 3, kGridX + kGridW, true);
+ } else if (page_ == kDownloadsPage) {
+ const Download * d = dl_cursor_ < (int) market_.downloads.size() ? &market_.downloads[(size_t) dl_cursor_] : nullptr;
+ const bool runs = d && (d->state == DownloadState::running || d->state == DownloadState::retrying ||
+ d->state == DownloadState::queued);
+ const char * cross = !d ? "" : runs ? "Pause" : d->state == DownloadState::done ? "" : d->state == DownloadState::failed ? "Try again" : "Resume";
+ const char * square = !d ? "" : d->state == DownloadState::done ? "Clear from list" : dl_confirm_ == dl_cursor_ ? "Yes, delete it" : "Cancel";
+ const ui::Hint all[] = { { ui::Button::dpad, "Choose" }, { ui::Button::square, square }, { ui::Button::cross, cross } };
+ const ui::Hint done[] = { { ui::Button::dpad, "Choose" }, { ui::Button::square, square } };
+ if (d) {
+ const bool has_cross = d->state != DownloadState::done;
+ ui::draw_hints(frame.scene, fonts_, style, has_cross ? all : done, has_cross ? 3 : 2, kGridX + kGridW, true);
+ }
} else if (page_ == kLogsPage) {
const ui::Hint hints[] = { { ui::Button::dpad, "Scroll" },
{ ui::Button::square, log_llama_ ? "app.log" : "llama.log" },
@@ -1856,6 +2012,8 @@ void Dashboard::draw(DashboardFrame & frame) const {
draw_settings(scene);
} else if (page_ == kLogsPage) {
draw_logs(scene);
+ } else if (page_ == kDownloadsPage) {
+ draw_downloads(scene);
} else {
draw_market(scene);
}
@@ -1869,6 +2027,28 @@ void Dashboard::draw(DashboardFrame & frame) const {
draw_details(frame.overlay, frame.glass_texture);
}
draw_hints(frame);
+ if (busy()) {
+ draw_busy(frame.overlay); // the overlay draws last, over the library too
+ }
+}
+
+// Slow work: a scrim, a turning arc and what is happening, so a pause never
+// looks like a hang.
+void Dashboard::draw_busy(gfx::DrawList & list) const {
+ const ui::Fonts & f = fonts_;
+ list.rounded_rect({ 0, 0, 1920, 1080 }, 0, kBlack.with_alpha(0.6f));
+ const Rect d{ 960 - 420, 540 - 120, 840, 240 };
+ list.shadow({ d.x, d.y + 18, d.w, d.h }, 28, 40, kBlack.with_alpha(0.6f));
+ draw_panel(list, d, 28, 1.0f, kCyan);
+ const float cx = d.x + 92, cy = d.cy();
+ list.ring(cx, cy, 34, 6, kInk.with_alpha(0.12f));
+ const float sweep = 1.6f + 0.9f * std::sin(clock_ * 2.1f);
+ list.arc(cx, cy, 34, 6, clock_ * 5.0f, sweep, kCyan);
+ ui::text(list, f.semibold, f.semibold.font->fit(busy_title_, 28, d.w - 200), d.x + 160, cy - 10, 28, kInk);
+ if (!busy_text_.empty()) {
+ ui::text(list, f.regular, f.regular.font->fit(busy_text_, 21, d.w - 200), d.x + 160, cy + 30, 21,
+ kInk.with_alpha(kMuted));
+ }
}
} // namespace ps5lm
diff --git a/ps5/app/dashboard.hpp b/ps5/app/dashboard.hpp
index f63872f..b329564 100644
--- a/ps5/app/dashboard.hpp
+++ b/ps5/app/dashboard.hpp
@@ -38,13 +38,21 @@ struct DashboardFrame {
class Dashboard {
public:
static constexpr int kTiles = 8;
- static constexpr int kPages = 4;
+ static constexpr int kPages = 5;
static constexpr int kLogsPage = 2;
static constexpr int kMarketPage = 3;
+ static constexpr int kDownloadsPage = 4;
explicit Dashboard(const hui::ui::Fonts & fonts) : fonts_(fonts) { ring_.snap(ring_rect()); }
void set_live(const Live & live) { live_ = live; }
+ // Slow work in progress: a spinner and these lines over everything, and
+ // no input until it is cleared (empty title).
+ void set_busy(std::string title, std::string text = {}) {
+ busy_title_ = std::move(title);
+ busy_text_ = std::move(text);
+ }
+ bool busy() const { return !busy_title_.empty(); }
void open_library(); // over the dashboard, cursor on the loaded model
void set_settings(const Settings & s) { settings_ = s; }
const Settings & settings() const { return settings_; }
@@ -67,9 +75,9 @@ class Dashboard {
// changed (read them with settings()).
struct Request {
enum Kind { none, load, unload, settings, clear_scratch, market_search, market_open, market_plan, market_download,
- market_download_unload } kind = none;
+ market_download_unload, download_pause, download_resume, download_remove } kind = none;
std::string path; // a model, a market query, or the folder a download goes to (empty: the setting)
- int repo = -1, file = -1;
+ int repo = -1, file = -1; // a market file, or (repo) a download's index
};
Request take_request() {
Request r = request_;
@@ -95,6 +103,8 @@ class Dashboard {
void update_logs(const hui::InputFrame & input, hui::ui::Feedback & feedback);
void update_market(const hui::InputFrame & input, hui::ui::Feedback & feedback);
void start_download(hui::ui::Feedback & feedback);
+ void update_downloads(const hui::InputFrame & input, hui::ui::Feedback & feedback);
+ void draw_downloads(hui::gfx::DrawList & list) const;
void draw_market(hui::gfx::DrawList & list) const;
const std::vector<std::string> & log_view() const { return log_llama_ ? llama_view_ : app_view_; }
void refilter_logs();
@@ -105,6 +115,8 @@ class Dashboard {
float age_ = 0; // seconds since start: the entrance
float clock_ = 0; // idle motion
+ std::string busy_title_, busy_text_;
+ void draw_busy(hui::gfx::DrawList & list) const;
int focus_ = 0;
int came_from_ = -1;
hui::Direction came_by_ = hui::Direction::none;
@@ -148,6 +160,8 @@ class Dashboard {
bool market_confirm_ = false; // asking whether to unload the model first
bool market_space_ = false; // telling that the download does not fit where it would go
std::string market_dir_; // where this download goes instead of the setting, or empty
+ int dl_cursor_ = 0; // the Downloads page's row
+ int dl_confirm_ = -1; // the row Square was pressed on once (a second press deletes)
mutable char size_text_[64] = {};
};
diff --git a/ps5/app/fetch.cpp b/ps5/app/fetch.cpp
index 17fc098..276b9cb 100644
--- a/ps5/app/fetch.cpp
+++ b/ps5/app/fetch.cpp
@@ -23,6 +23,8 @@ int sceHttp2ReadData(int req, void * buf, size_t size);
int sceHttp2DeleteRequest(int req);
int sceHttp2SetAutoRedirect(int id, int enable);
int sceHttp2GetAllResponseHeaders(int req, char ** headers, size_t * size);
+int sceHttp2SetRecvTimeOut(int id, uint32_t usec);
+int sceHttp2SetConnectTimeOut(int id, uint32_t usec);
}
namespace ps5lm {
@@ -31,6 +33,7 @@ namespace {
std::mutex g_init;
int g_template = -1;
+int g_http = -1;
std::string g_init_error;
// The libraries once per process; their contexts live as long as it does.
@@ -51,11 +54,12 @@ bool init(std::string * error) {
std::snprintf(text, sizeof(text), "sceNetPoolCreate 0x%x", net);
} else if ((ssl = sceSslInit(512 * 1024)) < 0) {
std::snprintf(text, sizeof(text), "sceSslInit 0x%x", ssl);
- } else if ((http = sceHttp2Init(net, ssl, 512 * 1024, 4)) < 0) {
+ } else if ((http = sceHttp2Init(net, ssl, 512 * 1024, 4)) < 0) { // more requests or pool: refused, 0x817b121c
std::snprintf(text, sizeof(text), "sceHttp2Init 0x%x", http);
} else if ((g_template = sceHttp2CreateTemplate(http, "PS5LM/1.0", 3, 1)) < 0) {
std::snprintf(text, sizeof(text), "sceHttp2CreateTemplate 0x%x", g_template);
} else {
+ g_http = http;
return true;
}
g_template = -1;
@@ -69,13 +73,7 @@ bool init(std::string * error) {
namespace {
// The Location header of a redirect, or empty.
-std::string location(int req) {
- char * headers = nullptr;
- size_t size = 0;
- if (sceHttp2GetAllResponseHeaders(req, &headers, &size) != 0 || !headers) {
- return {};
- }
- const std::string h(headers, size);
+std::string location_in(const std::string & h) {
for (size_t at = 0; at < h.size();) {
const size_t end = h.find('\n', at);
std::string line = h.substr(at, end == std::string::npos ? std::string::npos : end - at);
@@ -90,15 +88,35 @@ std::string location(int req) {
return {};
}
+std::string location(int req) {
+ char * headers = nullptr;
+ size_t size = 0;
+ if (sceHttp2GetAllResponseHeaders(req, &headers, &size) != 0 || !headers) {
+ return {};
+ }
+ return location_in(std::string(headers, size));
+}
+
} // namespace
+int https_template() {
+ std::string error;
+ if (!init(&error)) {
+ return -1;
+ }
+ return sceHttp2CreateTemplate(g_http, "PS5LM/1.0", 3, 1);
+}
+
FetchResult https_get(const std::string & url_in, const std::string & range,
- const std::function<bool(const char *, size_t)> & sink) {
+ const std::function<bool(const char *, size_t)> & sink, int tmpl, size_t buffer) {
FetchResult r;
const auto t0 = std::chrono::steady_clock::now();
if (!init(&r.error)) {
return r;
}
+ if (tmpl < 0) {
+ tmpl = g_template;
+ }
char text[160];
// Redirects are followed here, not by the library: after following one
// itself (Hugging Face's file links go to a CDN) it reported the length
@@ -106,13 +124,17 @@ FetchResult https_get(const std::string & url_in, const std::string & range,
std::string url = url_in;
int req = -1;
for (int hop = 0; hop < 6; ++hop) {
- req = sceHttp2CreateRequestWithURL(g_template, "GET", url.c_str(), 0);
+ req = sceHttp2CreateRequestWithURL(tmpl, "GET", url.c_str(), 0);
if (req < 0) {
std::snprintf(text, sizeof(text), "sceHttp2CreateRequestWithURL 0x%x", req);
r.error = text;
return r;
}
sceHttp2SetAutoRedirect(req, 0);
+ // A connection that goes quiet fails after 30 s instead of hanging;
+ // the downloader then asks again for the rest.
+ sceHttp2SetConnectTimeOut(req, 30u * 1000 * 1000);
+ sceHttp2SetRecvTimeOut(req, 30u * 1000 * 1000);
if (!range.empty()) {
sceHttp2AddRequestHeader(req, "Range", range.c_str(), 0);
}
@@ -146,7 +168,7 @@ FetchResult https_get(const std::string & url_in, const std::string & range,
r.length = (int64_t) length; // result 0: the length is known
}
// Large reads: 64 KiB ones ran at about 200 KB/s.
- std::vector<char> buf(4u << 20);
+ std::vector<char> buf(buffer);
for (;;) {
const int n = sceHttp2ReadData(req, buf.data(), buf.size());
if (n < 0) {
diff --git a/ps5/app/fetch.hpp b/ps5/app/fetch.hpp
index 3628418..517a2f4 100644
--- a/ps5/app/fetch.hpp
+++ b/ps5/app/fetch.hpp
@@ -21,7 +21,14 @@ struct FetchResult {
// GET `url`, optionally with a Range header ("bytes=0-16777215"). Each piece
// of the body goes to `sink`; returning false from it stops the download.
+// `tmpl`: a template from https_template(), or -1 for the shared one; each
+// template may keep its own connections. `buffer`: bytes asked of each read.
FetchResult https_get(const std::string & url, const std::string & range,
- const std::function<bool(const char *, size_t)> & sink);
+ const std::function<bool(const char *, size_t)> & sink, int tmpl = -1,
+ size_t buffer = 4u << 20);
+
+// A new template on the shared context, or a negative error. Make them one
+// at a time: four threads making theirs at once crashed the app.
+int https_template();
} // namespace ps5lm
diff --git a/ps5/app/main.cpp b/ps5/app/main.cpp
index 6884b9f..8adfc16 100644
--- a/ps5/app/main.cpp
+++ b/ps5/app/main.cpp
@@ -103,7 +103,6 @@ constexpr const char * kChoice = "/data/PS5LM/model.txt";
constexpr const char * kQuit = "/data/PS5LM/quit";
constexpr const char * kSettings = "/data/PS5LM/settings.json";
constexpr const char * kScratch = "/data/PS5LM/scratch";
-constexpr const char * kPendingDownload = "/data/PS5LM/download.txt"; // a download to start after a restart
// The file tools only: a title cannot start processes (no shell command).
constexpr const char * kTools = "read_file,write_file,edit_file,file_glob_search,grep_search,get_info";
constexpr const char * kLlamaLog = "/data/PS5LM/llama.log";
@@ -380,7 +379,54 @@ struct Models {
const char * kv_force() const { return settings.kv_type == "auto" ? nullptr : settings.kv_type.c_str(); }
void scan(StatsCollector & stats) {
- rows.clear();
+ rows = plan_rows(settings, budget_gib, running);
+ publish(stats);
+ }
+
+ // scan() on its own thread, for a settings change: the dashboard shows it
+ // working instead of freezing while every header is read.
+ std::mutex scan_mutex;
+ std::vector<ModelRow> scanned;
+ std::atomic<int> scan_state{ 0 }; // 0 idle, 1 running, 2 done
+ bool scan_again = false;
+ bool scan_shown = true; // the dashboard says it is working
+
+ void rescan(StatsCollector & stats, bool shown = true) {
+ scan_shown = shown;
+ if (scan_state != 0) {
+ scan_again = true; // the running one read the old settings
+ return;
+ }
+ scan_state = 1;
+ std::thread([this, s = settings, b = budget_gib, r = running] {
+ std::vector<ModelRow> out = plan_rows(s, b, r);
+ std::lock_guard<std::mutex> lock(scan_mutex);
+ scanned = std::move(out);
+ scan_state = 2;
+ }).detach();
+ (void) stats;
+ }
+
+ // Takes a finished rescan; true while one is still running.
+ bool poll_rescan(StatsCollector & stats) {
+ if (scan_state == 2) {
+ {
+ std::lock_guard<std::mutex> lock(scan_mutex);
+ rows = std::move(scanned);
+ }
+ scan_state = 0;
+ publish(stats);
+ if (scan_again) {
+ scan_again = false;
+ rescan(stats);
+ }
+ }
+ return scan_state != 0;
+ }
+
+ static std::vector<ModelRow> plan_rows(const Settings & settings, double budget_gib, const std::string & running) {
+ std::vector<ModelRow> rows;
+ const char * kv = settings.kv_type == "auto" ? nullptr : settings.kv_type.c_str();
for (const auto & path : find_models(kModelDirs)) {
const ModelInfo m = read_model_info(path);
ModelRow row;
@@ -392,7 +438,7 @@ struct Models {
rows.push_back(row);
continue;
}
- const Plan p = plan_model(m, budget_gib, settings.ctx_cap, kv_force());
+ const Plan p = plan_model(m, budget_gib, settings.ctx_cap, kv);
const Preset * pre = find_preset(m);
row.arch = m.arch;
row.plan = p.why;
@@ -403,7 +449,7 @@ struct Models {
rows.push_back(row);
std::printf("ps5lm-app: model %s (%s): %s\n", m.file_name.c_str(), m.arch.c_str(), p.why.c_str());
}
- publish(stats);
+ return rows;
}
void publish(StatsCollector & stats) {
@@ -608,24 +654,28 @@ int main(int, char **) {
Dashboard dash(fonts);
Market market;
market.start(models.budget_gib);
- std::string last_download;
+ int saved_seen = 0; // downloads finished, as last seen
dash.set_settings(models.settings);
bool library_shown = false; // opened once at launch when no model is loaded
bool scratch_warned = false;
- // A download asked for with "unload and download" before the restart.
- if (const auto pending = read_lines(kPendingDownload); pending.size() >= 5) {
- unlink(kPendingDownload);
- MarketJob job{ pending[0], pending[1], pending[2] == "-" ? "" : pending[2], pending[4], std::strtoull(pending[3].c_str(), nullptr, 10) };
- market.download(job, free_gib(job.dir));
- dash.show_page(Dashboard::kMarketPage);
- library_shown = true; // stay on Get models, not the library
- std::printf("ps5lm-app: downloading %s/%s after the restart\n", job.repo.c_str(), job.file.c_str());
+ // Downloads left queued or running carry on, on their own page.
+ unlink("/data/PS5LM/download.txt"); // the queue file replaced this one (v0.7.0)
+ market.load_queue();
+ for (const auto & d : market.snapshot().downloads) {
+ // Running already, maybe: the queue's thread starts it at once.
+ if (d.state == DownloadState::queued || d.state == DownloadState::running) {
+ dash.show_page(Dashboard::kDownloadsPage);
+ library_shown = true; // stay on Downloads, not the library
+ break;
+ }
}
DashboardFrame frame;
hui::ui::Feedback feedback;
hui::PadSample samples[64];
int64_t last = hui::sys::monotonic_us();
bool was_serving = false;
+ bool rescanning = false;
+ uint64_t restart_at = 0; // the frame to stop the model and restart on, or 0
for (uint64_t n = 0;; ++n) {
const int64_t now = hui::sys::monotonic_us();
const float dt = n == 0 ? 1.0f / 60.0f : std::min(0.05f, (float) (now - last) / 1e6f);
@@ -711,15 +761,13 @@ int main(int, char **) {
}
scratch_warned = over;
}
- if (dash.page() == Dashboard::kMarketPage && n % 10 == 0) {
+ if (n % 10 == 0) {
MarketView mv = market.snapshot();
// A finished download joins the library.
- if (!mv.download_result.empty() && mv.download_result != last_download) {
- last_download = mv.download_result;
- if (mv.download_result.rfind("Saved", 0) == 0) {
- models.scan(stats);
- notify(("PS5LM: " + mv.download_result).c_str());
- }
+ if (mv.saved != saved_seen) {
+ saved_seen = mv.saved;
+ models.rescan(stats, false);
+ notify(("PS5LM: " + mv.note).c_str());
}
dash.set_market(std::move(mv));
}
@@ -727,13 +775,36 @@ int main(int, char **) {
dash.set_logs(tail_lines(kLog), tail_lines(kLlamaLog));
}
+ // A settings rescan in the background: say so until it lands.
+ if (models.poll_rescan(stats) && models.scan_shown) {
+ char text[96];
+ std::snprintf(text, sizeof(text), "Planning every model again for %uk tokens and the %s cache",
+ models.settings.ctx_cap / 1024, models.settings.kv_type.c_str());
+ dash.set_busy("Applying the new limits", text);
+ rescanning = true;
+ } else if (rescanning) {
+ rescanning = false;
+ dash.set_busy("");
+ }
+ // A restart asked for a few frames ago, once the busy screen is up.
+ if (restart_at != 0 && n >= restart_at) {
+ std::fflush(nullptr);
+ models.stop();
+ sceSystemServiceLoadExec("/app0/eboot.bin", nullptr);
+ }
+
Dashboard::Request req = dash.take_request();
if (req.kind == Dashboard::Request::settings) {
// The planner's limits change every row's plan; the loaded model
// keeps its settings until it is loaded again.
+ // Only the context and cache limits change the plans; rescanning
+ // reads every model's header, seconds with a USB drive.
+ const Settings was = models.settings;
models.settings = dash.settings();
save_settings(kSettings, models.settings);
- models.scan(stats);
+ if (was.ctx_cap != models.settings.ctx_cap || was.kv_type != models.settings.kv_type) {
+ models.rescan(stats);
+ }
std::printf("ps5lm-app: settings saved\n");
}
switch (req.kind) {
@@ -743,23 +814,23 @@ int main(int, char **) {
case Dashboard::Request::market_download: {
MarketJob job;
if (market.job(req.repo, req.file, req.path.empty() ? models.settings.download_dir : req.path, &job)) {
- market.download(job, free_gib(job.dir));
+ market.enqueue(job, free_gib(job.dir));
}
break;
}
+ case Dashboard::Request::download_pause: market.pause(req.repo); break;
+ case Dashboard::Request::download_resume: market.resume(req.repo); break;
+ case Dashboard::Request::download_remove: market.remove(req.repo); break;
case Dashboard::Request::market_download_unload: {
- // Unload by restarting (as the library does), leaving the
- // download for the new process to start.
+ // Unload by restarting (as the library does); the queue,
+ // saved to disk, starts the download in the new process.
MarketJob job;
- if (market.job(req.repo, req.file, req.path.empty() ? models.settings.download_dir : req.path, &job)) {
- std::ofstream(kPendingDownload) << job.repo << "\n" << job.file << "\n" << (job.sha256.empty() ? "-" : job.sha256) << "\n"
- << job.bytes << "\n" << job.dir << "\n";
+ if (market.job(req.repo, req.file, req.path.empty() ? models.settings.download_dir : req.path, &job) &&
+ market.enqueue(job, free_gib(job.dir))) {
std::ofstream(kChoice) << "none\n";
- notify("PS5LM: unloading the model, then downloading");
std::printf("ps5lm-app: restarting to download %s/%s without a model\n", job.repo.c_str(), job.file.c_str());
- std::fflush(nullptr);
- models.stop();
- sceSystemServiceLoadExec("/app0/eboot.bin", nullptr);
+ dash.set_busy("Unloading " + base_name(models.running), "The app restarts without it, then the download starts");
+ restart_at = n + 3;
}
break;
}
@@ -798,11 +869,16 @@ int main(int, char **) {
if (req.kind == Dashboard::Request::load) {
unlink(kArgs); // the library's choice replaces a manual override
}
- notify(req.kind == Dashboard::Request::load ? "PS5LM: loading the new model" : "PS5LM: model unloaded");
std::printf("ps5lm-app: restarting for %s\n", req.kind == Dashboard::Request::load ? req.path.c_str() : "no model");
- std::fflush(nullptr);
- models.stop();
- sceSystemServiceLoadExec("/app0/eboot.bin", nullptr);
+ const bool loaded = !models.running.empty();
+ if (req.kind == Dashboard::Request::load) {
+ dash.set_busy(loaded ? "Switching models" : "Loading " + base_name(req.path),
+ loaded ? "Unloading " + base_name(models.running) + ", then the app restarts with " + base_name(req.path)
+ : "The app restarts to give the model the whole memory");
+ } else {
+ dash.set_busy("Unloading " + base_name(models.running), "The app restarts without a model, about 30 seconds");
+ }
+ restart_at = n + 3; // three frames with the busy screen on the TV first
}
if (ui_ok) {
diff --git a/ps5/app/market.cpp b/ps5/app/market.cpp
index 87efc6e..a4b14f8 100644
--- a/ps5/app/market.cpp
+++ b/ps5/app/market.cpp
@@ -11,8 +11,12 @@ extern "C" {
}
#include <cstdio>
+#include <algorithm>
+#include <chrono>
#include <fcntl.h>
#include <filesystem>
+#include <fstream>
+#include <sys/stat.h>
#include <unistd.h>
namespace ps5lm {
@@ -156,36 +160,55 @@ void Market::open_repo(int index) {
});
}
+// Checks wait in a queue and run one at a time on their own thread, so one
+// asked for while another (or a search) runs is not lost. They are kept by
+// repository and file name: the lists can change while one waits.
void Market::plan_file(int repo, int file) {
- std::string id, name;
- uint64_t bytes = 0;
{
std::lock_guard<std::mutex> lock(mutex_);
if (repo < 0 || repo >= (int) view_.repos.size() || file < 0 ||
file >= (int) view_.repos[(size_t) repo].files.size()) {
return;
}
- const MarketFile & f = view_.repos[(size_t) repo].files[(size_t) file];
- if (f.fits != -1) {
- return; // planned already, or too big by its size alone
+ MarketFile & f = view_.repos[(size_t) repo].files[(size_t) file];
+ if ((f.fits != -1 && f.fits != -2) || f.checking) {
+ return; // planned already, too big by its size alone, or waiting
}
- id = view_.repos[(size_t) repo].id;
- name = f.name;
- bytes = f.bytes;
+ f.checking = true;
+ plans_.push_back({ view_.repos[(size_t) repo].id, f.name, f.bytes });
}
- run(browsing_, [this, repo, file, id, name, bytes] {
- std::string error;
- const std::string head = get_text(std::string(kHub) + "/" + id + "/resolve/main/" + name, "bytes=0-16777215", &error,
- 16u << 20);
- const ModelInfo m = read_model_header(name, head, bytes);
- const Plan p = plan_model(m, budget_gib_);
- std::lock_guard<std::mutex> lock(mutex_);
- if (repo < (int) view_.repos.size() && file < (int) view_.repos[(size_t) repo].files.size()) {
- MarketFile & f = view_.repos[(size_t) repo].files[(size_t) file];
- f.fits = m.ok ? (p.fits ? 1 : 0) : -2;
- f.plan = m.ok ? p.why : (!error.empty() ? error : m.error);
+ if (planning_.exchange(true)) {
+ return; // the running thread takes it
+ }
+ std::thread([this] {
+ for (;;) {
+ PlanJob job;
+ {
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (plans_.empty()) {
+ planning_ = false;
+ return;
+ }
+ job = plans_.back(); // the newest first: what the cursor is on
+ plans_.pop_back();
+ }
+ std::string error;
+ const std::string head = get_text(std::string(kHub) + "/" + job.repo + "/resolve/main/" + job.file,
+ "bytes=0-16777215", &error, 16u << 20);
+ const ModelInfo m = read_model_header(job.file, head, job.bytes);
+ const Plan p = plan_model(m, budget_gib_);
+ std::lock_guard<std::mutex> lock(mutex_);
+ for (auto & r : view_.repos) {
+ for (auto & f : r.files) {
+ if (r.id == job.repo && f.name == job.file) {
+ f.fits = m.ok ? (p.fits ? 1 : 0) : -2;
+ f.checking = false;
+ f.plan = m.ok ? p.why : (!error.empty() ? error : m.error);
+ }
+ }
+ }
}
- });
+ }).detach();
}
bool Market::job(int repo, int file, const std::string & dir, MarketJob * out) {
@@ -198,84 +221,402 @@ bool Market::job(int repo, int file, const std::string & dir, MarketJob * out) {
return true;
}
-void Market::download(const MarketJob & job, double free) {
- const std::string id = job.repo, name = job.file, sha = job.sha256, dir = job.dir;
- const uint64_t bytes = job.bytes;
- {
+namespace {
+
+constexpr const char * kQueue = "/data/PS5LM/downloads.json";
+
+// Pieces at once, each on its own template (made once, one after the
+// other). Measured on the console (CHANGELOG 0.8.0): one connection gets 3
+// to 6 MB/s and more do not add much, but two never hurt, and the library's
+// four requests leave two for Get models while a download runs.
+constexpr int kConnections = 2;
+FetchResult kGet(int worker, const std::string & url, const std::string & range,
+ const std::function<bool(const char *, size_t)> & sink) {
+ static const int tmpl[kConnections] = { https_template(), https_template() };
+ return https_get(url, range, sink, tmpl[worker % kConnections] >= 0 ? tmpl[worker % kConnections] : -1, 4u << 20);
+}
+
+const char * state_name(DownloadState s) {
+ switch (s) {
+ case DownloadState::queued: return "queued";
+ case DownloadState::running: return "running";
+ case DownloadState::retrying: return "retrying";
+ case DownloadState::paused: return "paused";
+ case DownloadState::failed: return "failed";
+ case DownloadState::done: return "done";
+ }
+ return "queued";
+}
+
+std::string part_path(const Download & d) {
+ const size_t slash = d.file.find_last_of('/');
+ return d.dir + "/" + d.file.substr(slash == std::string::npos ? 0 : slash + 1) + ".part";
+}
+
+uint64_t file_size(const std::string & path) {
+ struct stat st = {};
+ return stat(path.c_str(), &st) == 0 ? (uint64_t) st.st_size : 0;
+}
+
+} // namespace
+
+void Market::save_queue() {
+ nlohmann::json j = nlohmann::json::array();
+ for (const auto & d : view_.downloads) {
+ j.push_back({ { "repo", d.repo }, { "file", d.file }, { "sha256", d.sha256 }, { "dir", d.dir }, { "bytes", d.bytes },
+ { "state", state_name(d.state) }, { "note", d.note }, { "resume", d.resume } });
+ }
+ std::ofstream(kQueue) << j.dump(1) << "\n";
+}
+
+void Market::load_queue() {
+ std::ifstream in(kQueue);
+ const nlohmann::json j = nlohmann::json::parse(in, nullptr, false);
+ if (!j.is_array()) {
+ return;
+ }
+ std::lock_guard<std::mutex> lock(mutex_);
+ for (const auto & e : j) {
+ Download d;
+ d.repo = e.value("repo", std::string());
+ d.file = e.value("file", std::string());
+ d.sha256 = e.value("sha256", std::string());
+ d.dir = e.value("dir", std::string());
+ d.bytes = e.value("bytes", (uint64_t) 0);
+ d.note = e.value("note", std::string());
+ const std::string st = e.value("state", std::string());
+ // Running when the app stopped: carry on.
+ d.state = st == "paused" ? DownloadState::paused : st == "failed" ? DownloadState::failed
+ : st == "done" ? DownloadState::done : DownloadState::queued;
+ // v0.7 queues had no "resume": their partial files were written in order.
+ d.resume = e.value("resume", file_size(part_path(d)));
+ d.done = d.state == DownloadState::done ? d.bytes : d.resume;
+ if (!d.repo.empty() && !d.file.empty()) {
+ view_.downloads.push_back(d);
+ }
+ }
+ if (!working_.exchange(true)) {
+ std::thread([this] { worker(); }).detach();
+ }
+}
+
+bool Market::enqueue(const MarketJob & job, double free) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ for (const auto & d : view_.downloads) {
+ if (d.repo == job.repo && d.file == job.file && d.state != DownloadState::done) {
+ view_.note = job.file + " is in Downloads already";
+ return false;
+ }
+ }
+ // Room for the file and 1 GiB to spare, so a download never fills a
+ // drive (a full /data upsets the system, not only this app).
+ if (free >= 0 && free < job.bytes / 1073741824.0 + 1.0) {
+ char text[256];
+ std::snprintf(text, sizeof(text), "Not enough space: %s needs %.1f GiB and 1 GiB spare, %s has %.1f GiB free",
+ job.file.c_str(), job.bytes / 1073741824.0, job.dir.c_str(), free);
+ view_.note = text;
+ std::printf("ps5lm-app: download %s/%s: %s\n", job.repo.c_str(), job.file.c_str(), text);
+ return false;
+ }
+ Download d;
+ static_cast<MarketJob &>(d) = job;
+ d.resume = d.done = 0; // ponytail: a stray partial file is fetched again, its progress is not known
+ view_.downloads.push_back(d);
+ view_.note = job.file + " added to Downloads";
+ save_queue();
+ if (!working_.exchange(true)) {
+ std::thread([this] { worker(); }).detach();
+ }
+ return true;
+}
+
+void Market::pause(int i) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (i < 0 || i >= (int) view_.downloads.size()) {
+ return;
+ }
+ Download & d = view_.downloads[(size_t) i];
+ if (d.state == DownloadState::running || d.state == DownloadState::retrying) {
+ stop_ = 1; // the worker marks it paused
+ } else if (d.state == DownloadState::queued) {
+ d.state = DownloadState::paused;
+ save_queue();
+ }
+}
+
+void Market::resume(int i) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (i < 0 || i >= (int) view_.downloads.size()) {
+ return;
+ }
+ Download & d = view_.downloads[(size_t) i];
+ if (d.state == DownloadState::paused || d.state == DownloadState::failed) {
+ d.state = DownloadState::queued;
+ d.attempt = 0;
+ d.note.clear();
+ save_queue();
+ if (!working_.exchange(true)) {
+ std::thread([this] { worker(); }).detach();
+ }
+ }
+}
+
+void Market::remove(int i) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (i < 0 || i >= (int) view_.downloads.size()) {
+ return;
+ }
+ Download & d = view_.downloads[(size_t) i];
+ if (d.state == DownloadState::running || d.state == DownloadState::retrying) {
+ stop_ = 2; // the worker deletes the partial file and the entry
+ return;
+ }
+ if (d.state != DownloadState::done) {
+ unlink(part_path(d).c_str());
+ }
+ view_.downloads.erase(view_.downloads.begin() + i);
+ save_queue();
+}
+
+void Market::worker() {
+ for (;;) {
+ Download d;
+ {
+ std::lock_guard<std::mutex> lock(mutex_);
+ auto it = std::find_if(view_.downloads.begin(), view_.downloads.end(),
+ [](const Download & x) { return x.state == DownloadState::queued; });
+ if (it == view_.downloads.end()) {
+ working_ = false;
+ return;
+ }
+ it->state = DownloadState::running;
+ d = *it;
+ stop_ = 0;
+ }
+ fetch(d);
std::lock_guard<std::mutex> lock(mutex_);
- if (downloading_) {
- return;
+ auto it = std::find_if(view_.downloads.begin(), view_.downloads.end(),
+ [&](const Download & x) { return x.repo == d.repo && x.file == d.file; });
+ if (stop_ == 2) {
+ unlink(part_path(d).c_str());
+ if (it != view_.downloads.end()) {
+ view_.downloads.erase(it);
+ }
+ } else if (it != view_.downloads.end()) {
+ *it = d;
+ if (d.state == DownloadState::done) {
+ ++view_.saved;
+ view_.note = d.note;
+ }
}
- view_.download_file = name;
- view_.download_result.clear();
- // Room for the file and 1 GiB to spare, so a download never fills a
- // drive (a full /data upsets the system, not only this app).
- std::error_code ec;
- std::filesystem::create_directories(dir, ec);
- if (free >= 0 && free < bytes / 1073741824.0 + 1.0) {
- char text[256];
- std::snprintf(text, sizeof(text), "Not enough space: %s needs %.1f GiB and 1 GiB spare, %s has %.1f GiB free",
- name.c_str(), bytes / 1073741824.0, dir.c_str(), free);
- view_.download_result = text;
- std::printf("ps5lm-app: download %s/%s: %s\n", id.c_str(), name.c_str(), text);
- return;
+ stop_ = 0;
+ save_queue();
+ }
+}
+
+// Several connections at once, each fetching 32 MiB pieces of the file and
+// writing them in place: one connection on the console tops out far below
+// the line's speed. What is done from the start of the file (`resume`) is
+// saved with the queue, so a dropped connection, a pause or a restart costs
+// at most the pieces in flight. The SHA-256 is checked once it is whole.
+bool Market::fetch(Download & d) {
+ constexpr uint64_t kPiece = 32ull << 20;
+ const std::string part = part_path(d);
+ const std::string to = part.substr(0, part.size() - 5);
+ const std::string url = std::string(kHub) + "/" + d.repo + "/resolve/main/" + d.file;
+ std::error_code ec;
+ std::filesystem::create_directories(d.dir, ec);
+ const auto publish = [&](bool save) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ for (auto & x : view_.downloads) {
+ if (x.repo == d.repo && x.file == d.file) {
+ x.state = d.state;
+ x.done = d.done;
+ x.resume = d.resume;
+ x.mbps = d.mbps;
+ x.attempt = d.attempt;
+ x.note = d.note;
+ }
+ }
+ if (save) {
+ save_queue();
}
- view_.download_progress = 0;
- }
- run(downloading_, [this, id, name, sha, bytes, dir] {
- const size_t slash = name.find_last_of('/');
- const std::string to = dir + "/" + name.substr(slash == std::string::npos ? 0 : slash + 1);
- const std::string part = to + ".part";
- // write(), not stdio: on /data stdio managed 18 MB/s, write() 230 MB/s.
- const int out = open(part.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
- sha256_t h;
- sha256_init(&h);
- uint64_t done = 0;
- const auto t0 = std::chrono::steady_clock::now();
- const FetchResult r = https_get(std::string(kHub) + "/" + id + "/resolve/main/" + name, "", [&](const char * p, size_t n) {
- if (out < 0 || write(out, p, n) != (ssize_t) n) {
- return false;
+ };
+ if (d.bytes == 0) {
+ d.state = DownloadState::failed;
+ d.note = "Failed: the repository does not give this file's size";
+ publish(true);
+ return false;
+ }
+ if (d.resume > d.bytes || d.resume > file_size(part)) {
+ d.resume = 0; // not this file, or the partial file is gone
+ }
+ const int fd = open(part.c_str(), O_WRONLY | O_CREAT, 0666);
+ if (fd < 0) {
+ d.state = DownloadState::failed;
+ d.note = "Failed: cannot write to " + d.dir;
+ publish(true);
+ return false;
+ }
+ const uint64_t base = d.resume;
+ const size_t pieces = (size_t) ((d.bytes - base + kPiece - 1) / kPiece);
+ std::vector<uint8_t> state(pieces, 0); // 0 to fetch, 1 in flight, 2 written
+ std::mutex m;
+ std::atomic<uint64_t> received{ base };
+ std::atomic<int> failures{ 0 }; // in a row, across connections
+ std::atomic<int> waiting{ 0 }; // connections waiting to try again
+ std::atomic<bool> fatal{ false };
+ std::string last_error;
+ const auto worker = [&](int id) {
+ for (;;) {
+ size_t k = pieces;
+ {
+ std::lock_guard<std::mutex> lock(m);
+ for (size_t i = 0; i < pieces; ++i) {
+ if (state[i] == 0) {
+ k = i;
+ state[i] = 1;
+ break;
+ }
+ }
}
- sha256_update(&h, (const unsigned char *) p, n);
- done += n;
- const double s = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
- std::lock_guard<std::mutex> lock(mutex_);
- view_.download_progress = bytes ? (float) ((double) done / (double) bytes) : 0.0f;
- view_.download_mbps = s > 0 ? done / 1e6 / s : 0;
- return true;
- });
- bool ok = out >= 0 && fsync(out) == 0;
- if (out >= 0) {
- close(out);
+ if (k == pieces || stop_ != 0 || fatal) {
+ return;
+ }
+ const uint64_t off = base + k * kPiece, len = std::min(kPiece, d.bytes - off);
+ char range[64];
+ std::snprintf(range, sizeof(range), "bytes=%llu-%llu", (unsigned long long) off, (unsigned long long) (off + len - 1));
+ uint64_t got = 0;
+ const FetchResult r = kGet(id, url, range, [&](const char * p, size_t n) {
+ if (stop_ != 0 || got + n > len || pwrite(fd, p, n, (off_t) (off + got)) != (ssize_t) n) {
+ return false;
+ }
+ got += n;
+ received += n;
+ return true;
+ });
+ std::lock_guard<std::mutex> lock(m);
+ if (got == len && r.status == 206) {
+ state[k] = 2;
+ failures = 0;
+ continue;
+ }
+ state[k] = 0; // again, from its start
+ received -= got;
+ if (stop_ != 0) {
+ return;
+ }
+ char text[200];
+ std::snprintf(text, sizeof(text), "%s%s%s", r.status > 0 ? ("HTTP " + std::to_string(r.status)).c_str() : "",
+ r.status > 0 && !r.error.empty() ? ", " : "", r.error.c_str());
+ last_error = text;
+ const int f = ++failures;
+ std::printf("ps5lm-app: download %s: piece at %llu stopped after %llu bytes: %s\n", d.file.c_str(),
+ (unsigned long long) off, (unsigned long long) got, text);
+ // A 4xx other than 408/429 will not get better by asking again.
+ if ((r.status >= 400 && r.status < 500 && r.status != 408 && r.status != 429) || r.status == 200 || f > 20) {
+ fatal = true;
+ return;
+ }
+ const int wait = std::min(60, 2 << std::min(f, 5)); // 4, 8, 16, 32, 60 s
+ ++waiting;
+ m.unlock();
+ for (int s = 0; s < wait * 4 && stop_ == 0; ++s) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(250));
+ }
+ m.lock();
+ --waiting;
}
- unsigned char digest[32];
- sha256_final(&h, digest);
- char hex[65];
- for (int i = 0; i < 32; ++i) {
- std::snprintf(hex + 2 * i, 3, "%02x", digest[i]);
+ };
+ std::vector<std::thread> threads;
+ for (int i = 0; i < kConnections && i < (int) pieces; ++i) {
+ threads.emplace_back(worker, i);
+ }
+ // Progress once a second, the queue saved every ten.
+ auto window_t = std::chrono::steady_clock::now();
+ uint64_t window_bytes = received;
+ for (int tick = 0;; ++tick) {
+ bool running = false;
+ {
+ std::lock_guard<std::mutex> lock(m);
+ size_t prefix = 0;
+ while (prefix < pieces && state[prefix] == 2) {
+ ++prefix;
+ }
+ d.resume = std::min(d.bytes, base + prefix * kPiece);
+ for (uint8_t s : state) {
+ running = running || s != 2;
+ }
+ running = running && !fatal;
+ d.done = received;
+ d.attempt = failures;
+ if (waiting > 0 && waiting >= (int) threads.size()) {
+ d.state = DownloadState::retrying;
+ d.note = "Connection lost (" + last_error + "); trying again, attempt " + std::to_string((int) failures);
+ } else {
+ d.state = DownloadState::running;
+ d.note.clear();
+ }
}
- std::string result;
- if (!ok || r.status != 200 || done != bytes) {
- char text[160];
- std::snprintf(text, sizeof(text), "Failed: HTTP %d, %llu of %llu bytes%s%s", r.status,
- (unsigned long long) done, (unsigned long long) bytes, r.error.empty() ? "" : ", ",
- r.error.c_str());
- result = text;
- } else if (!sha.empty() && sha != hex) {
- result = "Failed: the checksum does not match";
- } else if (std::rename(part.c_str(), to.c_str()) != 0) {
- result = "Failed: could not rename the file";
- } else {
- result = "Saved to " + to;
+ const auto now = std::chrono::steady_clock::now();
+ const double s = std::chrono::duration<double>(now - window_t).count();
+ if (s >= 3.0) {
+ d.mbps = (d.done - window_bytes) / 1e6 / s;
+ window_t = now;
+ window_bytes = d.done;
}
- if (result.rfind("Saved", 0) != 0) {
- unlink(part.c_str());
+ if (!running || stop_ != 0) {
+ break;
}
- std::printf("ps5lm-app: download %s/%s: %s\n", id.c_str(), name.c_str(), result.c_str());
- std::lock_guard<std::mutex> lock(mutex_);
- view_.download_progress = -1;
- view_.download_result = result;
- });
+ publish(tick % 10 == 0);
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ }
+ for (auto & t : threads) {
+ t.join();
+ }
+ fsync(fd);
+ close(fd);
+ d.mbps = 0;
+ if (stop_ != 0 || fatal) {
+ d.state = stop_ == 1 ? DownloadState::paused : DownloadState::failed;
+ d.note = stop_ == 1 ? "Paused" : stop_ == 2 ? "" : "Failed: " + last_error + " \xC2\xB7 Cross tries again";
+ d.done = d.resume; // what a restart keeps
+ publish(true);
+ return false;
+ }
+ // Whole: check it.
+ d.note = "Checking the SHA-256";
+ publish(false);
+ sha256_t h;
+ sha256_init(&h);
+ if (FILE * in = std::fopen(part.c_str(), "rb")) {
+ std::vector<unsigned char> buf(8u << 20);
+ for (size_t n; (n = std::fread(buf.data(), 1, buf.size(), in)) > 0;) {
+ sha256_update(&h, buf.data(), n);
+ }
+ std::fclose(in);
+ }
+ unsigned char digest[32];
+ sha256_final(&h, digest);
+ char hex[65];
+ for (int i = 0; i < 32; ++i) {
+ std::snprintf(hex + 2 * i, 3, "%02x", digest[i]);
+ }
+ if (!d.sha256.empty() && d.sha256 != hex) {
+ unlink(part.c_str());
+ d.resume = d.done = 0;
+ d.state = DownloadState::failed;
+ d.note = "Failed: the checksum does not match; Cross downloads it again";
+ } else if (std::rename(part.c_str(), to.c_str()) != 0) {
+ d.state = DownloadState::failed;
+ d.note = "Failed: could not rename the file";
+ } else {
+ d.state = DownloadState::done;
+ d.note = "Saved to " + to;
+ }
+ std::printf("ps5lm-app: download %s/%s: %s\n", d.repo.c_str(), d.file.c_str(), d.note.c_str());
+ publish(true);
+ return d.state == DownloadState::done;
}
} // namespace ps5lm
diff --git a/ps5/app/market.hpp b/ps5/app/market.hpp
index 13935fd..146c098 100644
--- a/ps5/app/market.hpp
+++ b/ps5/app/market.hpp
@@ -20,7 +20,8 @@ struct MarketFile {
std::string sha256; // from the repository's LFS pointer
uint64_t bytes = 0;
std::string plan; // the planner's line, once its header was read
- int fits = -1; // 1 fits, 0 too big, -1 not planned yet
+ int fits = -1; // 1 fits, 0 too big, -1 not planned yet, -2 could not tell
+ bool checking = false; // its header is being read
};
struct MarketRepo {
@@ -29,24 +30,35 @@ struct MarketRepo {
std::vector<MarketFile> files; // filled when the repository is opened
};
+// One file to download, by name.
+struct MarketJob {
+ std::string repo, file, sha256, dir;
+ uint64_t bytes = 0;
+};
+
+enum class DownloadState : uint8_t { queued, running, retrying, paused, failed, done };
+
+// A queued file. The queue is kept in /data/PS5LM/downloads.json, and the
+// partial file (name.gguf.part) stays on disk, so a download carries on
+// after a dropped connection, a pause or the app restarting.
+struct Download : MarketJob {
+ DownloadState state = DownloadState::queued;
+ uint64_t done = 0; // bytes fetched
+ uint64_t resume = 0; // bytes done from the start of the file, kept across restarts
+ double mbps = 0; // over the last seconds, while it runs
+ int attempt = 0; // retries since the last progress
+ std::string note; // "Saved to …", the error, or why it waits
+};
+
struct MarketView {
std::string query;
bool busy = false; // a search, listing or plan is running
std::string status; // the last error or note, for the screen
std::vector<MarketRepo> repos;
int open = -1; // the repository whose files are listed
- // The download in progress, or the last one.
- std::string download_file;
- float download_progress = -1; // 0..1 while it runs
- double download_mbps = 0;
- std::string download_result; // "Saved to …" or the error
-};
-
-// One file to download, by name: it survives the app restarting (a download
-// asked for after unloading the model is picked up by the new process).
-struct MarketJob {
- std::string repo, file, sha256, dir;
- uint64_t bytes = 0;
+ std::vector<Download> downloads; // the queue, oldest first
+ int saved = 0; // downloads finished since the app started
+ std::string note; // the last download refused or finished, for the Get models page
};
class Market {
@@ -59,17 +71,30 @@ class Market {
void open_repo(int index);
void plan_file(int repo, int file); // reads its header (16 MiB range request)
bool job(int repo, int file, const std::string & dir, MarketJob * out);
- // `free_gib`: room on the drive it goes to, or -1 when unknown (the check is skipped).
- void download(const MarketJob & job, double free_gib);
+
+ // The queue. `free_gib`: room on the drive it goes to, or -1 when unknown
+ // (the check is skipped). False, with the reason in the view's note, when
+ // it does not fit or is queued already.
+ bool enqueue(const MarketJob & job, double free_gib);
+ void pause(int index); // stops it, keeping the partial file
+ void resume(int index); // a paused or failed one goes back in the queue
+ void remove(int index); // cancels it and deletes the partial file; a finished one only leaves the list
+ void load_queue(); // at start: what was queued or running carries on
private:
- // One browse job (search, listing, plan) and one download at a time.
void run(std::atomic<bool> & flag, std::function<void()> job);
+ void worker(); // the download thread: the queue in order, one at a time
+ bool fetch(Download & d); // one download to the end, retrying; false when stopped
+ void save_queue(); // under mutex_
std::mutex mutex_;
MarketView view_;
double budget_gib_ = 0;
std::atomic<bool> browsing_{ false };
- std::atomic<bool> downloading_{ false };
+ struct PlanJob { std::string repo, file; uint64_t bytes = 0; };
+ std::vector<PlanJob> plans_; // fit checks asked for, newest last
+ std::atomic<bool> planning_{ false }; // their thread runs
+ std::atomic<bool> working_{ false }; // the worker thread runs
+ std::atomic<int> stop_{ 0 }; // 1 pause, 2 cancel the running download
};
} // namespace ps5lm
diff --git a/ps5/app/preview_main.cpp b/ps5/app/preview_main.cpp
index cd733e5..a1e2cfa 100644
--- a/ps5/app/preview_main.cpp
+++ b/ps5/app/preview_main.cpp
@@ -215,9 +215,39 @@ int main(int argc, char ** argv) {
f.plan = fplans[i];
mv.repos[0].files.push_back(f);
}
- mv.download_file = "Qwen3.8-27B-UD-IQ2_XXS.gguf";
- mv.download_progress = 0.37f;
- mv.download_mbps = 14.2;
+ {
+ ps5lm::Download d;
+ d.repo = "unsloth/Qwen3.8-27B-GGUF";
+ d.file = "Qwen3.8-27B-UD-IQ2_XXS.gguf";
+ d.dir = "/data/PS5LM/models";
+ d.bytes = (uint64_t) (6.8 * 1073741824.0);
+ d.done = (uint64_t) (2.5 * 1073741824.0);
+ d.state = ps5lm::DownloadState::running;
+ d.mbps = 14.2;
+ mv.downloads.push_back(d);
+ d.file = "gemma-4-12b-it-Q4_K_M.gguf";
+ d.repo = "unsloth/gemma-4-12b-it-GGUF";
+ d.dir = "/mnt/usb0/PS5LM/models";
+ d.bytes = (uint64_t) (7.1 * 1073741824.0);
+ d.done = 0;
+ d.mbps = 0;
+ d.state = ps5lm::DownloadState::queued;
+ mv.downloads.push_back(d);
+ d.file = "Llama-3.2-3B-Instruct-Q4_K_M.gguf";
+ d.repo = "bartowski/Llama-3.2-3B-Instruct-GGUF";
+ d.bytes = 2019377696;
+ d.done = 812000000;
+ d.state = ps5lm::DownloadState::retrying;
+ d.note = "Connection lost (sceHttp2ReadData 0x804101a3); trying again in 12 s, attempt 2";
+ mv.downloads.push_back(d);
+ d.file = "SmolLM2-135M-Instruct-F16.gguf";
+ d.repo = "unsloth/SmolLM2-135M-Instruct-GGUF";
+ d.dir = "/data/PS5LM/models";
+ d.bytes = d.done = 270885952;
+ d.state = ps5lm::DownloadState::done;
+ d.note = "Saved to /data/PS5LM/models/SmolLM2-135M-Instruct-F16.gguf";
+ mv.downloads.push_back(d);
+ }
dash.set_market(mv);
std::vector<unsigned char> pixels((size_t) W * H * 4);
stbi_flip_vertically_on_write(1);
@@ -323,11 +353,20 @@ int main(int argc, char ** argv) {
step(30, press(hui::Action::confirm), false);
step(20, nav(hui::Direction::down), false);
shot("12-market-files");
- mv.download_progress = -1; // nothing downloading, so Cross asks first
dash.set_market(mv);
step(30, press(hui::Action::confirm), false);
shot("13-market-space");
step(30, press(hui::Action::confirm), false);
shot("14-market-confirm");
+ step(20, press(hui::Action::back), false);
+ step(30, press(hui::Action::page_next), false);
+ shot("15-downloads");
+ step(20, nav(hui::Direction::down), false);
+ step(20, nav(hui::Direction::down), false);
+ step(20, press(hui::Action::west), false);
+ shot("16-downloads-cancel");
+ dash.set_busy("Applying the new limits", "Planning every model again for 32k tokens and the q8_0 cache");
+ step(20, press(hui::Action::back), false);
+ shot("17-busy");
return ok ? 0 : 1;
}
diff --git a/ps5/app/version.hpp b/ps5/app/version.hpp
index 4a33fb9..c60081c 100644
--- a/ps5/app/version.hpp
+++ b/ps5/app/version.hpp
@@ -4,4 +4,4 @@
// The app's version, semver. The one place it is set: scripts read it from
// here (scripts/release-app.sh), and git tags are v<this>. Bump it with an
// entry in CHANGELOG.md.
-#define PS5LM_VERSION "0.7.0"
+#define PS5LM_VERSION "0.8.0"
diff --git a/scripts/preview-app-ui.sh b/scripts/preview-app-ui.sh
index d5f9206..8b0f8db 100755
--- a/scripts/preview-app-ui.sh
+++ b/scripts/preview-app-ui.sh
@@ -25,7 +25,9 @@ sources+=("$kit/host/platform_host.cpp" "$root/ps5/app/dashboard.cpp" "$root/ps5
compile() {
local src=$1 o
o="$obj/$(echo "${src#"$root/"}" | tr '/' '_').o"
- if [ ! -f "$o" ] || [ "$src" -nt "$o" ] || [ "$root/ps5/app/dashboard.hpp" -nt "$o" ] || [ "$root/ps5/app/stats.hpp" -nt "$o" ]; then
+ # Any app header newer than the object rebuilds it: a struct changed in
+ # one header and not rebuilt everywhere crashes the preview.
+ if [ ! -f "$o" ] || [ "$src" -nt "$o" ] || [ -n "$(find "$root/ps5/app" -name '*.hpp' -newer "$o" -print -quit)" ]; then
if [[ $src == *.c ]]; then
$cc -std=c11 -O2 -w -I"$kit/src" -c "$src" -o "$o"
else