04.02

PyTorch, compile, and model files

skillmaxingInference EngineeringPyTorch, compile, and model files
Visual lesson

PyTorch, compile, and model files

Included with Pro · 4:54
Lessons · 1,270 words

When you download an open model, you get two things that matter: a small config.json that describes the architecture, and a set of *.safetensors shards that hold every weight as a named tensor. Nothing in those files runs. Code has to read the config, build the layers, pour the tensors into them, and then execute the math on a GPU. For almost every open model, that code is PyTorch.

From files on disk to a GPU
Figure 1From files on disk to a GPUThe config describes the architecture; the shards hold every weight by name.

By default PyTorch runs in eager mode: Python walks through the model one operation at a time, and each operation launches its own CUDA kernel. That is easy to debug and slow in two ways. Python adds overhead between every launch, and each small operation writes its result back to GPU memory before the next one reads it. torch.compile fixes both by capturing the whole sequence as a graph, fusing operations and picking kernels tuned for the GPU in front of it.

Pro

Continue reading

Pro unlocks every video lesson, the full notes, worked sizing and cost calculations, and runnable configs across the Inference Engineering course, from GPUs and kernels to quantization, speculative decoding, disaggregation and production autoscaling.

Unlock full access to
Python with AIInference EngineeringAI researchComplete system design
30% off with LAUNCH30first payment
Buy now
View all plans ·Already Pro? Sign in