Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update codeblock language type #6541

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.arctanh](https://pytorch.org/docs/stable/generated/torch.Tensor.arctanh.html#torch.Tensor.arctanh)

```
```python
torch.Tensor.arctanh()
```

### [paddle.Tensor.atanh]()

```
```python
paddle.Tensor.atanh()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.arctanh_](https://pytorch.org/docs/stable/generated/torch.Tensor.arctanh_.html)

```
```python
torch.Tensor.arctanh_()
```

### [paddle.Tensor.atanh_]()

```
```python
paddle.Tensor.atanh_()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.atanh](https://pytorch.org/docs/stable/generated/torch.Tensor.atanh.html#torch.Tensor.atanh)

```
```python
torch.Tensor.atanh()
```

### [paddle.Tensor.atanh]()

```
```python
paddle.Tensor.atanh()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.atanh_](https://pytorch.org/docs/stable/generated/torch.Tensor.atanh_.html#torch.Tensor.atanh_)

```
```python
torch.Tensor.atanh_()
```

### [paddle.Tensor.atanh_]()

```
```python
paddle.Tensor.atanh_()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### [torch.Tensor.is_contiguous](https://pytorch.org/docs/stable/generated/torch.Tensor.is_contiguous.html#torch-tensor-is-contiguous)

```
```python
torch.Tensor.is_contiguous(memory_format=torch.contiguous_format)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

### [torch.Tensor.is_cuda](https://pytorch.org/docs/stable/generated/torch.Tensor.is_cuda.html?highlight=is_cuda#torch.Tensor.is_cuda)

```
```python
torch.Tensor.is_cuda
```

判断 Tensor 是否在 gpu 上,PaddlePaddle 目前无对应 API,可使用如下代码组合替代实现:

### 转写示例

```
```python
# PyTorch 写法
d = torch.Tensor([1,2,3])
d.is_cuda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ paddle.Tensor.is_sparse()
两者功能一致,但使用方式不一致,前者可以直接访问属性,后者需要调用方法,具体如下:

### 转写示例
```

```python
# torch 版本可以直接访问属性
# x = torch.rand(3)
# print(x.is_sparse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ torch.Tensor.scatter(dim, index, src, reduce=None)

```python
paddle.Tensor.put_along_axis(indices, values, axis, reduce="assign", include_self=True, broadcast=True)

```

其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ torch.Tensor.scatter_(dim, index, src)

```python
paddle.Tensor.put_along_axis_(index, value, axis, reduce="assign", include_self=True)

```

其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.take](https://pytorch.org/docs/stable/generated/torch.Tensor.take.html#torch.Tensor.take)

```
```python
torch.Tensor.take(indices)
```

### [paddle.Tensor.take](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#take-index-mode-raise-name-none)

```
```python
paddle.Tensor.take(index, mode='raise', name=None)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.tan](https://pytorch.org/docs/stable/generated/torch.Tensor.tan.html#torch.Tensor.tan)

```
```python
torch.Tensor.tan()
```

### [paddle.Tensor.tan]()

```
```python
paddle.Tensor.tan()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.tanh](https://pytorch.org/docs/stable/generated/torch.Tensor.tanh.html#torch.Tensor.tanh)

```
```python
torch.Tensor.tanh()
```

### [paddle.Tensor.tanh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tanh-name-none)

```
```python
paddle.Tensor.tanh()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.tanh_](https://pytorch.org/docs/stable/generated/torch.Tensor.tanh_.html#torch.Tensor.tanh_)

```
```python
torch.Tensor.tanh_()
```

### [paddle.Tensor.tanh_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id22)

```
```python
paddle.Tensor.tanh_()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.tile](https://pytorch.org/docs/stable/generated/torch.Tensor.tile.html#torch.Tensor.tile)

```
```python
torch.Tensor.tile(*reps)
```

### [paddle.Tensor.tile](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tile-repeat-times-name-none)

```
```python
paddle.Tensor.tile(repeat_times, name=None)
```

Expand All @@ -24,7 +24,7 @@ paddle.Tensor.tile(repeat_times, name=None)

#### ***reps: 维度复制次数**

```
```python
# PyTorch 写法
x = torch.tensor([1, 2, 3])
x.tile(2,3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.to_sparse](https://pytorch.org/docs/stable/generated/torch.Tensor.to_sparse.html#torch.Tensor.to_sparse)

```
```python
torch.Tensor.to_sparse(sparseDims)
```

### [paddle.Tensor.to_sparse_coo]()

```
```python
paddle.Tensor.to_sparse_coo(sparseDims)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.tolist](https://pytorch.org/docs/stable/generated/torch.Tensor.tolist.html#torch.Tensor.tolist)

```
```python
torch.Tensor.tolist()
```

### [paddle.Tensor.tolist](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tolist)

```
```python
paddle.Tensor.tolist()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### [torch.Tensor.topk](https://pytorch.org/docs/stable/generated/torch.Tensor.topk.html#torch.Tensor.topk)

```
```python
torch.Tensor.topk(k, dim=None, largest=True, sorted=True)
```

### [paddle.Tensor.topk](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#topk-k-axis-none-largest-true-sorted-true-name-none)

```
```python
paddle.Tensor.topk(k, axis=None, largest=True, sorted=True, name=None)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ torch.Tensor.unsqueeze(dim)

### [paddle.Tensor.unsqueeze](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#unsqueeze-axis-name-none)

```
```python
paddle.Tensor.unsqueeze(axis, name=None)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ paddle.nn.functional.cross_entropy(input,

### 转写示例
#### size_average

size_average 为 True

```python
# PyTorch 写法
torch.nn.functional.cross_entropy(x,y,size_average=True)

# Paddle 写法
paddle.nn.functional.cross_entropy(x,y,reduction='mean')

```

size_average 为 False

```python
# PyTorch 写法
torch.nn.functional.cross_entropy(x,y,size_average=False)
Expand All @@ -63,7 +65,9 @@ paddle.nn.functional.cross_entropy(x,y,reduction='sum')
```

#### reduce

reduce 为 True

```python
# PyTorch 写法
torch.nn.functional.cross_entropy(x,y,reduce=True)
Expand All @@ -73,6 +77,7 @@ paddle.nn.BCEWithLogitsLoss(reduction='mean')
```

reduce 为 False

```python
# PyTorch 写法
torch.nn.functional.cross_entropy(x,y,reduce=False)
Expand All @@ -82,7 +87,9 @@ paddle.nn.BCEWithLogitsLoss(reduction='none')
```

#### reduction

reduction 为'none'

```python
# PyTorch 写法
torch.nn.functional.cross_entropy(x,y,reduction='none')
Expand All @@ -92,6 +99,7 @@ paddle.nn.functional.cross_entropy(x,y,reduction='none')
```

reduction 为'mean'

```python
# PyTorch 写法
torch.nn.functional.cross_entropy(x,y,reduction='mean')
Expand All @@ -101,6 +109,7 @@ paddle.nn.functional.cross_entropy(x,y,reduction='mean')
```

reduction 为'sum'

```python
# PyTorch 写法
torch.nn.functional.cross_entropy(x,y,reduction='sum')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### [torch.nn.functional.kl_div](https://pytorch.org/docs/stable/generated/torch.nn.functional.kl_div.html?highlight=kl_div#torch.nn.functional.kl_div)

```
```python
torch.nn.functional.kl_div(input,
target,
size_average=None,
Expand All @@ -13,7 +13,7 @@ torch.nn.functional.kl_div(input,

### [paddle.nn.functional.kl_div](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/kl_div_cn.html)

```
```python
paddle.nn.functional.kl_div(input,
label,
reduction='mean')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ torch.nn.BCELoss(weight=w, size_average=True)

# Paddle 写法
paddle.nn.BCELoss(weight=w, reduction='mean')

```

size_average 为 False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ torch.nn.BCEWithLogitsLoss(weight=w, size_average=True)

# Paddle 写法
paddle.nn.BCEWithLogitsLoss(weight=w, reduction='mean')

```

size_average 为 False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ paddle.nn.BatchNorm2D(num_features,
data_format='NCHW',
use_global_stats=True,
name=None)

```

两者功能一致但参数不一致,部分参数名不同,具体如下:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ torch.nn.CrossEntropyLoss(weight=w, size_average=True)

# Paddle 写法
paddle.nn.CrossEntropyLoss(weight=w, reduction='mean')

```

size_average 为 False
Expand Down
Loading