{"slug": "nano-lm-studio", "title": "Nano LM Studio", "summary": "NanoLM Studio V4, a local desktop workbench for building small decoder-only language models, has been publicly released by its developer. The Tk-based application integrates document ingestion, ByteLevel BPE tokenization, PyTorch training, interactive generation, and attention visualization, with a reliability-focused five-tab workflow that fixes earlier package, storage, cache, training, threading, and generation issues. It supports Python 3.11+, offers six model presets from approximately 4.2M to 478M parameters, and includes a Model/VRAM Planner to assess hardware fit before training.", "body_md": "NanoLM Studio is a local desktop workbench for building a small decoder-only language model from a corpus you can inspect and control. You can built it your way, how you want it to be. It combines document ingestion, cleaning, ByteLevel BPE tokenization, PyTorch training, interactive generation, and attention visualisation in one Tk application.\n\nAlthough this is the first time I have released it publicly, the program has gone through a number of iterations and this V4 Studio is a reliability-focused version. It has a five-tab workflow while correcting the package, storage, cache, training, threading, and generation problems found in earlier versions.\n\nUse Python 3.11 or newer. A virtual environment is strongly recommended.\n\n```\npy -m venv .venv\n.venv\\Scripts\\activate\npython -m pip install --upgrade pip\npip install -r requirements.txt\npython main.py\n```\n\nThe Windows requirements explicitly install PyTorch 2.12.1 with CUDA 12.6. NanoLM also checks for the broken state where Windows can see an NVIDIA GPU but the active environment contains CPU-only PyTorch. Training is blocked with repair instructions in that case; it will no longer silently use CPU.\n\n```\npython3 -m venv .venv\nsource .venv/bin/activate\npython -m pip install --upgrade pip\npip install -r requirements.txt\npython main.py\n```\n\nOn non-Windows systems, PyTorch installation can vary by operating system and\naccelerator. If the standard requirements command cannot select the right\nbuild, install PyTorch using the command generated at\n[https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/), then run\n`pip install -r requirements.txt`\n\nagain.\n\n**Library**— import TXT, Markdown, HTML, PDF, EPUB, or DOCX files. Search, sort, tag, enable/disable, remove, re-clean, or compare raw and cleaned text. The document table has permanent vertical and horizontal scrollbars.**Tokenizer**— train a ByteLevel BPE tokenizer on active documents and use the inspector to see token boundaries and IDs.** Training**— choose a model preset and train with gradient accumulation, cosine learning-rate decay, validation, early stopping, checkpoints, live metrics, charts, and sample generations. Each validation checkpoint reports fixed-sample training loss, validation loss, and their signed overfit gap; the chart shades the gap as it opens. The Model / VRAM Planner compares hardware and corpus fit before applying a configuration.**Chat**— load`best.pt`\n\n,`final.pt`\n\n, or a chosen checkpoint and generate in dialogue or continuation mode. Generation streams, can be stopped, and uses a key/value cache while the context window has room.**Glass Box**— inspect mean attention maps by layer and the next-token probability distribution for a prompt.\n\nBy default, all mutable data is placed in `./data`\n\nbeside `main.py`\n\n:\n\n```\ndata/\n  corpus.db\n  raw/\n  documents/\n  tokenizer/tokenizer.json\n  cache/{train_tokens.npy,val_tokens.npy,meta.json}\n  checkpoints/{best.pt,final.pt}\n  runs/run_*.jsonl\n```\n\nSet `NANOLM_DATA_DIR`\n\nbefore launch to use another workspace:\n\n```\n$env:NANOLM_DATA_DIR = \"D:\\NanoLMProjects\\experiment-01\"\npython main.py\nNANOLM_DATA_DIR=\"$HOME/NanoLMProjects/experiment-01\" python main.py\n```\n\nThis also makes automated tests safe: they use isolated temporary directories and never touch the real corpus.\n\n- Correct package layout:\n`python main.py`\n\nnow imports the included`nanolm`\n\npackage successfully. - The Library Treeview's scrollbar is actually placed in the layout, is always visible, and is paired with search, active-only filtering, sorting, mouse wheel support, and a context menu.\n- SQLite and document paths can be isolated; file replacements and tokenizer, cache, and checkpoint writes are atomic.\n- Token-cache validity includes both the tokenizer fingerprint and the exact active corpus fingerprint, preventing stale training data after corpus edits.\n- Model parameter counts correctly account for tied weights.\n- Six presets now cover approximately 4.2M through 478M parameters: Tiny, Small, Medium, Large, XL, and XXL.\n- A persistent Model / VRAM Planner accepts available VRAM, active corpus tokens, and a trial micro-batch. Its colour-coded table and visual meters distinguish comfortable, marginal, and poor settings, recommend the best corpus/model match, and apply batch, accumulation, step, and LR settings.\n- Training steps now mean optimizer updates. Every update performs exactly the requested number of accumulation micro-batches, so partial gradients are not silently discarded.\n- Resume checkpoints include optimizer/scaler state, early-stop state, NumPy RNG state, and PyTorch RNG state.\n- Validation restores the model's prior mode; sampling and shutdown respond to stop requests.\n- Generation validates settings, supports true greedy decoding at temperature zero, avoids per-token CPU repetition-penalty loops, and caches attention keys/values until the sliding window must be rebuilt.\n- Tk widgets and variables are only accessed on the UI thread. Checkpoint loads and Glass Box inference run in workers, and the event pump uses a time budget so streaming cannot starve the interface.\n- Chat streaming replaces the current decoded response rather than assuming every ByteLevel decode is an append-only string.\n- Closing during training requests a clean stop and gives\n`final.pt`\n\ntime to be saved.\n\nSee `V4_REVIEW.md`\n\nfor the full audit and development critique.\nSee `V4_CAPACITY_PLANNER.md`\n\nfor planner ranges, estimates, and usage.\n\nRun the non-GUI suite from the project directory:\n\n```\npython -m unittest discover -s tests -v\npython smoke_test.py\n```\n\nThe smoke test creates a temporary corpus, tokenizer, cache, run history, and checkpoints. It does not delete or overwrite application data.\n\nThis is an educational local language-model studio, not a substitute for a large pretrained assistant. Results depend heavily on corpus quality, corpus size, compute, and training time. The medium preset may be slow on CPU. Keep backups of valuable corpora and only load checkpoint files you trust, because PyTorch checkpoints are not a safe format for untrusted downloads.\n\nThe next natural evolution is a multi-project experiment studio: named project workspaces, richer dataset versioning, comparative run dashboards, adapter fine-tuning of pretrained models, and export/inference backends such as ONNX or GGUF. V4 deliberately establishes the reliable local foundation those features would need.\n\nIt is released open-source under MIT license.\n\nBy JL Kosev-Lex on 3 September 2026.", "url": "https://wpnews.pro/news/nano-lm-studio", "canonical_source": "https://github.com/Kosev-Lex/NanoLM-Studio", "published_at": "2026-09-04 06:31:52+00:00", "updated_at": "2026-09-04 06:52:44.141288+00:00", "lang": "en", "topics": ["machine-learning", "large-language-models", "ai-tools", "developer-tools"], "entities": ["NanoLM Studio", "PyTorch", "CUDA", "NVIDIA"], "alternates": {"html": "https://wpnews.pro/news/nano-lm-studio", "markdown": "https://wpnews.pro/news/nano-lm-studio.md", "text": "https://wpnews.pro/news/nano-lm-studio.txt", "jsonld": "https://wpnews.pro/news/nano-lm-studio.jsonld"}}