{"id":22656532,"url":"https://github.com/sbartlett97/roll-to-train","last_synced_at":"2026-04-16T12:02:08.627Z","repository":{"id":266555690,"uuid":"896465273","full_name":"sbartlett97/roll-to-train","owner":"sbartlett97","description":"A journey into the gamification of Machine Learning training algorithms","archived":false,"fork":false,"pushed_at":"2025-03-24T16:32:07.000Z","size":55,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-10T10:16:11.585Z","etag":null,"topics":["dnd","machine-learning","machine-learning-algorithms","machine-learning-training","machinelearning","python","python3","pytorch","transformers"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbartlett97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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-30T12:42:44.000Z","updated_at":"2025-03-24T16:32:11.000Z","dependencies_parsed_at":"2024-12-04T21:36:37.502Z","dependency_job_id":"a316826d-5fd0-4447-a02c-ff62ccfc682f","html_url":"https://github.com/sbartlett97/roll-to-train","commit_stats":null,"previous_names":["sbartlett97/roll-to-train"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sbartlett97/roll-to-train","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbartlett97%2Froll-to-train","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbartlett97%2Froll-to-train/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbartlett97%2Froll-to-train/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbartlett97%2Froll-to-train/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbartlett97","download_url":"https://codeload.github.com/sbartlett97/roll-to-train/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbartlett97%2Froll-to-train/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31884929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T11:36:10.202Z","status":"ssl_error","status_checked_at":"2026-04-16T11:36:09.652Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["dnd","machine-learning","machine-learning-algorithms","machine-learning-training","machinelearning","python","python3","pytorch","transformers"],"created_at":"2024-12-09T10:14:50.770Z","updated_at":"2026-04-16T12:02:08.590Z","avatar_url":"https://github.com/sbartlett97.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎲 Roll-to-Train: Where D\u0026D Meets Deep Learning\n\n[![PyTorch](https://img.shields.io/badge/PyTorch-2.0+-red.svg)](https://pytorch.org/)\n[![License](https://img.shields.io/badge/License-GPL--3.0-blue.svg)](LICENSE)\n[![Python](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://www.python.org/)\n[![Status](https://img.shields.io/badge/Status-Experimental-orange.svg)](https://github.com/yourusername/roll-to-train)\n\n\u003e 🎯 **Transform your ML training into an epic adventure!** Roll-to-Train brings the excitement of tabletop RPGs to machine learning, making model training more engaging and potentially more robust.\n\n## 🌟 Features\n\n- 🎲 **D\u0026D-Inspired Mechanics**: Roll for success, critical hits, and saving throws during training\n- 🧙‍♂️ **Character Classes**: Choose your training style with Wizard, Rogue, and more\n- 🐉 **Monster Encounters**: Face off against Gradient Ooze, Loss Dragon, and Weight Wraith\n- 📈 **Experience System**: Level up your training process\n- 🔄 **Flexible Integration**: Works with PyTorch and HuggingFace transformers\n- 📊 **Visual Analytics**: Track your training progress with detailed loss plots\n\n## 🚀 Quick Start\n\n```python\nfrom roll_to_train import RollToTrain, Wizard, ExperienceSystem\n\n# Initialize your model, optimizer, and scheduler\nmodel = YourTransformerModel()\noptimizer = torch.optim.AdamW(model.parameters())\nscheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=1000)\n\n# Create your trainer with RPG mechanics\ntrainer = RollToTrain(\n    model=model,\n    optimizer=optimizer,\n    scheduler=scheduler,\n    intelligence=15,  # Your model's intelligence stat\n    character_class=Wizard(level=1),  # Choose your class\n    use_xp_system=True\n)\n\n# Train your model\ntrainer.train(train_dataloader, eval_dataloader)\n```\n\n## 🎮 How It Works\n\n### Core Mechanics\n\n1. **Dice Rolls**: Each weight update is determined by rolling virtual dice (d20 by default)\n   - 🎯 **Critical Success (20)**: Full loss application\n   - 💥 **Critical Failure (1)**: Inverse loss application\n   - ⚔️ **Success (≥15)**: Scaled positive update\n   - 🛡️ **Failure (\u003c15)**: Scaled negative update\n\n2. **Character Classes**\n   - 🧙‍♂️ **Wizard**: Manipulates learning rates with arcane abilities\n   - 🗡️ **Rogue**: Applies gradient boosts with sneak attacks\n   - ⚔️ **Fighter**: Provides consistent training with Second Wind and Action Surge\n   - 🙏 **Cleric**: Stabilizes training with healing and divine intervention\n   - 💢 **Barbarian**: Aggressive training with Rage and Reckless Attack\n   - ✨ **Paladin**: Balanced approach with Aura of Protection and Divine Smite\n\nEach class offers unique training dynamics:\n\n| Class | Specialization | Key Abilities | Best For |\n|-------|---------------|--------------|-----------|\n| Wizard | Learning rate control | Arcane Recovery, Spell Mastery | Fine-tuning |\n| Rogue | Gradient manipulation | Sneak Attack, Cunning Action | Precise updates |\n| Fighter | Consistency | Second Wind, Action Surge | Stable training |\n| Cleric | Recovery \u0026 stability | Divine Intervention, Healing Word | Difficult models |\n| Barbarian | Aggressive updates | Rage, Reckless Attack | Escaping local minima |\n| Paladin | Balanced performance | Divine Smite, Aura of Protection | General training |\n\n3. **Monster Encounters**\n   - 🐉 **Loss Dragon**: Increases loss values\n   - 🦠 **Gradient Ooze**: Slows down updates\n   - 👻 **Weight Wraith**: Affects model weights\n\n## 📈 Results\n\nCheck out our [experiments](experiments/) directory for detailed results and comparisons with traditional training methods.\n\n## 🤝 Contributing\n\nWe welcome contributions! Whether you want to:\n- Add new character classes\n- Create new monsters\n- Implement additional RPG mechanics\n- Improve documentation\n- Fix bugs\n\nPlease check out our [Contributing Guidelines](CONTRIBUTING.md) to get started.\n\n## 📚 Documentation\n\nFor detailed documentation, visit our [Wiki](https://github.com/yourusername/roll-to-train/wiki).\n\n## 📝 License\n\nThis project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.\n\n## 🙏 Acknowledgments\n\n- Inspired by D\u0026D 5e mechanics\n- Built on PyTorch and HuggingFace transformers\n- Special thanks to all contributors and supporters\n\n---\n\n\u003cdiv align=\"center\"\u003e\n  \u003csub\u003eBuilt with ❤️ by the Roll-to-Train team\u003c/sub\u003e\n\u003c/div\u003e\n\n# **Roll-to-Train: A Gamified Approach to Machine Learning Training**\n\n*Roll-to-Train* is a novel, experimental, method for training transformer models that integrates mechanics inspired by tabletop role-playing games (RPGs), \nsuch as dice rolls and saving throws, into the training process. This approach incorporates randomness not just for initialization or \nsampling but directly into the optimization step, creating a dynamic and gamified training paradigm. \n\nThe potential benefits include increased robustness, creative exploration of optimization landscapes, and an engaging tool for educational purposes.\n\nThis repo is in active development, and I am welcome to suggestions and contributions to take this even further!\n\nsee the CONTRIBUTING.md file.\n\n---\n\n### **Methodology**\n\nThe current implementation is very basic, and only the default training option works. It implements dice-roll mechanics \ninto the weight update step on either a `per_mini_batch` or `per_accumulation_step` basis. When applied per mini-batch, \nthe loss for each batch is scaled directly in accordance with the outcome of the dice rolls. For each accumulation step, the\nstored weight updates for each parameter are scaled in the same way.\n\n1. **Saving Throws**: For each weight update, a random integer between 1 and 20 is rolled:\n   - **Critical Failure (1)**: The accumulated loss is discarded, and no update occurs.\n   - **Critical Success (20)**: Full loss is used for a scaled weight update.\n   - **Above Threshold (e.g., ≥15)**: A partial weight update scaled by the roll result is applied.\n   - **Below Threshold (e.g., \u003c15)**: A scaled inverse of the weight update is applied to simulate negative learning.\n   \n2. **Dynamic Update Scaling**: The magnitude of weight updates is scaled based on the roll, introducing randomness into the training trajectory.\n\n3. **Compatibility**: This method is designed to integrate seamlessly with existing frameworks like PyTorch and HuggingFace, requiring only minor modifications to the optimizer and training loop.\n\n---\n\n### **Potential Applications**\n1. **Robustness Testing**: Introducing randomness into weight updates can test a model's resilience to suboptimal optimization.\n2. **Educational Tool**: The gamified mechanics offer an engaging way to teach machine learning concepts.\n3. **Exploration of Loss Landscapes**: By breaking deterministic patterns, this approach could lead to unexpected paths through the optimization space.\n\n\n### References\n\n@article{DBLP:journals/corr/abs-1810-04805,\n  author    = {Jacob Devlin and\n               Ming{-}Wei Chang and\n               Kenton Lee and\n               Kristina Toutanova},\n  title     = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language\n               Understanding},\n  journal   = {CoRR},\n  volume    = {abs/1810.04805},\n  year      = {2018},\n  url       = {http://arxiv.org/abs/1810.04805},\n  archivePrefix = {arXiv},\n  eprint    = {1810.04805},\n  timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},\n  biburl    = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},\n  bibsource = {dblp computer science bibliography, https://dblp.org}\n}\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbartlett97%2Froll-to-train","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbartlett97%2Froll-to-train","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbartlett97%2Froll-to-train/lists"}