Skip to content

Commit b49c513

Browse files
authored
Fix docs2 (#6900)
* fix-docs * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2 * fix-docs2
1 parent a4b9de1 commit b49c513

File tree

6 files changed

+139
-0
lines changed

6 files changed

+139
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## [ 组合替代实现 ]torch.Tensor.addcmul_
2+
3+
### [torch.Tensor.addcmul_](https://pytorch.org/docs/stable/generated/torch.Tensor.addcmul_.html#torch-tensor-addcmul)
4+
```python
5+
torch.Tensor.addcmul_(tensor1, tensor2, *, value=1)
6+
```
7+
8+
用于实现矩阵 `tensor1` 与矩阵 `tensor2` 相乘,再加上输入 `input` ,公式为:
9+
10+
$ out = input + value * tensor1 * tensor2 $
11+
12+
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。
13+
14+
### 转写示例
15+
16+
```python
17+
# PyTorch 写法
18+
input.addcmul_(tensor1, tensor2, value=value)
19+
20+
# Paddle 写法
21+
input.add_(value * tensor1 * tensor2)
22+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## [ 组合替代实现 ]torch.autograd.Variable
2+
3+
### [torch.autograd.Variable](https://pytorch.org/docs/stable/autograd.html#variable-deprecated)
4+
```python
5+
torch.autograd.Variable(data, requires_grad=False)
6+
```
7+
8+
用于自动求导的类,它封装了一个 torch.Tensor 并记录了关于它的操作历史,以便后续进行梯度计算。
9+
10+
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。
11+
12+
### 转写示例
13+
14+
```python
15+
# PyTorch 写法
16+
torch.autograd.Variable(data, requires_grad=False)
17+
18+
# Paddle 写法
19+
data.stop_gradient = not False
20+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## [ 组合替代实现 ]torch.detach
2+
3+
### [torch.detach](https://pytorch.org/docs/stable/autograd.html#variable-deprecated)
4+
```python
5+
torch.detach(input)
6+
```
7+
8+
用于创建一个新的张量,该张量与原始张量共享相同的数据,但不再参与梯度计算。
9+
10+
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。
11+
12+
### 转写示例
13+
14+
```python
15+
# PyTorch 写法
16+
torch.detach(input=data)
17+
18+
# Paddle 写法
19+
data.detach()
20+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## [ 组合替代实现 ]torch.hub.load_state_dict_from_url
2+
3+
### [torch.hub.load_state_dict_from_url](https://pytorch.org/docs/stable/hub.html#torch.hub.load_state_dict_from_url)
4+
```python
5+
torch.hub.load_state_dict_from_url(url, model_dir=None, map_location=None, progress=True, check_hash=False, file_name=None, weights_only=False)
6+
```
7+
8+
在给定的 URL 处加载 Torch 序列化对象
9+
10+
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。
11+
12+
### 转写示例
13+
14+
```python
15+
# PyTorch 写法
16+
torch.hub.load_state_dict_from_url(url)
17+
18+
# Paddle 写法
19+
paddle.load(paddle.utils.download.get_weights_path_from_url(url))
20+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## [ 组合替代实现 ]torch.multiprocessing.cpu_count
2+
3+
### [torch.multiprocessing.cpu_count](https://github.com/pytorch/pytorch/blob/main/torch/multiprocessing/__init__.py)
4+
```python
5+
torch.multiprocessing.cpu_count()
6+
```
7+
8+
获取系统上可用的 CPU 核心数。
9+
10+
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。
11+
12+
### 转写示例
13+
14+
```python
15+
# PyTorch 写法
16+
torch.multiprocessing.cpu_count()
17+
18+
# Paddle 写法
19+
import os
20+
os.cpu_count()
21+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## [ 输入参数用法不一致 ]torch.sparse.FloatTensor
2+
3+
### [torch.sparse.FloatTensor](https://pytorch.org/docs/stable/generated/torch.cuda.comm.broadcast.html#torch.cuda.comm.broadcast)
4+
5+
```python
6+
torch.sparse.FloatTensor(indices, values, size, *, device=None)
7+
```
8+
9+
### [paddle.sparse.sparse_coo_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/sparse_coo_tensor_cn.html#sparse-coo-tensor)
10+
11+
```python
12+
paddle.sparse.sparse_coo_tensor(indices, values, shape=None, dtype=None, place=None, stop_gradient=True)
13+
```
14+
15+
其中 PyTorch 与 Paddle 参数不一致,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | ------------------------------------------------------------ |
21+
| indices | indices | 初始化 tensor 的数据。 |
22+
| values | values | 初始化 tensor 的数据。 |
23+
| size | shape | 稀疏 Tensor 的形状,仅参数名不一致。 |
24+
| device | place | 表示 Tensor 存放设备位置,输入用法不一致,需要转写。 |
25+
| - | dtype | 创建 tensor 的数据类型。PyTorch 无此参数,Paddle 保持默认即可。 |
26+
| - | stop_gradient | 是否阻断 Autograd 的梯度传导。PyTorch 无此参数,Paddle 保持默认即可。 |
27+
### 转写示例
28+
29+
#### device:输出数据类型
30+
31+
```python
32+
# PyTorch 写法
33+
torch.sparse.FloatTensor(i, v, torch.Size([2, 3]), device='cpu')
34+
35+
# Paddle 写法
36+
paddle.sparse.sparse_coo_tensor(i, v, [2, 3], place="cpu")

0 commit comments

Comments
 (0)