# PyTorch 中的 Channels Last 内存格式

- 原标题：Channels Last Memory Format in PyTorch
- 类型：教程
- 来源：docs.pytorch.org
- 发布时间：2023-01-01
- 首次精选：2026-10-29 23:09
- 分级：值得看
- 学习层级：深入
- 主题：[model-serving-compute](<https://oplearnx.com/md/topics/model-serving-compute.md>)（第 39 位）
- 原文链接：[https://docs.pytorch.org/tutorials/intermediate/memory\_format\_tutorial.html](<https://docs.pytorch.org/tutorials/intermediate/memory_format_tutorial.html>)
- 本站页面：[https://oplearnx.com/resources/pk\_f8b0fe8dd86e](<https://oplearnx.com/resources/pk_f8b0fe8dd86e>)

## 摘要

PyTorch 官方中级教程，介绍 channels last 内存格式是什么，以及如何用它提升某些算子的性能。正文说明该格式在保留 NCHW 维度顺序的前提下改变内存排列，使通道成为最密集的维度，并利用现有 strides 结构实现，例如 10x3x16x16 批次在该格式下 strides 为 \(768, 1, 48, 3\)；该格式仅针对 4D NCHW 张量实现，页面还给出连续格式与 channels last 格式之间的张量转换 API。前置条件为 PyTorch v1.5.0 和支持 CUDA 的 GPU。

---
来源：LearnMap · 学径（https://oplearnx.com）
