Skip to Content
AI and ML for Coders in PyTorch
book

AI and ML for Coders in PyTorch

by Laurence Moroney
June 2025
Beginner to intermediate
444 pages
11h 32m
English
O'Reilly Media, Inc.
Content preview from AI and ML for Coders in PyTorch

Chapter 12. Concepts of Inference

In the previous chapters of this book, you focused on training models using PyTorch and on how to create models that manage images (aka Computer Vision), text content (aka NLP), and sequence modelling. For the rest of this book, you’ll cover a lot of content around using trained models to make predictions from new data (aka inference) and in particular using large generative models for text-to-text and text-to-image generative AI.

But before you jump into that, it’s important for you to understand the underlying data transfer technology. We’ve touched on it a little in the training chapters, but as you go deeper into ML—in either training or inference—it’s important for you to be able to understand the underlying concepts of tensors.

Ultimately, no matter what data type you have, you’ll convert it into tensors to pass it into the model. Similarly, no matter the data type in which you want to present answers from the model to your users, you’ll get them back as tensors as well!

In many cases, you’ll have helper functions, such as the transformers that you’ll see in Chapter 15 (which covers LLMs) and the diffusers that you’ll see in Chapter 19 (which handles image generation). And while you won’t be touching tensors with them, you’ll still be using them under the hood.

Tensors

A tensor is an array that can have any number of dimensions. Tensors are typically used to represent numerical data for deep-learning algorithms; they’re containers that ...

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

Generative AI with LangChain - Second Edition

Generative AI with LangChain - Second Edition

Ben Auffarth, Leonid Kuligin

Publisher Resources

ISBN: 9781098199166Errata Page