Skip to content

Latest commit

 

History

History

android

Folders and files

README.md

BigMoeOnEdge for Android

The phone app: chat with a mixture-of-experts model larger than the phone's memory, streamed from storage, and hand the phone's hardware to any OpenAI-compatible client on the network.

It is a client of bmoe-server, the same engine process the desktop runs (docs/application-framework.md). The APK carries the server as libbmoe-server.so; a foreground service starts it on loopback with the app's data directory, and its screens (Chat, Models, Plan, Settings, and Metrics from Settings) speak its HTTP API (docs/server-api.md), exactly as the web UI does on a laptop. A process of its own is the crash boundary: a driver that ends the engine does not end the app.

Nothing about a prompt or an answer leaves the phone unless Serve on the network is on.

The app still needs the network permission, offline too: Android ties every IP socket to it, loopback included, so the app cannot reach its own engine without it. Being offline is fine (the loopback interface is always there, airplane mode included); being denied the network is not. Stock Android grants it at install and nobody can revoke it, but GrapheneOS's per-app Network toggle and firewall apps can. The app then says so in the status line, with a button to its system settings, and a download fails with the same reason instead of retrying; a model can still be imported from a file.

Install

Each release carries app-dev-release.apk, signed with the project's stable key, so each version installs over the previous one. Download it from the release page and open it; Android asks once to allow installs from the browser. app-dev-debug.apk, on the same page, is a debug build signed with another key: it cannot update the release one. Settings → Updates checks for a newer release when you press it and opens its page.

Build

  1. Cross-compile and stage the engine binaries (needs the Android NDK):

    pwsh ../../scripts/build-android.ps1

    This fills app/src/main/jniLibs/arm64-v8a/ with libbmoe-server.so, the engine the app starts as a child process, and the libllama/libggml/libmtmd shared libraries it links. libbmoe-cli.so is still staged beside them, but the app does not start it.

    The release build adds the Hexagon, Vulkan and OpenCL backends. It runs inside upstream's Snapdragon toolchain container (it carries the Hexagon SDK; scripts/android-gpu-deps.sh fetches what Vulkan and OpenCL need), then stages the same way:

    docker run --rm -v <repo>:/workspace ghcr.io/snapdragon-toolchain/arm64-android:v0.7 \
        bash /workspace/scripts/build-hexagon-android.sh
    powershell -File ../../scripts/stage-hexagon-jnilibs.ps1

    The release APK is built this way by CI, with a skel for every NPU generation the backend supports (v73 to v81) and with both GPU backends, so one APK fits every phone and the planner measures whichever devices the phone has. A local APK built with build-android.ps1 has the CPU alone.

  2. Build and install the APK. Open this folder in Android Studio, or use the committed Gradle wrapper directly. The app has two distribution flavors (see below); build the one you want:

    ./gradlew assembleDevDebug
    adb install app/build/outputs/apk/dev/debug/app-dev-debug.apk

    The app's pure-Kotlin rules (the event-stream parser, the chat protocol, the parameter table, the settings form, the catalog status, the merged model list, the plan's figures, the context warning, the transcript the conversation events build, Answer again, the conversations' JSON shapes and the one-time move of the conversations the app used to keep) have JVM unit tests under app/src/test; CI runs them, and so does ./gradlew testDevDebugUnitTest.

    Published sideload builds are signed with a stable key instead, so an update installs over the previous one rather than being refused. That needs a keystore.properties next to app/ (gitignored); without it, builds fall back to debug signing. The APKs attached to a GitHub release are built by the release-apk workflow from a clean checkout of the tag.

Flavors

Two build flavors differ only in how a model reaches the device:

  • dev — sideloaded (this is what CI attaches to releases). Keeps all-files access, so it can also read a model adb-pushed to shared storage. Application id ….example.dev.
  • play — Play-Store-compliant. No broad storage permission: models come only through the in-app downloader or the file picker. ./gradlew assemblePlayDebug.

Both declare android:appCategory="game". That is a performance decision rather than a claim about what the app is: vendor layers read the attribute to pick a CPU governor profile, and on the OxygenOS test device it lifted the foreground ceiling from 1.9/1.65 GHz to the hardware maximum of 3.32/3.80 GHz. Decode is the most CPU-hungry thing a phone does outside a game. The effect is the vendor's, not Android's, so treat any figure as a per-device measurement.

Getting a model onto the device

The Models screen is one list, Your models: what the engine sees and what the catalog offers, merged by file, so a model the catalog downloaded is one row (docs/screens.md, "Models"). Each row has one state and one action for it: Available (Download), Downloading (progress and Cancel), Partly downloaded (Resume, Delete partial), On this device (Load), Loaded (Reload, Unload, Go to Chat), Shards missing (Download, where an entry has the rest). Delete removes a model's files, a split set as a unit, after asking (the server deletes in its models directory, the app elsewhere where it may write); Forget takes an entry added from a repository or a link off the list and leaves its files. Catalog entries with nothing on the phone sit at the bottom as suggestions, and files that are not models (a projector, a draft head, by their headers) are listed apart with no Load. With nothing on the phone the screen is three steps (find, check it fits, download then load).

First run. When the first listing of a launch finds no model on the phone and none coming, the app opens on Get started instead of an empty Chat (the web UI's first run): the phone's memory and processor threads, then three steps whose number follows the model's state. Pick a model: every catalog model, the smallest first, the one picked checked by the server before its download (POST /api/models/inspect: one plain sentence, in the server's colour), and Download (or Resume). Download: progress, the time left over a 20 s window ("about 12 min left · 8.4 MB/s"), and Pause; a paused download stays on this step, with Resume and Pick another model. Start: the model loads by itself when the download ends, and the conversation opens once the engine reports it ready, with three questions to try. Under it: pick a gguf already on the phone, Models, or Skip for now.

The list covers the engine's own directory (the app's internal storage, where in-app downloads and imports land) and the other places a model can sit on the phone, which the app hands the server at launch (--scan-dir: the app's external files directory, and on the dev flavor /data/local/tmp/bmoe and Downloads), each with the folders directly inside it; Where models live, at the foot of the screen, names them. The server groups split sets, reads each model's architecture, says whether this build streams it and whether the file is a model at all; the app reads no gguf itself. Nothing below needs a storage permission except the last option.

  1. Built-in catalog (both flavors): six models from 5 GB to 300 GB, a small dense one that runs whole in memory up to MoE models whose experts stream, one tap each. The catalog is the project's one data file, catalog/models.json, shipped in the APK and read by the server; the app does the transfers itself (a phone has no curl for the server to run), in a foreground worker that survives the app being killed and resumes an interrupted transfer. Its notification shows the progress as the row does. A file whose catalog row names a sha256 is checked against it before it becomes the model; a mismatch deletes the download and says so. An entry whose file name is not a bare file name is not offered.

  2. From Hugging Face: a model's name, a repository id or its URL, in four steps shown as such: Find, Pick, Check (the server reads the header before any download and answers with a verdict the card shows as its headline, coloured by the server's code), Download (the model becomes a catalog entry and its row in Your models carries the download).

  3. Any other model: paste a direct https link to a gguf, or to any shard of a split set. The server makes it a catalog entry (POST /api/models/url), and the app downloads its files like any entry's, with Resume and one progress bar over the set. The server has no curl on the phone to ask the host for sizes, so they are left unknown and a file counts whole once it is there. Nothing checks the link before the download, so a link to nothing ends at once with the host's answer on its row (a definite 4xx is never retried). A link the server refuses shows its reason. Or pick a .gguf already on the device to import it.

  4. adb push (dev flavor only, needs all-files access, which the dev build requests on Refresh):

    adb push Qwen3-30B-A3B-Q4_K_M.gguf /data/local/tmp/bmoe/   # a real filesystem: O_DIRECT works
    adb push Qwen3-30B-A3B-Q4_K_M.gguf /sdcard/Download/        # emulated: buffered I/O

In-app downloads and imports land on a real f2fs/ext4 volume, so the streamed expert reads use O_DIRECT at full speed; a model read from the emulated external directories falls back to buffered I/O. A download needs free space equal to the model size, with no temporary second copy.

Resume. A download writes <name>.part and renames it once whole, so a stopped one keeps its bytes. A dropped connection is retried on its own with backoff, each attempt continuing from the .part with a Range request; a host that answers a definite 4xx (no such file, a token it wants) ends the download at once, the reason on its row. Whatever stopped it (the retries ran out, you pressed Cancel, or the app or the phone restarted), the row then reads Resume (X of Y GB) with the bytes already on disk, and pressing it continues from there; the free-space check counts only the bytes still to fetch. Delete partial download on the same row is the one action that throws them away (the server deletes the entry's .part files, in its models directory only). These are the desktop web UI's words and behaviour too (docs/server-api.md, "Models"). A link an older build downloaded on its own, with no entry, has no row to resume from, so its Cancel deletes its partial file.

Sharded models (gpt-oss-120b, DeepSeek V4 Flash and V4.1 Flash, Qwen3.8-Flash-Next)

Models above Hugging Face's 50 GB per-file limit ship as several shard files (-00001-of-0000N.gguf). The engine streams a split set natively: the repository listing shows the set as one model by its first shard, the shards download one at a time (each resumable), the row shows one progress bar over the set, and the model list offers the set once, by that first shard, which is the file the engine opens. For adb-pushed models push every shard to the same directory. Mind the space: DeepSeek V4 Flash UD-IQ2_M is ~91 GB on disk, Qwen3.8-Flash-Next UD-IQ3_XXS ~82 GB and the catalog's Q2_K build ~83 GB, and the catalog's DeepSeek V4.1 Flash Q2_K_S ~298 GB.

Qwen3.8-Flash-Next needs Dense weights = pinned (pinned, dma-buf) in Settings. Its dense side is 4.3 GB and every token walks it: with anon the kernel swaps it to zram and single tokens stall for 10-20 s, with mmap it is refaulted from flash every token. Its 51B n-gram table is held back automatically and stays mmap'd whatever the setting. The planner chooses this where it can. The catalog's Q2_K build keeps about as much in memory (4357 MiB by its header), so the same holds.

Loading, and the plan

Load on the Models screen opens the model. With Plan before every load on (the Plan screen; on by default), the engine first measures the phone (storage read rate, what memory it can hold and lock, each compute device in a process of its own) and chooses the streaming settings for that model, then loads. The Plan screen first says which model it is for ("For ": the planned model, else the one a load would open, with Change to Models), then leads with what the plan decided in one sentence, the machine, which device takes the prompt and which the tokens, and three figures: decode speed expected and, after the first answer, measured with the difference; the cache hit rate the plan credited and the one measured; and the memory held against what the process may hold. The app reads the plan when a session opens and when an answer ends, whichever screen is open, so the figures are there when you look. Apply and Measure again sit under them (an error at the top has its own Measure again); Apply lists the settings it changed, each a link to its row in Settings. Then where the memory goes, what each compute device does and why, and the decisions grouped, each with the fact behind it and a link to its setting. Copy diagnostic puts the command and the planner's whole account on the clipboard for a bug report. The screen shows which stage of the measurement is running; a value you set yourself in Settings is never overridden. With nothing loaded and no plan measured, it shows the decisions the settings carry from the last applied plan. A model is unloaded after ten idle minutes to give the phone its memory back; the next message reloads it.

The status line above the navigation bar, on every screen, says in words what the engine is doing (the loaded model's name and "Ready · private, on this phone", never a figure) and shows the running downloads ("Downloading 42%", or "2 downloads 42%"), which lead to Models. With "Serve on the network" on, or once a request was refused for the context, a loaded model whose context is below what a coding agent's first request needs gets a warning under it: the context, the server's recommendation, that a larger context takes memory from the expert cache, a link to the setting that raises it, and a ✕ that dismisses it for that model and context (a refusal brings it back). The same line stays under "Serve on the network" in Settings. A chat refused for a full context offers the same link beside New chat. The number and the setting come from the server (model.ctx_advice).

The chat

The app starts its server with --chat-only: the conversations are held by the engine process (docs/agent.md), not by the app, so an answer goes on while the app is in the background and the same conversations are there for any client of the phone's server, but they are plain chat, with no tools, no workspaces and no tasks. The agent is the desktop's: a small model on a phone is not one. The drawer lists the conversations, newest first, with a mark on one that is being answered; a row's menu renames or deletes it.

  • The status line. At the top of a conversation once it has begun, the logo beside one line of plain words from the engine's and the conversation's state: "Connecting…", "Measuring this phone…", "Loading the model…", "Thinking…", "Writing…", "Reading part of the model from the disk…" (when more than 0.3 of the live token's time is the disk's), "Answered", "Stopped", "No model loaded", "Ready". While the engine works the logo breathes, unless the system's animations are off.
  • The welcome. An empty conversation shows the logo on a sheet over a yellow rule, the same status words under it ("Private: everything stays on this phone." when all is ready), and "What shall we do?".
  • The transcript. Your messages on the right; long-press one to copy it or to edit it and send it again (everything after it is dropped). The model's answers on white sheets, as GitHub-flavoured Markdown (tables bordered and scrolling sideways when wide, drawn by multiplatform-markdown-renderer in the app's tokens; images are not loaded and HTML is not run), its thinking folded above them, with Copy under each and Answer again under the last one, which sends the last question again as it was (the server drops the old answer). Under a finished answer, one quiet line says how it ran, tg 12.4 tok/s · pp 140 tok/s (the writing speed, then the speed the message was read at), live while it is written; tapping it opens each figure with what it measures (Answer speed against what the plan expected; where each token's time went, as whole shares that add up to 100%; Found in memory, as "81 of every 100 parts"; Reading the message; Context used; Guesses kept) and links to the Plan and to Metrics. A notice says, in words, why something did not happen. Stop ends the answer.
  • The composer. The prompt, across the whole sheet, and under it the + and Send, or Stop while an answer is written, as on the web and iOS; the + holds Image and Take a photo, when the loaded model reads images (a projector file beside it; otherwise the two say so, disabled), at most 8 in a message, shown as thumbnails above the prompt until sent and on the message after, and Choose from options (below). With no model loaded the status line says so, and the engine's line above the navigation bar leads to Models.

The conversations earlier versions kept on the phone are handed to the server once, on the first launch that reaches it: each becomes a server conversation with its messages, and the phone's copy is deleted only once the server's answer shows every message arrived (an older server that ignored them keeps nothing and the phone keeps its copy).

The look

"Letterhead", the web UI's language: words on white sheets (6 dp corners, lifted by a soft shadow, no frame) over a cool grey desk, controls with a 10 dp corner, the top bar and the drawer in the ink shell, and one ink primary button per screen (Send, Load, Apply plan). Light and dark follow the system or the setting. The colour values sit in one place, ui/Theme.kt (LightTokens, DarkTokens), mapped onto Material's colour roles. Text is set in Hanken Grotesk (one variable file) and code in JetBrains Mono, both bundled in res/font under the SIL Open Font License; the APK carries Hanken Grotesk's licence from app/licenses/ and the others in THIRD_PARTY_LICENSES. The pixel logo is the one mark that keeps its own style.

Settings

Every engine tunable comes from the engine's parameter table (GET /api/params): the groups, the rows, their bounds and help text. The app names none of them, so a knob added to the engine appears here with no app change, and the same setting means the same thing on the desktop. The page is one card per group, in the table's order, with the group's one line of help; every card starts folded and lists, in the table's order, the rows the table marks for a form (form; a server that does not send it offers its basic rows), the same rows the web UI and the iOS app show. Every value you set, on the form or off it, sits instead in a Set by you card ahead of the groups, with the count in its header and hidden while you set nothing: each row appears once on the page, a reset sends it back to its group, and a link to a value you set opens that card. Below the groups, Advanced settings folds every other parameter the app may set (the devices for the prompt and the answer, the caches, the reads, the experimental and debug rows, marked as such) into the same group cards; only a path, given at launch, stays off the page. Each row carries one chip for where its value came from (default, from the plan, set by you); a value you set can be reset, or, where the plan decided another, replaced with Use plan value. Reset all my values removes yours after asking, leaving what the engine was launched with and the model. A number shows its unit, the name of a special value and the usual range. "Needs reload" marks only a row whose value differs from the loaded model's, and a banner offers the Reload. A link from the Plan screen or the context warning lands on its row.

Serve on the network is the first card on the page, folded like the rest, with its state in its header even when closed: Off, On with the phone's address, or On but not on a network. Switched on, the engine listens on every interface, and the card shows the phone's address on its Wi-Fi or Ethernet network (http://<phone IP>:<port>, ready to copy and kept current when the network changes), the API key (on its own line in blocks of four, masked, with Show, Copy and New key below it), the base URL a client takes, http://<phone IP>:<port>/v1, and a Port field. The port is the server's default (8765) unless the field names another; when another app holds it (a remote-access app often does), the server takes the next free one, the address shows the port it took, and the field says it moved. Any OpenAI-compatible client then uses it with Authorization: Bearer <key>: a laptop's coding agent, Open WebUI, a script. Prompts and answers cross the network unencrypted, as the card says; use it on a network you trust. A coding agent needs a larger Context than a chat: its first request alone is about 10k tokens, so set Context to 16384 or more before pointing one at the phone, at the cost of expert cache (sizing the context); the card shows the context warning with its Raise button. Changing it restarts the engine, and a model that was loaded is loaded again once the engine is back.

The engine requires a key even when it is not shared: on a phone, loopback is reachable by every installed app, and an open server would let any of them read a conversation off the event stream. The app starts it with a random key per launch, written to a file in its private storage that only it can read (--api-key-file, mode 0600, never on the command line), and sends it on every request; shared, the key is the persistent one Settings shows, so a client keeps working across restarts. The app never assumes the port: it starts the server with --port-fallback and --port-file in its private storage, and talks only to the port that file names once the server has bound it (server-api.md); the server binds it exclusively, so no other app can share it. Before it trusts the server there, the app still checks it is the one it started: that server refuses a random key and accepts the launch's. The server is stopped and restarted on a background thread, one step at a time, so a restart never races the old process for the port and a stop never freezes the screen; a stopped server's late exit report changes nothing. The event stream has a watchdog: the server pings every 15 s, and a stream silent for two pings is reconnected.

An Appearance card follows Serve on the network, folded too:

  • Theme: System, Light or Dark (the web UI's three). System follows the phone; the choice applies at once, status and navigation bars included.

The engine cards come next, then a folded This app card with Stop and Start engine, and the Metrics entry, always there, which opens the Metrics screen; back returns to Settings.

The prefill device (prefill-device) is a row like any other, and the planner chooses it: it measures every compute device the build carries (the GPU through Vulkan or OpenCL, a Snapdragon's NPU through Hexagon, all three in the release APK) on the prefill's wide matmul and arms the fastest, for the prefill only; decode stays on the cores. The Plan screen says which it chose and why. Nothing in the app names a device. See ../../docs/npu-prefill.md.

Metrics

The Metrics screen, opened from Settings, has the Record switch (off by default: one per-token CSV file per model loaded while it is on) and shows the live card for the current or last generation (the rate; while it writes, the share of each token's time spent waiting for the disk and what it finds in memory; for the last answer, each token's time split into computing, waiting for the disk, managing the cache and what nothing claims, as whole shares that add up to 100%), then the CSV files: view one, share one, correlate its columns, or compare two on one axis. The chat shows the writing speed under an answer while it streams. The flash term and the threads the CPU figures divide by are the server's (flash_wait_ms, compute_threads, busy_threads), never read from the settings. The fields are documented in ../../docs/telemetry.md and in the screen's glossary, whose settings half is the engine's parameter table: each setting a file was recorded with is shown under the table's label, typed and with its unit, and a run's identity names every setting that changes the reply and is off its default.

Expected numbers

On a phone with UFS 4.x storage and ~12 GB RAM, streaming Qwen3-30B-A3B-Q4_K_M with the expert cache at 4000 MiB, 4 I/O lanes and 4 compute threads, decode settles around 0.55–0.6 s/token (~1.8 tok/s), a model ~1.7× the device RAM, lossless. See ../../docs/benchmark-method.md for the procedure and the cache/thread sweep; ../../README.md has the table across models.

Choose from options

Choose from options, in the + menu beside the prompt, turns it into a question and adds a field for options, one per line. The model picks one without writing an answer: the options are lettered, the whole request is one prefill with no decode (POST /api/decide), and each option comes back with the probability the model put on it (they need not add up to 100%; the rest is the model being unsure). A decision is not a conversation turn: its answer stays on the chat screen until dismissed and is never sent to the server's conversation. The engine side is docs/decide.md.