{"id":13571881,"url":"https://github.com/AviSoori1x/makeMoE","last_synced_at":"2025-04-04T09:30:37.027Z","repository":{"id":218585095,"uuid":"746833579","full_name":"AviSoori1x/makeMoE","owner":"AviSoori1x","description":"From scratch implementation of a sparse mixture of experts language model inspired by Andrej Karpathy's makemore :)","archived":false,"fork":false,"pushed_at":"2024-10-30T15:32:41.000Z","size":7293,"stargazers_count":589,"open_issues_count":3,"forks_count":60,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-10-30T16:34:02.506Z","etag":null,"topics":["deep-learning","large-language-models","llm","mixture-of-experts","neural-networks","pytorch","pytorch-implementation"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/AviSoori1x.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}},"created_at":"2024-01-22T19:04:58.000Z","updated_at":"2024-10-30T15:34:34.000Z","dependencies_parsed_at":"2024-10-30T16:36:49.335Z","dependency_job_id":null,"html_url":"https://github.com/AviSoori1x/makeMoE","commit_stats":null,"previous_names":["avisoori1x/makemoe"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AviSoori1x%2FmakeMoE","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AviSoori1x%2FmakeMoE/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AviSoori1x%2FmakeMoE/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AviSoori1x%2FmakeMoE/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AviSoori1x","download_url":"https://codeload.github.com/AviSoori1x/makeMoE/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247152760,"owners_count":20892551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["deep-learning","large-language-models","llm","mixture-of-experts","neural-networks","pytorch","pytorch-implementation"],"created_at":"2024-08-01T14:01:07.774Z","updated_at":"2025-04-04T09:30:32.016Z","avatar_url":"https://github.com/AviSoori1x.png","language":"Jupyter Notebook","funding_links":[],"categories":["Jupyter Notebook","[🔤 pedagogy](https://github.com/stars/ketsapiwiq/lists/pedagogy)"],"sub_categories":[],"readme":"# makeMoE\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"images/makemoelogo.png\" width=\"500\"/\u003e\n\u003c/div\u003e\n\n\n\n\n#### Sparse mixture of experts language model from scratch inspired by (and largely based on) Andrej Karpathy's makemore (https://github.com/karpathy/makemore) :)\n\nHuggingFace Community Blog that walks through this: https://huggingface.co/blog/AviSoori1x/makemoe-from-scratch\n\nPart #2 detailing expert capacity: https://huggingface.co/blog/AviSoori1x/makemoe2\n\nThis is an implementation of a sparse mixture of experts language model from scratch. This is inspired by and largely based on Andrej Karpathy's project 'makemore' and borrows the re-usable components from that implementation. Just like makemore, makeMoE is also an autoregressive character-level language model but uses the aforementioned sparse mixture of experts architecture. \n\nJust like makemore, pytorch is the only requirement (so I hope the from scratch claim is justified).\n\nSignificant Changes from the makemore architecture\n\n- Sparse mixture of experts instead of the solitary feed forward neural net. \n- Top-k gating and noisy top-k gating implementations.\n- initialization - Kaiming He initialization used here but the point of this notebook is to be hackable so you can swap in Xavier Glorot etc. and take it for a spin.\n- Expert Capacity -- most recent update (03/18/2024)\n\nUnchanged from makemore\n- The dataset, preprocessing (tokenization), and the language modeling task Andrej chose originally - generate Shakespeare-like text\n- Causal self attention implementation \n- Training loop\n- Inference logic\n\nPublications heavily referenced for this implementation: \n- Outrageously Large Neural Networks: The Sparsely-Gated Mixture-Of-Experts layer: https://arxiv.org/pdf/1701.06538.pdf\n- Mixtral of experts: https://arxiv.org/pdf/2401.04088.pdf\n\nmakeMoE.py is the entirety of the implementation in a single file of pytorch.\n\nmakMoE_from_Scratch.ipynb walks through the intuition for the entire model architecture and how everything comes together. I recommend starting here.\n\nmakeMoE_from_Scratch_with_Expert_Capacity.ipynb just builds on the above walkthrough and adds expert capacity for more efficient training.\n\nmakeMoE_Concise.ipynb is the consolidated hackable implementation that I encourage you to hack, understand, improve and make your own\n\n**The code was entirely developed on Databricks using a single A100 for compute. If you're running this on Databricks, you can scale this on an arbitrarily large GPU cluster with no issues, on the cloud provider of your choice.**\n\n**I chose to use MLFlow (which comes pre-installed in Databricks. It's fully open source and you can pip install easily elsewhere) as I find it helpful to track and log all the metrics necessary. This is entirely optional but encouraged.**\n\n**Please note that the implementation emphasizes readability and hackability vs. performance, so there are many ways in which you could improve this. Please try and let me know!**\n\nHope you find this useful. Happy hacking!!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAviSoori1x%2FmakeMoE","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAviSoori1x%2FmakeMoE","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAviSoori1x%2FmakeMoE/lists"}