{"slug": "training-a-tiny-model-for-the-m5stack-cores3", "title": "Training a tiny model for the M5Stack CoreS3", "summary": "A developer built five small generative AI apps that run entirely on an M5Stack CoreS3 (ESP32-S3, 16 MB flash, 8 MB PSRAM) with no cloud, phone or Wi-Fi, using models from 82 KB to 4 MB. The worked example, a recipe writer with 8.2 million parameters stored at 4 bits (4.2 MB total), generates a novel recipe in about 25 seconds at 6-7 tokens per second, with the training code and model published on GitHub and Hugging Face. The developer reports that keeping the architecture and inference code unchanged and focusing effort on data, training options and validation was the right split.", "body_md": "Over the last few weeks I've built five small generative AI apps that run entirely on an M5Stack CoreS3: a recipe writer, a pixel-art sprite maker, a card game inventor, a cocktail maker and a Shakespeare scene writer that types into your computer as a USB keyboard. No cloud, no phone, no Wi-Fi. Each has its own model, from 82 KB to 4 MB, running on the ESP32-S3.\n\nThis article walks through how to train one, using Recipe Maker as the worked example, then gives the exact commands to retrain it yourself and to train a model on a subject of your own. You pick a main ingredient and a kind of dish on the touchscreen, and about 25 seconds later you have a recipe nobody has written before. Everything here is in the repo, [esp32-recipe-maker](https://github.com/justinmclean/esp32-recipe-maker), and the model is on Hugging Face at [jmclean/esp32-recipe-maker](https://huggingface.co/jmclean/esp32-recipe-maker).\n\nThe CoreS3 has an ESP32-S3 at 240 MHz, 16 MB of flash (slow storage that keeps its contents with the power off) and 8 MB of PSRAM (faster working memory). That is not much for a language model.\n\nA model is a large set of numbers, its parameters (or weights), learnt in training. Writing text means doing arithmetic with all of them for every word piece it writes. [slvDev/esp32-ai](https://github.com/slvDev/esp32-ai) has a clever layout for a small chip: most of the parameters are lookup tables, called embeddings, where the model only reads the few rows it needs for the current word piece. Those can stay in flash and be read in place. Only a small core, the transformer that does the real computing, needs the full arithmetic on every step, and that sits in PSRAM.\n\nThe recipe model has 8.2 million parameters: 6.3 million in lookup tables for each of its layers (per-layer embeddings), 0.8 million in the table of word pieces (the token embedding), and 1.1 million in the core (6 layers, each 96 numbers wide). Each parameter is stored in 4 bits rather than the usual 32, so the whole model is 4.2 MB, and the core is expanded to 8 bits in PSRAM to run. It writes 6 to 7 tokens a second.\n\nA token is the unit the model reads and writes: a common word, part of a longer word, or a piece of punctuation. \"pumpkin\" is one token; a rarer word might be two or three.\n\nI didn't change the architecture or the inference code. All my work went into the data, the training options and the checking. That turned out to be the right split.\n\nA tiny model can't follow instructions, but it can learn a shape very reliably. So the first job is to design a fixed text layout that carries both the user's choices and the output:\n\n```\nMain: pumpkin\nDish: soup\nTitle: Roast Pumpkin and Ginger Soup\nIngredients:\n- 1 kg pumpkin, peeled and cubed\n- 1 onion, chopped\nMethod:\n1. Roast the pumpkin at 200C for 25 minutes.\n2. ...\n<|endoftext|>\n```\n\nThe device sends everything up to `Title:` and the model writes the rest. The picks go first so the model learns to follow them. `<|endoftext|>` tells the app when to stop.\n\nDesign this around the screen, not the model. The touch picker means no keyboard. The model can only see 256 tokens at a time (its context), prompt included, so recipes have to be short, which suits a 320 x 240 display anyway.\n\nThe model only sees about 20 to 80 million tokens in training, so you don't need a huge dataset, but you do need enough examples for every combination of picks.\n\nThere are two ways to get it:\n\nThere's a third way, which Card Maker uses: write a program that makes the data. Its engine plays random rule sets against itself and keeps the good ones. No licence questions at all.\n\nWhatever you choose, convert or generate 200 first and read 30 by hand before doing the rest.\n\nRecipeNLG is American. I wanted Australian recipes: metric units and standard can sizes, Celsius, Australian names (capsicum, coriander, spring onions, thickened cream) and Australian spelling. The converter, `training/convert_recipenlg.py`, uses only the standard library and does all of that, and also files each recipe under one of 14 mains and 12 kinds of dish by keyword matching.\n\nMost of the data didn't survive:\n\n| Dropped because | Share | \n|---|---|\n| From cookbooks.com or kraftrecipes.com | 42% | \n| No main ingredient from the picker | 29% | \n| Too long for the 256-token window | 9% | \n| No proper method, or more than 10 steps | 6% | \n| Built on US convenience products (cake mixes, cream soups in salads) | 5% | \n| Other checks (all caps, footnotes, adverts, huge batches) | 1% | \n| **Kept** | **9%** | \n\nThat still left 191,930 recipes, about 35 million training tokens.\n\nThree habits made this manageable:\n\n`test_converter.py`. The build script runs the tests first and stops if anything regresses.`audit_data.py` lists anything that still looks American, for a person to read. It runs on the CPU while the GPU trains, so it never holds anything up.`check_data.py` counts anything the filters should have removed. It should be zero.\nA converter run also writes a table of how many recipes there are for every main and dish pair. Pairs with fewer than 50 are too thin to learn from: the model ignores the pick or copies one recipe. The app greys those out. Chocolate soup has no recipes, which is probably for the best.\n\nGenerate the app's picker from this table (`tools/make_picks_h.py`) so the device and the data can't drift apart.\n\nThe model works on numbers, not letters, so the text has to be cut into tokens and each token given a number. The tokeniser does that. It is learnt from the data itself: byte-level BPE (byte pair encoding) starts from single characters and keeps merging the pairs that appear together most often, so frequent words like \"simmer\" end up as a single token and rare ones are built from pieces.\n\n`prepare_recipes.py` learns the tokeniser, turns every recipe into token numbers, and splits them into two files: `train.bin`, which the model learns from, and `val.bin`, a small validation set of recipes it never trains on. Checking the model on recipes it has never seen tells you whether it has learnt how recipes go in general, or has just memorised the ones it was shown. A few things matter here:\n\n`pumpkin`, `garlic`, `simmer`) come out as one or two tokens. The cocktail model went further, with 2,048 tokens learnt from the drinks, so Chartreuse and Angostura are one token each.`vocab.h`). If a data rebuild learnt a new tokeniser, the numbers would mean different words and the device would print nonsense. Later rebuilds reuse the published tokeniser so the numbers still match.\nTraining runs on a Mac with PyTorch's `mps` backend. The final model took about 80 minutes on an M3 MacBook; this size of model needs well under 4 GB.\n\n```\nESP32AI_DATA=data/recipes PYTHONPATH=src .venv/bin/python research/tinystories/train.py \\\n    --arm ple --vocab 8192 --d-model 96 --n-layers 6 --ple-dim 128 \\\n    --target-core 1100000 --batch-size 16 --seq-len 256 --steps 20000 \\\n    --eval-every 1000 --tag recipes\n```\n\nWhat the settings mean:\n\n`--arm ple`: the per-layer-embedding layout described above.`--d-model 96 --n-layers 6 --ple-dim 128 --target-core 1100000`: the model's size. Each layer is 96 numbers wide, there are 6 layers, each layer's lookup table is 128 wide, and the core is sized to about 1.1 million parameters.`--vocab 8192`: must match the tokeniser.`--batch-size 16 --seq-len 256`: each training step looks at 16 pieces of text, 256 tokens each, about 4,000 tokens.`--steps 20000`: how many training steps. 20,000 steps of 4,000 tokens is 82 million tokens, so the model sees the 35 million tokens of recipes a bit over twice.`--eval-every 1000`: check the validation set every 1,000 steps.\nEach step, the model guesses every next token in the batch, the trainer measures how wrong the guesses were (the loss), and it nudges every parameter slightly in the direction that makes the guesses better. Training is that, 20,000 times.\n\nStart with a 500-step run to time it. Mine took 84 seconds, so 5,000 steps was about 12 minutes: short enough to try an idea and look at the result in the same sitting.\n\nRun times grew as the model did. All of these are on the same M3 MacBook:\n\n| Runs | Steps | Time each | \n|---|---|---|\n| First timing run | 500 | 84 seconds | \n| Early runs, trying data changes | 5,000 | 11 to 13 minutes | \n| With the penalties, then the bigger core | 10,000 | 23 to 39 minutes | \n| Final model | 20,000 | 81 minutes | \n\nThe penalties added a few minutes a run, and doubling the core took a 10,000-step run to 39 minutes. Most of the iterating happened at 10,000 steps, where one idea took about half an hour to test.\n\nOne practical warning: don't run two GPU training jobs at once. I tried two and it crashed the Mac. The queue scripts now wait for the GPU to be free.\n\nThe trainer reports a number called the loss: roughly, how surprised the model is by the real next token, averaged over the text. Lower is better. The validation loss is the same measure on the held-out validation recipes, so it shows how well the model does on recipes it hasn't seen.\n\nValidation loss is a poor guide once the data changes. My first full run had a validation loss of 1.81. The final model, which is much better, has 1.965. In between the tokeniser changed, the data got cleaner and harder to predict, and extra penalties were added, so the numbers across versions aren't comparable.\n\nLoss is still useful within one dataset. For Bard Lite it decided when to stop training (see below).\n\nWhat I needed to know was whether the recipes were right, so I wrote a test for that. `pick_test.py` writes 20 recipes for each of 13 picks covering every kind of dish, at the device's temperature, and counts:\n\nIt runs at the device's temperature of 0.7, because temperature changes the results a lot (see What temperature does, in the section on training your own model).\n\nEach new model was tested against the one on the device, side by side. Every decision after this point came from that test.\n\nI trained 17 recipe models in under a day. The changes that helped, in order:\n\n`esp32-ai.patch`: one against an ingredient line using ingredient words already listed above it (units and numbers are allowed, as real lists repeat those), one against a method step naming an ingredient that isn't in the list, and one against repeating a word within a list inside a method step (\"salt, pepper and salt\"). Each has a weight, how hard it pushes compared with normal training; the final weights are 3, 3 and 1.\nAn early 5,000-step model put the main ingredient in the list 140 times in 160. The final model:\n\n|  | Recipes | \n|---|---|\n| Layout right | 252 of 260 | \n| Main ingredient in the list | 240 of 260 (92%) | \n| Method uses an ingredient the list lacks | 13 of 260 (5%) | \n| Ingredient listed twice | 13 of 260 (5%) | \n\nFor comparison, 10.7% of real recipes have a method step naming something not in the list, by the same count. The weakest pick is mushroom salad, where the list often leaves out the mushrooms.\n\n`model.bin`, esp32-ai's device format. This rounds every parameter to 4 bits (quantisation), so the model is an eighth of the size. Rounding costs a little accuracy; testing the exported model, as below, shows whether that matters.`model` partition, then the app. The flash is divided into partitions, fixed areas for the app, settings and data. The model goes in once (it's 4 MB, so it's slow to write); after that you can reflash the app as often as you like without touching it:\n\n```\npio run -e m5stack-cores3 -t upload_model\npio run -e m5stack-cores3 -t upload\n```\n\nThe apps share one partition layout, and each model starts at its own address (offset) in the `model` partition: the recipe model at 0x190000, Bard Lite's at 0xC00000. Flashing one model doesn't overwrite another, so several can be on one CoreS3 at once.\n\nBefore flashing anything, I test with `host/recipe.c`. It loads the same `model.bin` and runs the same 8-bit arithmetic and sampling as the device, and only needs a C compiler. That is also how the pick test's numbers can be trusted to match what the device writes.\n\nThe repo has the device model, the full-precision weights for fine-tuning, the scripts to rebuild the data and retrain from scratch, and a model card. The model licence follows the data: RecipeNLG is non-commercial, so the model is CC BY-NC 4.0, while the code is MIT. The card also says plainly that the recipes are made up by a tiny model, so check quantities, cooking times and temperatures before you cook one.\n\nEverything below was run on fresh clones on an M3 MacBook Pro (8 cores), and the times are from that run.\n\nYou need:\n\n`hf`);` esp32s3-headless` build instead, over serial.\n\n```\ngit clone https://github.com/slvDev/esp32-ai.git ~/esp32-ai\ngit clone https://github.com/justinmclean/esp32-recipe-maker.git ~/esp32-recipe-maker\ncd ~/esp32-ai && git checkout 52ebcbb && git apply ~/esp32-recipe-maker/training/esp32-ai.patch && uv sync\n```\n\nThe patch adds the training options this needs: another data folder, the three penalties, starting from saved weights and CPU training. `git status` should show only `research/tinystories/train.py` changed.\n\n```\ncd ~/esp32-recipe-maker\nhf download SandhyaKilari/RecipeNLG_dataset RecipeNLG_dataset.csv --repo-type dataset --local-dir data\ntraining/prepare_data.sh\n```\n\nThe download is 2.2 GB. The build took 8.5 minutes, using every core. It runs the converter's tests first, converts and filters 2.2 million recipes, sorts the ingredient lists, tokenises everything with the published tokeniser and then counts anything that should have been removed. The end of the output should look like this, with every count at zero except the cream soups:\n\n```\ntrain 34,903,013 tokens / val 165,909 tokens\n191,924 recipes\n  double numbered steps: 0\n  brand marks: 0\n  Fahrenheit: 0\n  ...\n  cream soups (allowed): 6637, in salads (should be 0): 0\nSTEPS=500 training/train.sh\n```\n\nThis trains for 500 steps (2 minutes), exports the model to `firmware/model/model.bin` and runs the pick test (2 more minutes). It overwrites the published model in your clone: `git checkout firmware/model` puts it back.\n\nDon't expect a usable model from 500 steps. Mine put the main ingredient in the list 15 times in 260 and listed an ingredient twice in 178. Run it on the computer to see:\n\n```\ncc -O2 -o recipe host/recipe.c -lm && ./recipe pumpkin soup\n```\n\nI asked for pumpkin soup and got \"Pork Chops With Mushroom and Garlic And Pumpkin\", with three cups of rice wine, half a cup of mayonnaise, water listed three times and a method that ends in the microwave. It has the layout and the right sort of words, and nothing more. That is what 500 steps is for: proving that every stage runs before you spend 80 minutes.\n\n```\ntraining/train.sh\n```\n\n20,000 steps, about 80 minutes. The pick test at the end should come out close to the published model: about 250 of 260 with the right layout and 240 with the main ingredient in the list. Runs differ a little from one to the next.\n\nThis replaces whatever is on the board, partition table included.\n\n```\ncd ~/esp32-recipe-maker/firmware\npio run -e m5stack-cores3 -t upload_model\npio run -e m5stack-cores3 -t upload\n```\n\nThe model took 60 seconds to write and the app 53 seconds to build and flash. Pick on the touchscreen, or open the serial monitor (`pio device monitor`) and type `pumpkin soup`. Mine wrote 130 tokens in 20.1 seconds, 6.5 tokens a second.\n\nRecipes need a big conversion job. The general route is much shorter, and you can try all of it in a few minutes. This example teaches a model to write made-up weather forecasts for Australian cities.\n\nEach example uses the same fixed layout and ends with `<|endoftext|>`:\n\n```\nCity: Hobart\nSeason: Winter\nDay: Sunday\nForecast: Rain at times. Top 10, low -1. Calm.\n<|endoftext|>\n```\n\nHere a short program writes them, with simple rules: each city has a usual top for summer and winter, autumn and spring are halfway between, each city has its own chance of rain, the top varies by up to 4 degrees either way, and the low is 8 to 14 degrees under the top.\n\n``` python\nimport random\n\n# City: (usual top in summer, usual top in winter, chance of rain)\nCITIES = {\n    \"Darwin\": (33, 31, 0.5), \"Cairns\": (31, 26, 0.45), \"Brisbane\": (29, 21, 0.3),\n    \"Sydney\": (26, 17, 0.3), \"Canberra\": (28, 12, 0.25), \"Melbourne\": (25, 14, 0.35),\n    \"Hobart\": (22, 12, 0.4), \"Adelaide\": (29, 15, 0.25), \"Perth\": (31, 18, 0.25),\n    \"Alice Springs\": (36, 20, 0.1),\n}\nSEASONS = [\"Summer\", \"Autumn\", \"Winter\", \"Spring\"]\nDAYS = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\nDRY = [\"Sunny.\", \"Mostly sunny.\", \"Partly cloudy.\", \"Clear skies.\"]\nWET = [\"Showers.\", \"A shower or two.\", \"Rain at times.\", \"Possible storm.\"]\nWINDS = [\"Light winds.\", \"Winds becoming gusty.\", \"Fresh southerly change late.\", \"Calm.\"]\n\ndef usual_top(city, season):\n    \"\"\"Summer and winter as listed; autumn and spring halfway between.\"\"\"\n    summer, winter, _ = CITIES[city]\n    return {\"Summer\": summer, \"Winter\": winter}.get(season, (summer + winter) // 2)\n\nif __name__ == \"__main__\":\n    rng = random.Random(1)\n    with open(\"forecasts.txt\", \"w\") as f:\n        for _ in range(50000):\n            city = rng.choice(list(CITIES))\n            season = rng.choice(SEASONS)\n            top = usual_top(city, season) + rng.randint(-4, 4)\n            low = top - rng.randint(8, 14)\n            sky = rng.choice(WET if rng.random() < CITIES[city][2] else DRY)\n            f.write(f\"City: {city}\\nSeason: {season}\\nDay: {rng.choice(DAYS)}\\n\"\n                    f\"Forecast: {sky} Top {top}, low {low}. {rng.choice(WINDS)}\\n<|endoftext|>\\n\")\n```\n\nSave it as `make_forecasts.py` in a new `~/forecasts` folder and run it there:\n\n```\nmkdir -p ~/forecasts && cd ~/forecasts && python3 make_forecasts.py\n```\n\nFor your own subject, replace this with your own data in the same shape: one example per document, a fixed layout, `<|endoftext|>` at the end of each.\n\n```\ncd ~/esp32-ai\n.venv/bin/python ~/esp32-recipe-maker/training/prepare_recipes.py ~/forecasts/forecasts.txt data/forecasts --vocab 1024\n```\n\nAbout a second. It says \"recipes\" and checks a few recipe words at the end; ignore those. A vocabulary of 1,024 is a ceiling: forecasts use so few words that the tokeniser stopped at 505 tokens, which is fine.\n\n```\nESP32AI_DATA=data/forecasts PYTHONPATH=src .venv/bin/python research/tinystories/train.py --arm ple --vocab 1024 --d-model 96 --n-layers 6 --ple-dim 128 --target-core 560000 --batch-size 16 --seq-len 256 --steps 500 --eval-every 100 --tag forecasts\n```\n\nAbout 70 seconds. Validation loss falls from 6.97 to 0.49. A layout this simple is learnt in about 200 steps.\n\n```\nPYTHONPATH=src .venv/bin/python -m research.tinystories.sample --run runs/ple-forecasts-s0.pt --tokenizer data/forecasts/vocab-1024/tokenizer.json --prompt \"$(printf 'City: Darwin\\nSeason: Winter\\nDay: Monday\\nForecast:')\" --samples 3 --tokens 25\n```\n\nRun it as a module (`-m`), as shown; running `sample.py` as a script fails with an import error. It doesn't stop at `<|endoftext|>`, so each sample runs on into the start of another forecast. Mine gave Darwin winter tops of 29 to 35; the same prompt for Hobart gave 12 to 16.\n\n```\nPYTHONPATH=src .venv/bin/python -m research.tinystories.export ple-forecasts-s0 --tokenizer data/forecasts/vocab-1024/tokenizer.json\ncp artifacts/tinystories/model.bin artifacts/tinystories/tokenizer.json ~/forecasts/\n```\n\nThat gives a 0.75 MB `model.bin`, which the `cp` above copies to `~/forecasts`. The exporter always writes to `artifacts/tinystories/`, whatever model you export, so the next export (for example `training/train.sh` for Recipe Maker) replaces these files. Keep your own copy somewhere else.\n\nTo run it the way the device would, use `host/run.c` from the Recipe Maker repo. It is `host/recipe.c` cut down to take the prompt as token ids, so it works for any subject. It needs `vocab.h` regenerated from your tokeniser:\n\n```\ncd ~/esp32-recipe-maker && ~/esp32-ai/.venv/bin/python tools/make_vocab_h.py ~/forecasts/tokenizer.json && cc -O2 -o run host/run.c -lm\npython\n./run -m ~/forecasts/model.bin -n 3 $(~/esp32-ai/.venv/bin/python -c 'import sys; from tokenizers import Tokenizer; print(*Tokenizer.from_file(sys.argv[1]).encode(sys.argv[2]).ids)' ~/forecasts/tokenizer.json \"$(printf 'City: Hobart\\nSeason: Winter\\nDay: Sunday\\nForecast:')\")\n```\n\nThis stops at `<|endoftext|>`, as the device does. Run `git checkout firmware/src/vocab.h` afterwards to put Recipe Maker's back.\n\nReading samples only tells you so much. Because a program made this data, every forecast can be checked against the rules that made it. I generated 1,000 forecasts, 25 for each city and season, at the device's temperature of 0.7. A short script read each one and checked it:\n\n| Rule | Forecasts that follow it | \n|---|---|\n| Layout right | 1,000 of 1,000 | \n| Top within 4 degrees of that city's usual for the season | 908 | \n| Low 8 to 14 degrees under the top | 884 | \n| Sky and wind from the generator's lists | 1,000 | \n\nNot bad for about a minute of training. Then I counted how often each city got rain. Darwin and Hobart came out right, but Adelaide, Perth and Alice Springs got rain about half as often as they should.\n\nThat isn't the model getting rain wrong. It is the sampling temperature. The model gives a probability for every possible next token, and the temperature reshapes those probabilities before one is picked. At 1.0 they are used as the model learnt them. Below 1.0 the likelier choices get likelier still, and above 1.0 the unlikely ones get more of a chance.\n\nSo when the model has learnt that Adelaide is dry 75% of the time, sampling at 0.7 pushes that higher still and rain mostly disappears. At 1.0 most cities came within a few points of their real rate. Perth overshot to 39%; with 100 forecasts a city, some of that is just chance:\n\n| City | Chance of rain in the data | Model at 0.7 | Model at 1.0 | \n|---|---|---|---|\n| Darwin | 50% | 51% | 51% | \n| Sydney | 30% | 22% | 38% | \n| Adelaide | 25% | 11% | 29% | \n| Perth | 25% | 12% | 39% | \n| Alice Springs | 10% | 5% | 12% | \n\nThe cost of 1.0 is more mistakes: tops within range fell from 908 to 791, and lows from 884 to 812.\n\nPartly. I trained the same model for 2,000 steps instead of 500 (3 minutes 47 seconds) and scored it the same way:\n\n|  | 500 steps | 2,000 steps | \n|---|---|---|\n| Top within 4 degrees, at 0.7 | 908 | 998 | \n| Low 8 to 14 under the top, at 0.7 | 884 | 996 | \n| Top within 4 degrees, at 1.0 | 791 | 981 | \n| Adelaide rain at 0.7 (should be 25%) | 11% | 12% | \n| Adelaide rain at 1.0 | 29% | 24% | \n| Perth rain at 1.0 (should be 25%) | 39% | 23% | \n\nThe temperatures are now nearly perfect, and at 1.0 the rain rates are close to the data, with Perth's overshoot gone. But at 0.7 the dry cities are still too dry: Adelaide gets rain 12% of the time, Sydney 17% instead of 30%, Alice Springs 4% instead of 10%.\n\nThat is the useful lesson. More training makes the model's probabilities more accurate. It can't undo what the sampling temperature does to them afterwards, because that happens in the app, not in the model. If the app needs the real odds, sample at 1.0 and train long enough that 1.0 doesn't bring mistakes with it.\n\nIt is the same trade-off in every app. Recipe Maker samples at 0.7 because a recipe with an odd ingredient is worse than a predictable one, and that is also why recipes drift towards the commonest ingredients. Bard Lite samples at 0.8, where a bit of variety matters more. Whichever you choose, run your tests at the temperature the device uses, or the numbers won't match what people see.\n\nStart from Recipe Maker's firmware. Copy in your `model.bin` and `vocab.h`, change the prompt the app builds (Recipe Maker's prompts are token ids in `firmware/src/picks.h`, made by `tools/make_picks_h.py`) and change the screens to suit. A small model like this one can sit at its own offset in the `model` partition next to the others.\n\nThe other apps follow the same ten steps. What changes is what a token is and where the data comes from:\n\nAll five projects are open source, with versions that run on a computer and builds for other ESP32-S3 boards with PSRAM:", "url": "https://wpnews.pro/news/training-a-tiny-model-for-the-m5stack-cores3", "canonical_source": "https://dev.to/justin_mclean_1dd355c2931/training-a-tiny-model-for-the-m5stack-cores3-4849", "published_at": "2026-12-03 02:08:04+00:00", "updated_at": "2026-12-03 02:17:59.935763+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "large-language-models", "generative-ai", "ai-tools"], "entities": ["M5Stack CoreS3", "ESP32-S3", "RecipeNLG", "Hugging Face", "GitHub", "slvDev/esp32-ai"], "also_reported_by": [], "takeaway": "A 4.2 MB, 4-bit 8.2M-parameter model runs on an ESP32-S3 at 6-7 tokens per second by keeping per-layer embedding lookup tables in flash and only the 1.1M-parameter transformer core in PSRAM, so effort should go into a fixed prompt/output layout and data coverage rather than architecture changes.", "recommendation": {"advice": "Keep embedding lookup tables in flash and expand only the small transformer core to 8 bits in PSRAM when running a tiny LLM on an ESP32-S3, and design a fixed text layout around the device's screen and 256-token context.", "playbook": "inference-serving", "playbook_url": "https://wpnews.pro/playbooks/inference-serving"}, "alternates": {"html": "https://wpnews.pro/news/training-a-tiny-model-for-the-m5stack-cores3", "markdown": "https://wpnews.pro/news/training-a-tiny-model-for-the-m5stack-cores3.md", "text": "https://wpnews.pro/news/training-a-tiny-model-for-the-m5stack-cores3.txt", "jsonld": "https://wpnews.pro/news/training-a-tiny-model-for-the-m5stack-cores3.jsonld"}}