mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
19da3da3d3
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
85 lines
1.6 KiB
Markdown
85 lines
1.6 KiB
Markdown
---
|
|
myst:
|
|
html_meta:
|
|
description: Linear layers in PyTorch C++ — Linear, Bilinear, and Flatten modules.
|
|
keywords: PyTorch, C++, Linear, Bilinear, Flatten, fully connected, dense layer
|
|
---
|
|
|
|
# Linear Layers
|
|
|
|
Linear layers apply affine transformations to input data: `y = xW^T + b`.
|
|
They are the building blocks of fully-connected networks and are used for
|
|
feature transformation, classification heads, and projection layers.
|
|
|
|
- **Linear**: Standard fully-connected layer
|
|
- **Bilinear**: Bilinear transformation of two inputs
|
|
- **Identity**: Pass-through layer (useful for skip connections)
|
|
- **Flatten/Unflatten**: Reshape tensors between convolutional and linear layers
|
|
|
|
## Linear
|
|
|
|
```{doxygenclass} torch::nn::Linear
|
|
:members:
|
|
:undoc-members:
|
|
```
|
|
|
|
```{doxygenclass} torch::nn::LinearImpl
|
|
:members:
|
|
:undoc-members:
|
|
```
|
|
|
|
**Example:**
|
|
|
|
```cpp
|
|
auto linear = torch::nn::Linear(torch::nn::LinearOptions(784, 256).bias(true));
|
|
auto output = linear->forward(input); // input: [N, 784]
|
|
```
|
|
|
|
## Bilinear
|
|
|
|
```{doxygenclass} torch::nn::Bilinear
|
|
:members:
|
|
:undoc-members:
|
|
```
|
|
|
|
```{doxygenclass} torch::nn::BilinearImpl
|
|
:members:
|
|
:undoc-members:
|
|
```
|
|
|
|
## Identity
|
|
|
|
```{doxygenclass} torch::nn::Identity
|
|
:members:
|
|
:undoc-members:
|
|
```
|
|
|
|
```{doxygenclass} torch::nn::IdentityImpl
|
|
:members:
|
|
:undoc-members:
|
|
```
|
|
|
|
## Flatten
|
|
|
|
```{doxygenclass} torch::nn::Flatten
|
|
:members:
|
|
:undoc-members:
|
|
```
|
|
|
|
```{doxygenclass} torch::nn::FlattenImpl
|
|
:members:
|
|
:undoc-members:
|
|
```
|
|
|
|
## Unflatten
|
|
|
|
```{doxygenclass} torch::nn::Unflatten
|
|
:members:
|
|
:undoc-members:
|
|
```
|
|
|
|
```{doxygenclass} torch::nn::UnflattenImpl
|
|
:members:
|
|
:undoc-members:
|
|
```
|