Files
Svetlana Karslioglu 19da3da3d3 Restructure C++ docs (#174096)
The fix-cpp-build branch is a major restructuring that:

- Drops Exhale (which auto-generated API docs but caused OOM in CI) in favor of hand-written RST pages using Breathe directives
- Reorganizes notes into a hierarchical API reference with proper categories
- Adds new content: XPU docs, stable ABI docs, DeviceGuard/Stream docs
- Always runs Doxygen instead of gating on an env var

Pull Request resolved: https://github.com/pytorch/pytorch/pull/174096
Approved by: https://github.com/janeyx99, https://github.com/seemethere, https://github.com/albanD
2026-04-07 17:24:38 +00:00

1.9 KiB

myst
myst
html_meta
description keywords
Data transforms in PyTorch C++ — Stack, Normalize, Lambda, and Collate transforms for data pipelines. PyTorch, C++, transforms, Stack, Normalize, Lambda, Collate, data pipeline

Transforms

Transforms apply preprocessing to data samples, such as normalization or augmentation. They can be chained using the .map() method on datasets.

Transform (Base Class)

The base class for all transforms. Subclass this to create custom transforms.

:members:
:undoc-members:

BatchTransform (Base Class)

Base class for transforms that operate on entire batches.

:members:
:undoc-members:

TensorTransform

Base class for transforms that operate on tensors specifically.

:members:
:undoc-members:

Normalize

Normalizes tensors with a given mean and standard deviation.

:members:
:undoc-members:

Stack

Stacks a batch of tensors into a single tensor.

:members:
:undoc-members:

Example:

auto dataset = torch::data::datasets::MNIST("./data")
    .map(torch::data::transforms::Normalize<>(0.5, 0.5))
    .map(torch::data::transforms::Stack<>());

Lambda

:members:
:undoc-members:

TensorLambda

:members:
:undoc-members:

BatchLambda

:members:
:undoc-members:

Chaining Transforms

Transforms can be chained together using .map():

auto dataset = torch::data::datasets::MNIST("./data")
    .map(torch::data::transforms::Normalize<>(0.1307, 0.3081))
    .map(torch::data::transforms::Stack<>());