|
Download README.md from jmclean/esp32-card-maker: direct link, hf CLI and curl.
- Browser
- Download file 5.81 kB
-
https://huggingface.co/jmclean/esp32-card-maker/resolve/main/README.md
- Command line
-
hf download hf://jmclean/esp32-card-maker/README.md
-
curl -L -o README.md https://huggingface.co/jmclean/esp32-card-maker/resolve/main/README.md
5.81 kB
| license: mit | |
| library_name: esp32-ai | |
| pipeline_tag: text-generation | |
| tags: | |
| - esp32 | |
| - esp32-s3 | |
| - microcontroller | |
| - embedded | |
| - edge | |
| - per-layer-embeddings | |
| - int4 | |
| - card-games | |
| - game-design | |
| - procedural-generation | |
| # Model Card for ESP32 Card Maker | |
| A 149,000-parameter transformer that invents rules for new card games for a standard | |
| deck, on an ESP32-S3 microcontroller (M5Stack CoreS3), with nothing off the chip. A rules | |
| engine on the same chip tests each game by self-play and then plays it against you. | |
|  | |
| ## Model Details | |
| ### Model Description | |
| The model writes a rule set as a sequence of tokens, one per rule: the family of game | |
| (shedding, tricks, collecting or capturing), then that family's rules in a fixed order, | |
| for example `family=tricks deck=32 deal=10 trump=spades follow=0 goal=fewest | |
| scoring=win_hand target=1`. Decoding is constrained to the tokens of the next field, so | |
| every rule set it writes is complete. The engine turns the tokens into readable rules and | |
| plays them. | |
| - **Developed by:** Justin McLean | |
| - **Model type:** decoder-only transformer with per-layer embeddings, autoregressive over | |
| rule tokens | |
| - **License:** MIT | |
| - **Inference code:** [slvDev/esp32-ai](https://github.com/slvDev/esp32-ai) (MIT) | |
| ### Model Sources | |
| - **Repository:** https://github.com/justinmclean/esp32-card-maker | |
| ## Uses | |
| ### Direct Use | |
| Inventing two-player card games for a standard deck, to read and play, on an ESP32-S3 | |
| board or a computer (the repository's `host/play.cpp`). The tokens are only meaningful to | |
| the repository's rules engine (`engine/`), which explains and plays them. | |
| ### Out-of-Scope Use | |
| Games with more than two players, or families and rules the engine does not have. The | |
| model does not judge whether a game is any good: always test what it writes with the | |
| engine's self-play test, as the device does. | |
| ## Bias, Risks, and Limitations | |
| - About a third of the rule sets it writes fail the full self-play test, and shedding | |
| games fail most often (see Evaluation). The device tests every rule set and asks for | |
| another when one fails. | |
| - It learned from rule sets a random generator made and the engine kept, so it can only | |
| invent within the engine's rules, and its games are variations of familiar ones. | |
| - "Quality" here means the game ends, is fair to both players and rewards skill, measured | |
| by computer players. Whether a game is fun is not measured. | |
| ### Recommendations | |
| Sample at temperature 1.3, as the device does, and keep only rule sets that pass the | |
| engine's test. | |
| ## How to Get Started with the Model | |
| On a computer, with only a C++ compiler, from the GitHub repository: | |
| ```bash | |
| c++ -std=c++17 -O2 -Iengine host/play.cpp -o play | |
| ``` | |
| ```bash | |
| ./play | |
| ``` | |
| On an M5Stack CoreS3, from the repository's `firmware/` folder: | |
| ```bash | |
| pio run -e m5stack-cores3 -t upload_model | |
| ``` | |
| ```bash | |
| pio run -e m5stack-cores3 -t upload | |
| ``` | |
| ## Files | |
| - `model.bin`: the device model, 4-bit weights (82 KB). Flashed at 0x890000. | |
| - `tokenizer.json`: the 215 rule tokens and each family's field order. | |
| - `card-maker.safetensors`: full-precision weights (0.6 MB), for fine-tuning. The | |
| repository's `training/weights.py` turns them into a checkpoint training can start from. | |
| ## Training Details | |
| ### Training Data | |
| Made by the repository's engine; nothing is downloaded. 18,000 random rule sets were each | |
| tested by self-play: 300 games of random play (the game must end, last 10 to 120 turns, | |
| not favour the first player, not end in too many draws) and 40 games of a Monte Carlo | |
| player with 20 playouts a move against one with 2 (the stronger player must score at | |
| least 60%, so skill matters). The 10,452 that passed were scored for skill, fairness and | |
| game length, and the best half of each family were kept: 5,226 rule sets. Shedding, | |
| which has the fewest, was repeated 4 times so each family has a fair share. | |
| ### Training Procedure | |
| #### Training Hyperparameters | |
| - 3,000 steps, batch 64 x 32 tokens, AdamW, learning rate 1e-3 with 200 warmup steps and | |
| cosine decay | |
| - **Training regime:** fp32, on the CPU | |
| #### Speeds, Sizes, Times | |
| - 148,576 parameters (99,424 in the transformer core); 82 KB on the device at 4 bits | |
| - Small for a generative model: other ESP32 text models on Hugging Face are mostly 1 to 15 MB | |
| - About a minute of training on an Apple M3 MacBook CPU | |
| - 0.2 to 0.5 seconds to write a rule set on an ESP32-S3 at 240 MHz | |
| ## Evaluation | |
| ### Testing Data, Factors & Metrics | |
| 400 rule sets written by the model at temperature 1.3, against 400 from the random | |
| generator, measured two ways: | |
| - **The full self-play test**, the one the training data passed. | |
| - **What the device keeps:** the device runs only the quick checks (100 random games) | |
| to stay fast, so this measures how many rule sets it accepts, and how many of those | |
| pass the skill test. | |
| ### Results | |
| | | Model | Random rules | | |
| |---|---|---| | |
| | Pass the full test | 70% | 50% | | |
| | Device accepts | 95% | 77% | | |
| | Of those, skill matters | 74% | 68% | | |
| By family, of the rule sets the device accepts, skill matters in: | |
| | Family | Model | Random rules | | |
| |---|---|---| | |
| | Shedding | 38% | 28% | | |
| | Tricks | 72% | 65% | | |
| | Collecting | 100% | 100% | | |
| | Capturing | 90% | 68% | | |
| ## Technical Specifications | |
| ### Model Architecture and Objective | |
| 4 transformer layers, width 64, 4 attention heads, SwiGLU feed-forward, RoPE positions, | |
| per-layer embeddings of width 32, output head tied to the token embedding. Trained with | |
| next-token cross-entropy over a 215-token vocabulary (padded to 256), context 32 tokens. | |
| ### Compute Infrastructure | |
| - **Training:** Apple M3 MacBook (PyTorch, CPU) | |
| - **Inference:** ESP32-S3 (M5Stack CoreS3) with 8 MB PSRAM, or any computer | |
| ## Licence | |
| MIT. Trained only on rule sets generated by the repository's own engine. |