Laya Tetris example
A Flutter app in which a Laya decision model plays real-time Tetris through DecisionEngine, with first-launch model downloads and a published fine-tuned head.
On this page
Path: example/laya_tetris · Platforms: macOS 14.0+, iOS 16.4+, Android 10+
(API 29), Web · First-run download: laya-Q8_0.gguf (421 MB),
laya-head.safetensors (106 MB) and laya-head-tetris.safetensors
(106 MB)
A Flutter app in which a Laya decision model plays real-time Tetris while gravity keeps running. Live demo: https://leehack-flutter-laya-tetris.static.hf.space
Run#
cd example/laya_tetris
flutter pub get
flutter run -d macos # or an iOS or Android device
Variants, from example/laya_tetris:
# Web: fetch the pinned bridge assets, then run
WEBGPU_BRIDGE_OUT_DIR="$PWD/web/webgpu_bridge" \
../../scripts/fetch_webgpu_bridge_assets.sh
flutter run -d chrome
# Headless games from local model files, no downloads
dart run bin/bench.dart --model laya-Q8_0.gguf --head laya-head.safetensors \
--tuned-head laya-head-tetris.safetensors
# Use your own tuned head
flutter run -d macos --dart-define=LAYA_TUNED_HEAD_URL=<url>
The app caches the downloads in a laya/ folder and reuses them on later
launches. A Web build needs a cross-origin isolated page.
What it demonstrates#
-
One
LlamaEngineholding the backbone GGUF, shared by twoDecisionEngines: the base head and a Tetris-tuned head (Decision models). -
First-launch downloads with progress through
loadModelSourcefor the backbone andmodelDownloadManager.ensureModelfor the heads (Downloads and cache). -
Yes/no and
choicequestions sent as onesystemOneBatchcall per piece, or per knockout round, while the llama.cpp worker isolate does the work (Batches). -
A typed
ChoiceKey.ofover the candidate placements, read back withanswerOf(Choice values). - Switching GPU and CPU, backbones and thread counts at runtime by disposing the engine and loading a new one (Backend selection).
- The same app on the llama.cpp WebGPU bridge (Decision models: Web).
Test#
cd example/laya_tetris
flutter test
LAYA_MODEL_DIR=<folder> flutter test test/laya_models_local_test.dart also
loads the real backbone and base head from <folder>.
Full options: the players, candidate modes, tuned-head lookup order, Web
serving, headless benchmark flags and measured results are in the
example README;
fine-tuning the head is in
training/README.md.