mirror of
https://github.com/pytorch/pytorch.git
synced 2026-10-28 18:56:51 +08:00
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
10 KiB
10 KiB
myst
| myst | ||||||
|---|---|---|---|---|---|---|
|
Functional API
The torch::nn::functional namespace provides stateless versions of neural
network operations. Unlike module classes, functional operations do not hold
learnable parameters — you pass weights explicitly.
When to use functional vs modules:
- Use modules (
torch::nn::Conv2d) when you need learnable parameters managed automatically (training, saving, loading). - Use functional (
torch::nn::functional::conv2d) when you already have weights as tensors, or for operations without parameters (e.g.,relu).
#include <torch/nn/functional.h>
namespace F = torch::nn::functional;
// Stateless activation — no module needed
auto output = F::relu(input);
// Convolution with explicit weight tensor
auto output = F::conv2d(input, weight, F::Conv2dFuncOptions().stride(1).padding(1));
// Softmax along a dimension
auto probs = F::softmax(logits, F::SoftmaxFuncOptions(/*dim=*/1));
Activation Functions
Convolution Functions
Pooling Functions
Linear Functions
Dropout Functions
Embedding Functions
Normalization Functions
Loss Functions
Distance Functions
Vision Functions
Fold/Unfold
Functional Options Structs
Each functional operation that takes configuration uses a corresponding options
struct. The naming convention is <Operation>FuncOptions.
Activation Options:
Convolution Options:
Pooling Options:
Other Options: