Book Image

Pretrain Vision and Large Language Models in Python

By : Emily Webber
4.5 (2)
Book Image

Pretrain Vision and Large Language Models in Python

4.5 (2)
By: Emily Webber

Overview of this book

Foundation models have forever changed machine learning. From BERT to ChatGPT, CLIP to Stable Diffusion, when billions of parameters are combined with large datasets and hundreds to thousands of GPUs, the result is nothing short of record-breaking. The recommendations, advice, and code samples in this book will help you pretrain and fine-tune your own foundation models from scratch on AWS and Amazon SageMaker, while applying them to hundreds of use cases across your organization. With advice from seasoned AWS and machine learning expert Emily Webber, this book helps you learn everything you need to go from project ideation to dataset preparation, training, evaluation, and deployment for large language, vision, and multimodal models. With step-by-step explanations of essential concepts and practical examples, you’ll go from mastering the concept of pretraining to preparing your dataset and model, configuring your environment, training, fine-tuning, evaluating, deploying, and optimizing your foundation models. You will learn how to apply the scaling laws to distributing your model and dataset over multiple GPUs, remove bias, achieve high throughput, and build deployment pipelines. By the end of this book, you’ll be well equipped to embark on your own project to pretrain and fine-tune the foundation models of the future.
Table of Contents (23 chapters)
1
Part 1: Before Pretraining
5
Part 2: Configure Your Environment
9
Part 3: Train Your Model
13
Part 4: Evaluate Your Model
17
Part 5: Deploy Your Model

Using Flash Attention to speed up your training runs

In earlier chapters, we learned about the core Transformer model, with its underlying self-attention mechanism that serves as the basis for most state-of-the-art models across vision, language, and generative use cases today. While Transformer models are easily parallelizable, they aren’t particularly good at optimizing for different memory speeds within modern GPUs. This becomes a problem when they materialize the Transformer in the slowest part of the GPU due to a naïve implementation. As you can imagine, that leaves performance gains on the table.

A Stanford-led research team realized that they could improve this and developed a novel implementation of the Transformer architecture. Simply put, it’s an extremely clever way to handle a quadratic nested for-loop. Let’s take a closer look.

Figure 9.2 – From FlashAttention by Tri Dao et al, 2022 (1)

Figure 9.2 – From FlashAttention by Tri Dao et al, 2022 (1)

This visual from...