{"id":22418936,"url":"https://github.com/en10/tinystoriesmodal","last_synced_at":"2026-02-10T22:02:27.509Z","repository":{"id":264390342,"uuid":"892515510","full_name":"EN10/TinyStoriesModal","owner":"EN10","description":"TinyStories on Modal","archived":false,"fork":false,"pushed_at":"2025-05-23T17:38:42.000Z","size":79,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-01T04:45:18.698Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EN10.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-22T09:03:21.000Z","updated_at":"2025-05-23T17:38:45.000Z","dependencies_parsed_at":"2024-11-23T23:20:55.206Z","dependency_job_id":"762c06a2-99b5-432e-824d-1c288a6ecf04","html_url":"https://github.com/EN10/TinyStoriesModal","commit_stats":null,"previous_names":["en10/tinystoriesmodal"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EN10/TinyStoriesModal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EN10%2FTinyStoriesModal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EN10%2FTinyStoriesModal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EN10%2FTinyStoriesModal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EN10%2FTinyStoriesModal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EN10","download_url":"https://codeload.github.com/EN10/TinyStoriesModal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EN10%2FTinyStoriesModal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29319254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T20:44:44.282Z","status":"ssl_error","status_checked_at":"2026-02-10T20:44:43.393Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T16:13:24.095Z","updated_at":"2026-02-10T22:02:27.488Z","avatar_url":"https://github.com/EN10.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinyStories Language Model\n\nThis repository contains an implementation of a small GPT-style language model trained on the TinyStories dataset using Modal for cloud-based training.\n\n## Contents\n- [Overview](#overview)\n- [Features](#features)\n- [Model Architecture \u0026 Configuration](#model-architecture-and-configuration)\n- [Files and Dependencies](#files-and-dependencies)\n  - [Core Files](#core-files)\n  - [Data Files](#data-files-automatically-downloaded)\n  - [For Inference](#for-inference)\n  - [Directory Structure](#directory-structure)\n- [Getting Started](#getting-started)\n  - [Example Usage](#example-usage)\n  - [Command Line Options](#command-line-options)\n- [Contributing](#contributing)\n- [License](#license)\n- [Acknowledgments](#acknowledgments)\n\n## Overview\n\nThe project implements a transformer-based language model that can:\n- Train on the TinyStories dataset (a collection of simple stories)\n- Generate new text in a similar style\n- Run efficiently in the cloud using Modal's GPU infrastructure\n\n## Model Architecture \u0026 Configuration\n\nThe model is a small GPT-style transformer with these default parameters:\n- Vocabulary size: 105 tokens\n- Embedding dimension: 128\n- Number of layers: 5\n- Number of attention heads: 8\n- Number of key/value heads: 4\n- Context length: 256 tokens\n- Batch size: 32\n- Total parameters: ~1M\n\nThese parameters can be modified in the configuration:\n```python\n# Model and training parameters\nvocab_size = 105\ndim = 128\nn_layers = 5\nn_heads = 8\nn_kv_heads = 4\nbatch_size = 32\n```\n\n## Files and Dependencies\n\n### Core Files\n- `tinystories_modular.py` - Main implementation with modular design for training and inference\n- `tinystories_data.py` - Data downloading and preprocessing utilities\n- `tinystories_trainer_v1.py` - Alternative training implementation with more detailed logging\n- `volume_cleanup.py` - Utility for cleaning up Modal volume files\n- `transfer_model.py` - Utility for transferring models between local and Modal volume\n- `tinystories.ipynb` - Jupyter notebook for interactive training and testing\n\n### Data Files (automatically downloaded)\nFrom HuggingFace (`tok105` files):\n- `tok105.tar.gz` - Pre-tokenized training data\n- `tok105.bin` - Tokenizer model\n\nFrom llama2.c GitHub:\n- `train.py` - Training script\n- `model.py` - Model implementation\n- `tinystories.py` - Dataset handling\n- `tokenizer.py` - Tokenizer implementation\n- `export.py` - Model export utilities\n- `configurator.py` - Configuration handling\n- `run.c` - C inference program\n\n### For Inference\nRequired files (must exist from previous training):\n- `tok105.bin` - Tokenizer model\n- `out/model.bin` - Trained model output\n- `run` - Compiled C inference program\n\nNote: All files are automatically managed in the Modal volume `tinystories-volume`. The setup function in `tinystories_modular.py` handles downloading and compiling all necessary files.\n\n## Directory Structure\n\nAfter running, your Modal volume will contain:\n```\n/data/\n  ├── tok105.bin            # Tokenizer model\n  ├── tok105.model          # SentencePiece tokenizer model\n  ├── tok105.vocab          # Tokenizer vocabulary\n  ├── tok105.tar.gz         # Training data archive\n  ├── tok105/              # Extracted training data\n  │   └── data*.bin        # Individual training files\n  ├── run.c                # C inference program source\n  ├── run                  # Compiled inference program\n  ├── model.py             # Model implementation\n  ├── train.py             # Training script\n  ├── tinystories.py       # Dataset handling\n  ├── export.py            # Model export utilities\n  ├── configurator.py      # Configuration handling\n  ├── tokenizer.py         # Tokenizer implementation\n  ├── train.pt             # Processed training data\n  ├── val.pt               # Processed validation data\n  ├── checkpoint.pt        # Latest training checkpoint\n  ├── model_best.pt        # Best model during training\n  └── out/                 # Training outputs\n      └── model.bin        # Trained model\n```\n\nNote: The directory structure is automatically managed by the setup function in `tinystories_modular.py`. Files are downloaded and organized as needed.\n\n## Getting Started\n\n1. Install Modal:\n```\npip install modal\n```\n\n2. Set up Modal:\n```\nmodal token new\n```\n\n3. Create a Modal volume:\n```\nmodal volume create tinystories-volume\n```\n\n4. Run the training:\n```\nmodal run tinystories_modular.py\n```\n\nOr run inference with a custom prompt:\n```\nmodal run tinystories_modular.py --command inference --prompt \"Once upon a time\"\n```\n\n## Example Usage\n\nThe code provides three main modes of operation:\n\n1. Training:\n```bash\nmodal run tinystories_modular.py --command train\n```\n\n2. Inference:\n```bash\nmodal run tinystories_modular.py --command inference --prompt \"Once upon a time\"\n```\n\n3. Model Transfer:\n```bash\n# Download model from Modal volume to local\nmodal run transfer_model.py --action download --path out/model.bin\n\n# Upload model from local to Modal volume\nmodal run transfer_model.py --action upload --path out/model.bin\n```\n\n## Command Line Options\n\n### Main Script (tinystories_modular.py)\n- `--command`: Either \"train\" or \"inference\" (default: \"train\")\n- `--prompt`: Initial text for story generation when using inference (default: \"Once upon a time\")\n\n### Transfer Script (transfer_model.py)\n- `--action`: Either \"download\" or \"upload\" (default: \"download\")\n- `--path`: Local path for model file (default: \"out/model.bin\")\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nMIT License\n\n## Acknowledgments\n\n- Based on [Andrej Karpathy's](https://github.com/karpathy/llama2.c) implementation\n- Uses the [TinyStories dataset](https://huggingface.co/datasets/roneneldan/TinyStories)\n- Cloud implementation powered by [Modal](https://modal.com/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fen10%2Ftinystoriesmodal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fen10%2Ftinystoriesmodal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fen10%2Ftinystoriesmodal/lists"}