Exploring the PyTorch Code Style
00:00 Let’s explore PyTorch’s code style and function. PyTorch is based on Torch, which is a framework for doing fast computation that is written in C, and Torch has a Lua wrapper for constructing models.
00:16 Lua is a lightweight, high-level programming language. It has a straightforward syntax, is fast, and it’s cross-platform, so it means you can run it on a wide range of operating systems.
00:29 Fun fact, Lua has been used in games like World of Warcraft and Angry Birds. This Lua wrapper that you heard about before in the context of Torch is a tool that allows Torch to be used with the Lua programming language.
00:46 PyTorch wraps the same C backend in a Python interface, and the underlying low-level C is optimized for running Python code. That’s why PyTorch is fast.
00:59 By integrating PyTorch, you get better memory and optimization, more sensible error messages, finer grain control of model structure, more transparent model behavior, and better compatibility with NumPy.
01:16
Let’s get a sense of PyTorch’s code style. Here you can see a code snippet that takes two NumPy arrays, X
and Y
, creates a tensor for each array by calling torch.from_numpy
, taking in X
and Y
as input.
01:32
And finally, it multiplies them by using torch.mul()
. The final array is X
and Y
multiplied.
01:43 Does it seem familiar? You did the exact same thing using TensorFlow.
Become a Member to join the conversation.