---
title: Linear
description: "PyTorch的Linear用于创建全连接层，进行线性变换。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/KunpengHPCKit_developer_195.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/KunpengHPCKit_developer_195.html
indexId: 055fbabfaab8b1819d323ad9ed450794ebd98e0cf97fc5cec0a9ee01192e055567
---
# Linear

#### 接口功能

PyTorch的Linear用于创建全连接层，进行线性变换。


#### 函数原型

```
torch.nn.Linear(
in_features: int,
out_features: int,
bias: bool = True,
device=None,
dtype=None
)
```


#### 参数说明


**表1 参数说明**

| 参数 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| in\_features | int | 是 | 输入特征维度。 |
| out\_features | int | 是 | 输出特征维度。 |
| bias | bool | 否 | 是否包含偏置（默认True）。 |
| device | torch.device | 否 | 计算设备（如“cpu”，“cuda”）。 |
| dtype | torch.dtype | 否 | 权重数据类型（如torch.float16、torch.float32）。 |
