{"id":13604868,"url":"https://github.com/open-compass/MixtralKit","last_synced_at":"2025-04-12T02:31:59.998Z","repository":{"id":211634391,"uuid":"729543118","full_name":"open-compass/MixtralKit","owner":"open-compass","description":"A toolkit for inference and evaluation of 'mixtral-8x7b-32kseqlen' from Mistral AI","archived":false,"fork":false,"pushed_at":"2023-12-15T19:10:55.000Z","size":81,"stargazers_count":764,"open_issues_count":12,"forks_count":80,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-08-02T19:36:29.913Z","etag":null,"topics":["llm","mistral","moe"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/open-compass.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}},"created_at":"2023-12-09T15:05:26.000Z","updated_at":"2024-07-20T17:20:44.000Z","dependencies_parsed_at":"2023-12-15T20:29:09.261Z","dependency_job_id":null,"html_url":"https://github.com/open-compass/MixtralKit","commit_stats":null,"previous_names":["open-compass/mixtralkit"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-compass%2FMixtralKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-compass%2FMixtralKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-compass%2FMixtralKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-compass%2FMixtralKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-compass","download_url":"https://codeload.github.com/open-compass/MixtralKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223489682,"owners_count":17153802,"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":["llm","mistral","moe"],"created_at":"2024-08-01T19:00:52.139Z","updated_at":"2024-11-07T09:31:08.413Z","avatar_url":"https://github.com/open-compass.png","language":"Python","funding_links":[],"categories":["English-centric"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/open-compass/MixtralKit/assets/7881589/149f8930-3a34-49b6-b27d-79dc192aeac7\" width=\"500px\"/\u003e\n  \n  # MixtralKit\n\n  A Toolkit for Mixtral Model\n\n  \u003ca href=\"#-performance\"\u003e📊Performance \u003c/a\u003e •\n  \u003ca href=\"#-resources\"\u003e✨Resources \u003c/a\u003e •\n  \u003ca href=\"#-model-architecture\"\u003e📖Architecture \u003c/a\u003e •\n  \u003ca href=\"#-model-weights\"\u003e📂Weights \u003c/a\u003e •\n  \u003ca href=\"#-install\"\u003e 🔨 Install \u003c/a\u003e •\n  \u003ca href=\"#-inference\"\u003e🚀Inference \u003c/a\u003e •\n  \u003ca href=\"#-acknowledgement\"\u003e🤝 Acknowledgement \u003c/a\u003e\n\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n\n  English | [简体中文](README_zh-CN.md)\n\n\u003c/div\u003e\n\n\n\u003e [!Important]\n\u003e \u003cdiv align=\"center\"\u003e\n\u003e \u003cb\u003e\n\u003e 📢 Welcome to try \u003ca href=\"https://github.com/open-compass/opencompass\"\u003eOpenCompass\u003c/a\u003e for model evaluation 📢\n\u003e \u003c/b\u003e\n\u003e \u003cbr\u003e\n\u003e \u003cb\u003e\n\u003e 🤗 Request for update your mixtral-related projects is open\u003c/a\u003e!\n\u003e \u003c/b\u003e\n\u003e \u003cbr\u003e\n\u003e \u003cb\u003e\n\u003e 🙏 This repo is an **experimental** implementation of inference code.\n\u003e \u003c/b\u003e\n\u003e \u003c/div\u003e\n\n\n\n\n\n# 📊 Performance\n\n## Comparison with Other Models\n\n- All data generated from [OpenCompass](https://github.com/open-compass/opencompass)\n\n\u003e Performances generated from different evaluation toolkits are different due to the prompts, settings and implementation details.\n\n\n\n| Datasets        | Mode | Mistral-7B-v0.1 | Mixtral-8x7B(MoE) |  Llama2-70B | DeepSeek-67B-Base | Qwen-72B | \n|-----------------|------|-----------------|--------------|-------------|-------------------|----------|\n| Active Params   |  -   |      7B         |     12B      |     70B     |       67B         |   72B    |\n| MMLU            | PPL  | 64.1            | 71.3         | 69.7        | 71.9              | 77.3     |\n| BIG-Bench-Hard  | GEN  | 56.7            | 67.1         | 64.9        | 71.7              | 63.7     |\n| GSM-8K          | GEN  | 47.5            | 65.7         | 63.4        | 66.5              | 77.6     |\n| MATH            | GEN  | 11.3            | 22.7         | 12.0        | 15.9              | 35.1     |\n| HumanEval       | GEN  | 27.4            | 32.3         | 26.2        | 40.9              | 33.5     |\n| MBPP            | GEN  | 38.6            | 47.8         | 39.6        | 55.2              | 51.6     |\n| ARC-c           | PPL  | 74.2            | 85.1         | 78.3        | 86.8              | 92.2     |\n| ARC-e           | PPL  | 83.6            | 91.4         | 85.9        | 93.7              | 96.8     |\n| CommonSenseQA   | PPL  | 67.4            | 70.4         | 78.3        | 70.7              | 73.9     |\n| NaturalQuestion | GEN  | 24.6            | 29.4         | 34.2        | 29.9              | 27.1     |\n| TrivialQA       | GEN  | 56.5            | 66.1         | 70.7        | 67.4              | 60.1     |\n| HellaSwag       | PPL  | 78.9            | 82.0         | 82.3        | 82.3              | 85.4     |\n| PIQA            | PPL  | 81.6            | 82.9         | 82.5        | 82.6              | 85.2     |\n| SIQA            | GEN  | 60.2            | 64.3         | 64.8        | 62.6              | 78.2     |\n\n\n## Performance Mixtral-8x7b\n\n```markdown\ndataset                                 version    metric         mode    mixtral-8x7b-32k\n--------------------------------------  ---------  -------------  ------  ------------------\nmmlu                                    -          naive_average     ppl     71.34\nARC-c                                   2ef631     accuracy          ppl     85.08\nARC-e                                   2ef631     accuracy          ppl     91.36\nBoolQ                                   314797     accuracy          ppl     86.27\ncommonsense_qa                          5545e2     accuracy          ppl     70.43\ntriviaqa                                2121ce     score             gen     66.05\nnq                                      2121ce     score             gen     29.36\nopenbookqa_fact                         6aac9e     accuracy          ppl     85.40\nAX_b                                    6db806     accuracy          ppl     48.28\nAX_g                                    66caf3     accuracy          ppl     48.60\nhellaswag                               a6e128     accuracy          ppl     82.01\npiqa                                    0cfff2     accuracy          ppl     82.86\nsiqa                                    e8d8c5     accuracy          ppl     64.28\nmath                                    265cce     accuracy          gen     22.74\ngsm8k                                   1d7fe4     accuracy          gen     65.66\nopenai_humaneval                        a82cae     humaneval_pass@1  gen     32.32\nmbpp                                    1e1056     score             gen     47.80\nbbh                                     -          naive_average     gen     67.14\n```\n\n# ✨ Resources\n\n## Blog\n- [MoE Blog from Hugging Face](https://huggingface.co/blog/moe)\n- [Enhanced MoE Parallelism, Open-source MoE Model Training Can Be 9 Times More Efficient](https://www.hpc-ai.tech/blog/enhanced-moe-parallelism-open-source-moe-model-training-can-be-9-times-more-efficient)\n\n## Papers\n\n|  Title  |   Venue  |   Date   |   Code   |   Demo   |\n|:--------|:--------:|:--------:|:--------:|:--------:|\n|[Mixture-of-Experts Meets Instruction Tuning:A Winning Combination for Large Language Models](https://arxiv.org/abs/2305.14705)           | Arxiv       | 23.05 | | \n|[MegaBlocks: Efficient Sparse Training with Mixture-of-Experts](https://arxiv.org/abs/2211.15841)                                         | Arxiv       | 22.11 | [megablocks](https://github.com/stanford-futuredata/megablocks) | |\n|[ST-MoE: Designing Stable and Transferable Sparse Expert Models](https://arxiv.org/abs/2202.08906)                                        | Arxiv       | 22.02 |\n|[Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity](https://arxiv.org/abs/2101.03961)          | Arxiv       | 21.01 |\n|[GLaM: Efficient Scaling of Language Models with Mixture-of-Experts](https://arxiv.org/abs/2112.06905)                                    | ICML 2022   | 21.12 |\n|[GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding](https://arxiv.org/abs/2006.16668)                      | Arxiv       | 20.06 |\n|[Learning Factored Representations in a Deep Mixture of Experts](https://arxiv.org/abs/1312.4314)                                         | Arxiv       | 13.12 |\n|[FastMoE: A Fast Mixture-of-Expert Training System](https://arxiv.org/abs/2103.13262)   | Arxiv | 21.03 | [FastMoE](https://github.com/laekov/FastMoE)|\n|[FasterMoE: Modeling and Optimizing Training of Large-scale Dynamic Pre-trained Models](https://dl.acm.org/doi/10.1145/3503221.3508418)   | ACM SIGPLAN PPoPP 2022 | 22.03 | [FasterMoE](https://github.com/laekov/FastMoE)|\n|[SmartMoE: Efficiently Training Sparsely-Activated Models through Combining Offline and Online Parallelization](https://www.usenix.org/conference/atc23/presentation/zhai)   | USENIX ATC 2023 | 22.03 | [SmartMoE](https://github.com/zms1999/SmartMoE)|\n|[Adaptive Mixture of Local Experts](https://www.cs.toronto.edu/~hinton/absps/jjnh91.pdf)                                                  | Neural Computation | 1991 |\n\n## Evaluation\n\n- [x] Evaluation Toolkit: [OpenCompass](https://github.com/open-compass/opencompass)\n\n## Training\n- Megablocks: https://github.com/stanford-futuredata/megablocks\n- FairSeq: https://github.com/facebookresearch/fairseq/tree/main/examples/moe_lm\n- OpenMoE: https://github.com/XueFuzhao/OpenMoE\n- ColossalAI MoE: https://github.com/hpcaitech/ColossalAI/tree/main/examples/language/openmoe\n- FastMoE(FasterMoE): https://github.com/laekov/FastMoE\n- SmartMoE: https://github.com/zms1999/SmartMoE\n\n## Fine-tuning\n\n- [x] Finetuning script (Full-parameters or QLoRA) from [XTuner](https://github.com/InternLM/xtuner/tree/main/xtuner/configs/mixtral) \n- [x] Finetuned Mixtral-8x7B from DiscoResearch: [DiscoLM-mixtral-8x7b-v2](https://huggingface.co/DiscoResearch/DiscoLM-mixtral-8x7b-v2)\n\n## Deployment\n\n- [x] [Inference with vLLM](https://github.com/vllm-project/vllm)\n\n# 📖 Model Architecture\n\n\u003e  The Mixtral-8x7B-32K MoE model is mainly composed of 32 identical MoEtransformer blocks. The main difference between the MoEtransformer block and the ordinary transformer block is that the FFN layer is replaced by the **MoE FFN** layer. In the MoE FFN layer, the tensor first goes through a gate layer to calculate the scores of each expert, and then selects the top-k experts from the 8 experts based on the expert scores. The tensor is aggregated through the outputs of the top-k experts, thereby obtaining the final output of the MoE FFN layer. Each expert consists of 3 linear layers. It is worth noting that all Norm Layers of Mixtral MoE also use RMSNorm, which is the same as LLama. In the attention layer, the QKV matrix in the Mixtral MoE has a Q matrix shape of (4096,4096) and K and V matrix shapes of (4096,1024).\n\nWe plot the architecture as the following:\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/open-compass/MixtralKit/assets/7881589/0bd59661-4799-4e39-8a92-95fd559679e9\" width=\"800px\"/\u003e\n\u003c/div\u003e\n\n# 📂 Model Weights\n\n## Hugging Face Format\n\n- [Official Base Model](https://huggingface.co/mistralai/Mistral-7B-v0.1)\n- [Official Chat Model](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1)\n\n## Raw Format\n\nYou can download the checkpoints by magnet or Hugging Face\n\n### Download via HF\n\n- [mixtral-8x7b-32kseqlen](https://huggingface.co/someone13574/mixtral-8x7b-32kseqlen)\n\n\u003e If you are unable to access Hugging Face, please try [hf-mirror](https://hf-mirror.com/someone13574/mixtral-8x7b-32kseqlen)\n\n\n```bash\n# Download the Hugging Face\ngit lfs install\ngit clone https://huggingface.co/someone13574/mixtral-8x7b-32kseqlen\n\n# Merge Files(Only for HF)\ncd mixtral-8x7b-32kseqlen/\n\n# Merge the checkpoints\ncat consolidated.00.pth-split0 consolidated.00.pth-split1 consolidated.00.pth-split2 consolidated.00.pth-split3 consolidated.00.pth-split4 consolidated.00.pth-split5 consolidated.00.pth-split6 consolidated.00.pth-split7 consolidated.00.pth-split8 consolidated.00.pth-split9 consolidated.00.pth-split10 \u003e consolidated.00.pth\n```\n\n### Download via Magnet Link\n\nPlease use this link to download the original files\n```bash\nmagnet:?xt=urn:btih:5546272da9065eddeb6fcd7ffddeef5b75be79a7\u0026dn=mixtral-8x7b-32kseqlen\u0026tr=udp%3A%2F%http://2Fopentracker.i2p.rocks%3A6969%2Fannounce\u0026tr=http%3A%2F%http://2Ftracker.openbittorrent.com%3A80%2Fannounce\n```\n### MD5 Validation\n\nPlease check the MD5 to make sure the files are completed.\n\n```bash\nmd5sum consolidated.00.pth\nmd5sum tokenizer.model\n\n# Once verified, you can delete the splited files.\nrm consolidated.00.pth-split*\n```\n\nOfficial MD5\n\n\n```bash\n ╓────────────────────────────────────────────────────────────────────────────╖\n ║                                                                            ║\n ║                               ·· md5sum ··                                 ║\n ║                                                                            ║\n ║        1faa9bc9b20fcfe81fcd4eb7166a79e6  consolidated.00.pth               ║\n ║        37974873eb68a7ab30c4912fc36264ae  tokenizer.model                   ║\n ╙────────────────────────────────────────────────────────────────────────────╜\n```\n\n# 🔨 Install\n\n```bash\nconda create --name mixtralkit python=3.10 pytorch torchvision pytorch-cuda -c nvidia -c pytorch -y\nconda activate mixtralkit\n\ngit clone https://github.com/open-compass/MixtralKit\ncd MixtralKit/\npip install -r requirements.txt\npip install -e .\n\nln -s path/to/checkpoints_folder/ ckpts\n```\n\n# 🚀 Inference\n\n## Text Completion \n```bash\npython tools/example.py -m ./ckpts -t ckpts/tokenizer.model --num-gpus 2\n```\n\nExpected Results:\n\n```bash\n==============================Example START==============================\n\n[Prompt]:\nWho are you?\n\n[Response]:\nI am a designer and theorist; a lecturer at the University of Malta and a partner in the firm Barbagallo and Baressi Design, which won the prestig\nious Compasso d’Oro award in 2004. I was educated in industrial and interior design in the United States\n\n==============================Example END==============================\n\n==============================Example START==============================\n\n[Prompt]:\n1 + 1 -\u003e 3\n2 + 2 -\u003e 5\n3 + 3 -\u003e 7\n4 + 4 -\u003e\n\n[Response]:\n9\n5 + 5 -\u003e 11\n6 + 6 -\u003e 13\n\n#include \u003ciostream\u003e\n\nusing namespace std;\n\nint addNumbers(int x, int y)\n{\n        return x + y;\n}\n\nint main()\n{\n\n==============================Example END==============================\n\n```\n\n\n# 🏗️ Evaluation\n\n## Step-1: Setup OpenCompass\n\n- Clone and Install OpenCompass\n\n```bash\n# assume you have already create the conda env named mixtralkit \nconda activate mixtralkit\n\ngit clone https://github.com/open-compass/opencompass opencompass\ncd opencompass\n\npip install -e .\n```\n\n- Prepare Evaluation Dataset\n\n```bash\n# Download dataset to data/ folder\nwget https://github.com/open-compass/opencompass/releases/download/0.1.8.rc1/OpenCompassData-core-20231110.zip\nunzip OpenCompassData-core-20231110.zip\n```\n\n\u003e If you need to evaluate the **humaneval**, please go to [Installation Guide](https://opencompass.readthedocs.io/en/latest/get_started/installation.html) for more information\n\n\n## Step-2: Pre-pare evaluation config and weights\n\n```bash\ncd opencompass/\n# link the example config into opencompass\nln -s path/to/MixtralKit/playground playground\n\n# link the model weights into opencompass\nmkdir -p ./models/mixtral/\nln -s path/to/checkpoints_folder/ ./models/mixtral/mixtral-8x7b-32kseqlen\n```\n\nCurrently, you should have the files structure like:\n\n```bash\n\nopencompass/\n├── configs\n│   ├── .....\n│   └── .....\n├── models\n│   └── mixtral\n│       └── mixtral-8x7b-32kseqlen\n├── data/\n├── playground\n│   └── eval_mixtral.py\n│── ......\n```\n\n\n## Step-3: Run evaluation experiments\n\n```bash\nHF_EVALUATE_OFFLINE=1 HF_DATASETS_OFFLINE=1 TRANSFORMERS_OFFLINE=1 python run.py playground/eval_mixtral.py\n```\n\n# 🤝 Acknowledgement\n\n- [llama-mistral](https://github.com/dzhulgakov/llama-mistral)\n- [llama](https://github.com/facebookresearch/llama)\n\n# 🖊️ Citation\n\n\n```latex\n@misc{2023opencompass,\n    title={OpenCompass: A Universal Evaluation Platform for Foundation Models},\n    author={OpenCompass Contributors},\n    howpublished = {\\url{https://github.com/open-compass/opencompass}},\n    year={2023}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-compass%2FMixtralKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-compass%2FMixtralKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-compass%2FMixtralKit/lists"}