Skip to Content
基于scikit-learn和PyTorch的实践机器学习
book

基于scikit-learn和PyTorch的实践机器学习

by Aurélien Géron
October 2025
Intermediate to advanced
878 pages
12h 53m
Chinese
O'Reilly Media, Inc.
Content preview from 基于scikit-learn和PyTorch的实践机器学习

第 17 章 加速转换器

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

在第15章和第16 章中,我们构建了各种各样的变形器,从分类器、翻译器和聊天机器人,到视觉和多模态变形器。虽然变形程序用途广泛、功能强大,但它们远非完美无缺。尤其是在处理长输入序列时,它们的速度可能会非常慢。

幸运的是,我们已经开发出了许多技术来加快任何规模的变换器:

  • 为了加快生成式变换器的解码速度,我们将使用键/值缓存和推测解码,然后我们将快速了解几种并行化文本生成的方法。

  • 多头注意力(MHA)是变换器中计算成本最高的部分之一,为了加速多头注意力,我们将研究稀疏注意力、近似注意力、共享投影和 FlashAttention。

  • 为了加速处理多达数万亿个参数的大型变换器,我们将讨论专家混合(MoE)。

  • 为了高效地训练大型变换器,我们将讨论使用适配器进行参数高效微调(PEFT),这些适配器包括低链适配(LoRA)、激活检查点、序列打包、梯度累积和并行性。

提示

加快变换器速度的另一种方法是缩小变换器。这可以通过降低精度和量化来实现,附录 B 将对此进行讨论。

本章要介绍的技术相当多,而且相当高级,所以如果你是变压器的新手,可以暂时跳过本章,以后有需要时再来学习。这也是本章仅在https://homl.info 上提供的原因,以便为其他章节留出空间。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

雷达趋势观察:2025年9月

雷达趋势观察:2025年9月

Mike Loukides
编写整洁的Python代码(第2版)

编写整洁的Python代码(第2版)

Posts & Telecom Press, Mariano Anaya

Publisher Resources

ISBN: 0642572270117