Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorChris Fregly, Antje Barth, Shelbee Eigenbrode

Companies today are moving rapidly to integrate generative AI into their products and services. But there's a great deal of hype (and misunderstanding) about the impact and promise of this technology. With this book, Chris Fregly, Antje Barth, and Shelbee Eigenbrode from AWS help CTOs, ML practitioners, application developers, business analysts, data engineers, and data scientists find practical ways to use this exciting new technology. You'll learn the generative AI project life cycle including use case definition, model selection, model fine-tuning, retrieval-augmented generation, reinforcement learning from human feedback, and model quantization, optimization, and deployment. And you'll explore different types of models including large language models (LLMs) and multimodal models such as Stable Diffusion for generating images and Flamingo/IDEFICS for answering questions about images. • Apply generative AI to your business use cases • Determine which generative AI models are best suited to your task • Perform prompt engineering and in-context learning • Fine-tune generative AI models on your datasets with low-rank adaptation (LoRA) • Align generative AI models to human values with reinforcement learning from human feedback (RLHF) • Augment your model with retrieval-augmented generation (RAG) • Explore libraries such as LangChain and ReAct to develop agents and actions • Build generative AI applications with Amazon Bedrock

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A practical, AWS-centric guide for building production-grade generative AI applications—covering the full project life cycle from prompt engineering and model selection to fine-tuning, RLHF, RAG, and deployment—ideal for ML practitioners, data engineers, and application developers who want to move beyond hype and ship real solutions. 【Book Arc】 - **Opening (~0%–9%)**: Introduces the generative AI landscape, common use cases (translation, content generation, etc.), and the end-to-end project life cycle—use case definition, model selection, fine-tuning, alignment, evaluation, deployment, and augmentation. Sets the stage for why a structured approach matters. - **Early (~9%–25%)**: Dives into prompt engineering and in-context learning fundamentals—zero-shot, one-shot, few-shot inference, context design, and best practices like XML/HTML tags, PII masking, and selective focus. Warns about in-context learning pitfalls (e.g., tricking models with bad examples). - **Early (~25%–34%)**: Explains large-language foundation models—embedding vectors, attention mechanisms, transformer architecture (query/key vectors, softmax), and scaling laws. Shows how model size vs. dataset size trade-offs affect performance and compute budgets. - **Middle (~34%–44%)**: Covers memory and compute optimizations—quantization (fp16, int8), memory footprint reduction, and distributed computing with FSDP across GPUs. Includes practical code snippets for SageMaker and AWS Trainium. - **Middle (~44%–47%)**: Continues optimization techniques—post-training quantization (PTQ), GPTQ, and deployment considerations. Bridges training optimizations to inference performance. - **Late (~47%–end)**: Moves to context-aware reasoning applications using RAG and agents—addressing LLM limitations (hallucination, knowledge cutoff), document loading/chunking, embedding vector stores, retrieval chains, and reranking with Maximum Marginal Relevance. (Excerpts thin here; full book likely covers LangChain/ReAct and Amazon Bedrock.) 【Key Takeaways】 - **Generative AI is a full life cycle, not a single model** (Opening): Success requires iterating through use case definition, model selection, prompt engineering, fine-tuning, alignment, evaluation, and deployment—each stage has its own tools and trade-offs. - **Prompt engineering is the first lever to pull** (Early): Start with zero-shot, escalate to one-shot/few-shot inference, and use structured tags (XML/HTML) and PII masking to improve output quality. But beware—in-context examples can mislead models if poorly chosen. - **Context is everything for coherent responses** (Early): Passing relevant background, dialogue, or examples as context enables in-context learning; the quality of your prompt-completion pairs directly determines output reliability. - **Transformer architecture explains model behavior** (Early): Embedding vectors (512–4,096 dimensions), attention weights (query-key dot products), and softmax probability distributions are the mechanics behind "completions"—understanding them helps you debug and tune models. - **Scaling laws offer a compute-smart path** (Middle): You can match 175B-parameter performance by increasing dataset size instead of model size—a key insight for teams with limited compute budgets. - **Quantization is a memory and speed win** (Middle): fp16 and int8 quantization cut memory usage by 50–75% with acceptable precision loss; tools like bitsandbytes/LLM.int8() minimize performance impact, making deployment cheaper and faster. - **Distributed training is essential for scale** (Middle): FSDP (Fully Sharded Data Parallel) across GPUs, via SageMaker's distributed library, enables training large models efficiently—with practical code patterns for sharding and bf16. - **RAG solves hallucination and knowledge cutoff** (Late): Retrieval-augmented generation grounds models in external knowledge via document loading, chunking, embedding stores, and reranking (e.g., MMR)—critical for production accuracy. 【Reading Tips】 - **Skim the opening chapters** (~0–9%) for the life cycle overview; they're foundational but high-level—don't get bogged down in use-case examples if you're already familiar with gen AI basics. - **Deep-read the prompt engineering chapter** (~9–25%): It's the most immediately actionable content; practice the few-shot and XML-tag techniques with your own models to internalize them. - **Pay attention to the quantization and distributed computing sections** (~34–47%): These are dense but crucial for cost and performance; skim the math, focus on the practical trade-offs (memory vs. precision) and code snippets. - **For RAG and agents** (~47%+): Expect hands-on implementation details—document chunking strategies, embedding vector stores, and reranking—but note the excerpts are thin here; supplement with the book's GitHub code if needed. - **Skip the front matter** (preface, permissions) unless you need code-usage guidelines; it's standard O'Reilly boilerplate. 【Coverage Limits】 This guide synthesizes excerpts covering roughly the first half of the book (through optimization and into RAG). The later chapters on Amazon Bedrock, LangChain/ReAct agents, and full deployment workflows are only partially represented—consult the book directly for those details.
Page 12
g with RLHF 130 Evaluate RLHF Fine-Tuned Model 131 Qualitative Evaluation 131 Quantitative Evaluation 132 Load Evaluation Model 133 Define Evaluation-Metric...
View in text
Excerpt 2
rative models with external data sources or APIs. Evaluate. To properly implement generative AI applications, you need to iterate heavily. Therefore, it’s im...
View in text
Excerpt 3
ace it with XXX,” for instance. Here is an example. Prompt: Human: Here is some text inside the <text></text> XML tags. Please remove all personally identifi...
View in text
Excerpt 4
post-training quantization (GPTQ)1 in more detail when you prepare the model for deployment in Chapter 8. 1 Elias Frantar et al., “GPTQ: Accurate Post-Traini...
View in text
Excerpt 5
ining_args, train_dataset=tokenized_datasets["train"] ) As shown in Figure 6-6, the two low-rank matrices, A and B, are multiplied together to create a matri...
View in text
Excerpt 6
ure the toxicity score again using the same aggregate_toxic ity_scores() function: from transformers import AutoTokenizer model_checkpoint = "..." # generati...
View in text
Excerpt 7
if the data is already in a consumable format; however, the preparation of data is often a prerequisite in RAG-based architecture to prepare the data for ret...
View in text
Excerpt 8
t guide models to create step-by-step action plans, you can now build powerful context-aware reasoning applications. To build end-to-end generative AI soluti...
View in text
Tags
AI categories
Cloud NativeArtificial IntelligenceBackend
ISBN: 1098159225
Publisher: O'Reilly Media
Publish Year: 2024
Language: English
Pages: 312
File Format: PDF
File Size: 2.8 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…