AI prompts
base on Machine Learning Engineering Open Book # Machine Learning Engineering Open Book
This is an open collection of methodologies, tools and step by step instructions to help with successful training of large language models and multi-modal models and their inference.
This is a technical material suitable for LLM/VLM training engineers and operators. That is the content here contains lots of scripts and copy-n-paste commands to enable you to quickly address your needs.
This repo is an ongoing brain dump of my experiences training Large Language Models (LLM) (and VLMs); a lot of the know-how I acquired while training the open-source [BLOOM-176B](https://huggingface.co/bigscience/bloom) model in 2022 and [IDEFICS-80B](https://huggingface.co/HuggingFaceM4/idefics-80b-instruct) multi-modal model in 2023, and RAG models at [Contextual.AI](https://contextual.ai/) in 2024.
I've been compiling this information mostly for myself so that I could quickly find solutions I have already researched in the past and which have worked, but as usual I'm happy to share these notes with the wider ML community.
## Table of Contents
**Part 1. Insights**
1. **[The AI Battlefield Engineering](./insights/ai-battlefield.md)** - what you need to know in order to succeed
**Part 2. Hardware**
1. **[Compute](compute)** - accelerators, CPUs, CPU memory.
1. **[Storage](storage)** - local, distributed and shared file systems.
1. **[Network](network)** - intra- and inter-node networking.
**Part 3. Orchestration**
1. **[SLURM](orchestration/slurm)** - the main orchestration environment
**Part 4. Training**
1. **[Training](training)** - model training-related guides
**Part 5. Inference**
1. **[Inference](inference)** - model inference insights
**Part 6. Development**
1. **[Debugging and Troubleshooting](debug)** - how to debug easy and difficult issues
1. **[And more debugging](https://github.com/stas00/the-art-of-debugging)**
1. **[Testing](testing)** - numerous tips and tools to make test writing enjoyable
**Part 7. Miscellaneous**
1. **[Resources](resources)** - LLM/VLM chronicles
## Updates
I announce any significant updates on my twitter channel [https://twitter.com/StasBekman](https://twitter.com/StasBekman).
## PDF version
Download the [PDF](https://huggingface.co/stas/ml-engineering-book/resolve/main/Stas%20Bekman%20-%20Machine%20Learning%20Engineering.pdf?download=true) version of the book.
I will try to rebuild it once a week or so, but if you want the latest, the instructions for building are [here](build).
Thanks to HuggingFace for giving me permission to host my book's PDF at the [HF hub](https://huggingface.co/).
## Discussions
If you want to discuss something related to ML engineering this repo has the [community discussions](https://github.com/stas00/ml-engineering/discussions) available - so please don't hesitate to share your experience or start a new discussion about something you're passionate about.
## Key comparison tables
High end accelerators:
- [Theoretical accelerator TFLOPS](compute/accelerator#tflops-comparison-table)
- [Accelerator memory size and speed](compute/accelerator#accelerator-memory-size-and-speed)
Networks:
- [Theoretical inter-node speed](network#intra-node-networking)
- [Theoretical intra-node speed](network#inter-node-networking)
## Shortcuts
Things that you are likely to need to find quickly and often.
Tools:
- [all_reduce_bench.py](network/benchmarks/all_reduce_bench.py) - a much easier way to benchmark network throughput than nccl-tests.
- [torch-distributed-gpu-test.py](debug/torch-distributed-gpu-test.py) - a tool to quickly test your inter-node connectivity
Guides:
- [debugging pytorch applications](debug/pytorch.md) - quick copy-n-paste solutions to resolve hanging or breaking pytorch applications
- [slurm for users](orchestration/slurm/users.md) - a slurm cheatsheet and tricks
- [make tiny models/datasets/tokenizers](debug/make-tiny-models-tokenizers-datasets.md)
- [LLM/VLM chronicles collection](resources#publicly-available-training-llmvlm-logbooks)
## Gratitude
None of this would have been possible without me being entrusted with doing the specific LLM/VLM trainings I have learned the initial know-how from. This is a privilege that only a few enjoy due to the prohibitively expensive cost of renting huge ML compute clusters. So hopefully the rest of the ML community will vicariously learn from these notes.
Special thanks go to [Thom Wolf](https://github.com/thomwolf) who proposed that I lead the BLOOM-176B training back when I didn't know anything about large scale training. This was the project that catapulted me into the intense learning process. And, of course, HuggingFace for giving me the opportunity to work full time on BLOOM-176B and later on IDEFICS-80B trainings.
Recently, I continued expanding my knowledge and experience while training models and building scalable training/inference systems at [Contextual.AI](https://contextual.ai/) and I'm grateful to that opportunity to Aman and Douwe.
I'd also like to say thanks to the numerous [contributors](contributors.md) who have been making this text awesome and error-free.
## Contributing
If you found a bug, typo or would like to propose an improvement please don't hesitate to open an [Issue](https://github.com/stas00/ml-engineering/issues) or contribute a PR.
## License
The content of this site is distributed under [Attribution-ShareAlike 4.0 International](LICENSE-CC-BY-SA).
## Citation
```bibtex
@misc{bekman2024mlengineering,
author = {Bekman, Stas},
title = {Machine Learning Engineering Open Book},
year = {2023-2024},
publisher = {Stasosphere Online Inc.},
journal = {GitHub repository},
url = {https://github.com/stas00/ml-engineering}
}
```
## My repositories map
✔ **Machine Learning:**
[ML Engineering Open Book](https://github.com/stas00/ml-engineering) |
[ML ways](https://github.com/stas00/ml-ways) |
[Porting](https://github.com/stas00/porting)
✔ **Guides:**
[The Art of Debugging](https://github.com/stas00/the-art-of-debugging)
✔ **Applications:**
[ipyexperiments](https://github.com/stas00/ipyexperiments)
✔ **Tools and Cheatsheets:**
[bash](https://github.com/stas00/bash-tools) |
[conda](https://github.com/stas00/conda-tools) |
[git](https://github.com/stas00/git-tools) |
[jupyter-notebook](https://github.com/stas00/jupyter-notebook-tools) |
[make](https://github.com/stas00/make-tools) |
[python](https://github.com/stas00/python-tools) |
[tensorboard](https://github.com/stas00/tensorboard-tools) |
[unix](https://github.com/stas00/unix-tools)
", Assign "at most 3 tags" to the expected json: {"id":"2254","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"