diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh.md index fb62a8d0cce..f3da848166e 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh.md @@ -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() ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh_.md index 34e442b56ac..74279293b62 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh_.md @@ -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_() ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh.md index bca7344dffc..5489807bbc2 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh.md @@ -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() ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh_.md index 9a543f502d3..8e7f20a39ee 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh_.md @@ -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_() ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_contiguous.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_contiguous.md index 8b79a71875a..e5b1adab428 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_contiguous.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_contiguous.md @@ -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) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_cuda.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_cuda.md index ce8cf751514..a95be80ad47 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_cuda.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_cuda.md @@ -2,7 +2,7 @@ ### [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 ``` @@ -10,7 +10,7 @@ torch.Tensor.is_cuda ### 转写示例 -``` +```python # PyTorch 写法 d = torch.Tensor([1,2,3]) d.is_cuda diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse.md index e1092e488d6..1393779c8ea 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse.md @@ -15,7 +15,8 @@ paddle.Tensor.is_sparse() 两者功能一致,但使用方式不一致,前者可以直接访问属性,后者需要调用方法,具体如下: ### 转写示例 -``` + +```python # torch 版本可以直接访问属性 # x = torch.rand(3) # print(x.is_sparse) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md index 6144608a3f4..3a0b3197474 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md @@ -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 支持更多其他参数,具体如下: diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_.md index 8540fd77e82..af8d055b1f8 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_.md @@ -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 支持更多其他参数,具体如下: diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take.md index 19619df5a26..3c4467b85b1 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take.md @@ -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) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan.md index b798da1014a..ed6c896330a 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan.md @@ -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() ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh.md index 9e88bdfb03e..514297cf873 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh.md @@ -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() ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh_.md index 6ad79d7d099..80bdd1e2223 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh_.md @@ -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_() ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tile.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tile.md index 8159494fb83..94f44d94e11 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tile.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tile.md @@ -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) ``` @@ -24,7 +24,7 @@ paddle.Tensor.tile(repeat_times, name=None) #### ***reps: 维度复制次数** -``` +```python # PyTorch 写法 x = torch.tensor([1, 2, 3]) x.tile(2,3) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_sparse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_sparse.md index 6277def49d0..277b09b035e 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_sparse.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_sparse.md @@ -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) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tolist.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tolist.md index e4815b6868f..616cced334e 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tolist.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tolist.md @@ -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() ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.topk.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.topk.md index b0871b48911..93786434dab 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.topk.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.topk.md @@ -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) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze.md index f49c45d3fc9..34599af5637 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze.md @@ -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) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cross_entropy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cross_entropy.md index 0dc8a334698..7d0074b3400 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cross_entropy.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cross_entropy.md @@ -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) @@ -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) @@ -73,6 +77,7 @@ paddle.nn.BCEWithLogitsLoss(reduction='mean') ``` reduce 为 False + ```python # PyTorch 写法 torch.nn.functional.cross_entropy(x,y,reduce=False) @@ -82,7 +87,9 @@ paddle.nn.BCEWithLogitsLoss(reduction='none') ``` #### reduction + reduction 为'none' + ```python # PyTorch 写法 torch.nn.functional.cross_entropy(x,y,reduction='none') @@ -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') @@ -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') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.kl_div.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.kl_div.md index 10ef6185f37..c476ce903ce 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.kl_div.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.kl_div.md @@ -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, @@ -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') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md index 571be10ee30..a79a175e155 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md @@ -34,7 +34,6 @@ torch.nn.BCELoss(weight=w, size_average=True) # Paddle 写法 paddle.nn.BCELoss(weight=w, reduction='mean') - ``` size_average 为 False diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md index d0d36cd79b9..c1a5527a3e5 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md @@ -37,7 +37,6 @@ torch.nn.BCEWithLogitsLoss(weight=w, size_average=True) # Paddle 写法 paddle.nn.BCEWithLogitsLoss(weight=w, reduction='mean') - ``` size_average 为 False diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm2d.md index 48b7a38323a..bffb8efdb2d 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm2d.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm2d.md @@ -21,7 +21,6 @@ paddle.nn.BatchNorm2D(num_features, data_format='NCHW', use_global_stats=True, name=None) - ``` 两者功能一致但参数不一致,部分参数名不同,具体如下: diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md index 40f8fc63a77..2b4b4514fbf 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md @@ -43,7 +43,6 @@ torch.nn.CrossEntropyLoss(weight=w, size_average=True) # Paddle 写法 paddle.nn.CrossEntropyLoss(weight=w, reduction='mean') - ``` size_average 为 False diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MSELoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MSELoss.md index 15582f849ce..280f7e9c9b6 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MSELoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MSELoss.md @@ -23,6 +23,7 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: ### 转写示例 #### size_average + ```python # Paddle 写法 torch.nn.MSELoss(size_average=True) @@ -32,17 +33,19 @@ paddle.nn.MSELoss(reduction='mean') ``` #### size_average + size_average 为 True + ```python # PyTorch 写法 torch.nn.MSELoss(size_average=True) # Paddle 写法 paddle.nn.MSELoss(reduction='mean') - ``` size_average 为 False + ```python # PyTorch 写法 torch.nn.MSELoss(size_average=False) @@ -52,7 +55,9 @@ paddle.nn.MSELoss(reduction='sum') ``` #### reduce + reduce 为 True + ```python # PyTorch 写法 torch.nn.MSELoss(reduce=True) @@ -62,6 +67,7 @@ paddle.nn.MSELoss(reduction='mean') ``` reduce 为 False + ```python # PyTorch 写法 torch.nn.MSELoss(reduce=False) @@ -71,7 +77,9 @@ paddle.nn.MSELoss(reduction='none') ``` #### reduction + reduction 为'none' + ```python # PyTorch 写法 torch.nn.MSELoss(reduction='none') @@ -81,6 +89,7 @@ paddle.nn.MSELoss(reduction='none') ``` reduction 为'mean' + ```python # PyTorch 写法 torch.nn.MSELoss(reduction='mean') @@ -90,6 +99,7 @@ paddle.nn.MSELoss(reduction='mean') ``` reduction 为'sum' + ```python # PyTorch 写法 torch.nn.MSELoss(reduction='sum') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md index 110d963bf4e..3cbfb0407ab 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md @@ -41,17 +41,19 @@ paddle.nn.NLLLoss(reduction='mean') ``` #### size_average + size_average 为 True + ```python # PyTorch 写法 torch.nn.NLLLoss(weight=w, size_average=True) # Paddle 写法 paddle.nn.NLLLoss(weight=w, reduction='mean') - ``` size_average 为 False + ```python # PyTorch 写法 torch.nn.NLLLoss(weight=w, size_average=False) @@ -61,7 +63,9 @@ paddle.nn.NLLLoss(weight=w, reduction='sum') ``` #### reduce + reduce 为 True + ```python # PyTorch 写法 torch.nn.NLLLoss(weight=w, reduce=True) @@ -71,6 +75,7 @@ paddle.nn.NLLLoss(weight=w, reduction='mean') ``` reduce 为 False + ```python # PyTorch 写法 torch.nn.NLLLoss(weight=w, reduce=False) @@ -80,7 +85,9 @@ paddle.nn.NLLLoss(weight=w, reduction='none') ``` #### reduction + reduction 为'none' + ```python # PyTorch 写法 torch.nn.NLLLoss(weight=w, reduction='none') @@ -90,6 +97,7 @@ paddle.nn.NLLLoss(weight=w, reduction='none') ``` reduction 为'mean' + ```python # PyTorch 写法 torch.nn.NLLLoss(weight=w, reduction='mean') @@ -99,6 +107,7 @@ paddle.nn.NLLLoss(weight=w, reduction='mean') ``` reduction 为'sum' + ```python # PyTorch 写法 torch.nn.NLLLoss(weight=w, reduction='sum') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md index 3393da06f6c..0fd6925b53e 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md @@ -43,7 +43,6 @@ torch.nn.SmoothL1Loss(size_average=True) # Paddle 写法 paddle.nn.SmoothL1Loss(reduction='mean') - ``` size_average 为 False diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax2d.md index ec82bd2dd75..ef2be99fdab 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax2d.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax2d.md @@ -22,7 +22,7 @@ paddle.nn.Softmax(axis=-1) ### 转写示例 -``` +```python # PyTorch 写法 cri = torch.nn.Softmax2d() cri(input) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acos.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acos.md index 0f5f14e84e8..32e723a4e0d 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acos.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acos.md @@ -34,5 +34,4 @@ torch.acos(torch.tensor([0.3348, -0.5889]), out=y) # Paddle 写法 paddle.assign(paddle.acos(paddle.to_tensor([0.3348, -0.5889])), y) - ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter.md index 99928ebd4ce..fb4ba91af63 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter.md @@ -10,7 +10,6 @@ torch.scatter(input,dim, index, src, reduce=None,out=None) ```python paddle.put_along_axis(arr,indices, values, axis, reduce="assign", include_self=True, broadcast=True) - ``` 其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: @@ -31,6 +30,7 @@ paddle.put_along_axis(arr,indices, values, axis, reduce="assign", include_self=T ### 转写示例 #### out:指定输出 + ```python # PyTorch 写法 index = torch.tensor([[0],[1],[2]]) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_printoptions.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_printoptions.md index 3a088fb8a72..f976612710c 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_printoptions.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_printoptions.md @@ -29,7 +29,7 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: #### profile:预设风格,设置为 `default`。 -``` +```python # PyTorch 写法 torch.set_printoptions(profile='default') @@ -39,7 +39,7 @@ paddle.set_printoptions(precision=4, threshold=1000, edgeitems=3, linewidth=80) #### profile:预设风格,设置为 `short`。 -``` +```python # PyTorch 写法 torch.set_printoptions(profile='short') @@ -49,7 +49,7 @@ paddle.set_printoptions(precision=2, threshold=1000, edgeitems=2, linewidth=80) #### profile:预设风格,设置为 `full`。 -``` +```python # PyTorch 写法 torch.set_printoptions(profile='full') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.WeightedRandomSampler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.WeightedRandomSampler.md index c479c746a09..b64daa8a6ef 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.WeightedRandomSampler.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.WeightedRandomSampler.md @@ -2,7 +2,7 @@ ### [torch.utils.data.WeightedRandomSampler](https://pytorch.org/docs/stable/data.html#torch.utils.data.WeightedRandomSampler) -``` +```python torch.utils.data.WeightedRandomSampler(weights, num_samples, replacement=True, @@ -11,7 +11,7 @@ torch.utils.data.WeightedRandomSampler(weights, ### [paddle.io.WeightedRandomSampler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/WeightedRandomSampler_cn.html#paddle.io.WeightedRandomSampler) -``` +```python paddle.io.WeightedRandomSampler(weights, num_samples, replacement=True) diff --git a/docs/guides/model_convert/convert_from_pytorch/validate_mapping_in_api_difference.py b/docs/guides/model_convert/convert_from_pytorch/validate_mapping_in_api_difference.py index 3e556bc9fd0..b01cbc292f6 100644 --- a/docs/guides/model_convert/convert_from_pytorch/validate_mapping_in_api_difference.py +++ b/docs/guides/model_convert/convert_from_pytorch/validate_mapping_in_api_difference.py @@ -112,7 +112,7 @@ def get_meta_from_diff_file(filepath): paddle_pattern = re.compile( r"^### +\[ *(?Ppaddle.[^\]]+)\](\((?P[^\)]*)\))?$" ) - code_begin_pattern = re.compile(r"^```(python)?$") + code_begin_pattern = re.compile(r"^```python$") code_pattern = re.compile(r"^(?P(paddle|torch)[^\( ]+)(.*?)$") code_end_pattern = re.compile(r"^```$") @@ -247,10 +247,29 @@ def get_meta_from_diff_file(filepath): # print(state) # 允许的终止状态,解析完了 paddle_api 或者只有 torch_api - if state not in [ParserState.end, ParserState.wait_for_paddle_api]: - raise Exception( - f"Unexpected End State at {state} in parsing file: {filepath}, current meta: {meta_data}" - ) + # 这些映射类型必须要有对应的 paddle_api + if mapping_type in [ + "无参数", + "参数完全一致", + "仅参数名不一致", + "仅 paddle 参数更多", + "仅参数默认值不一致", + # type 2 + "torch 参数更多", + # type 3 + "返回参数类型不一致", + "参数不一致", + "参数用法不一致", + ]: + if state != ParserState.end: + raise Exception( + f"Unexpected End State at {state} in parsing file: {filepath}, current meta: {meta_data}" + ) + else: + if state not in [ParserState.end, ParserState.wait_for_paddle_api]: + raise Exception( + f"Unexpected End State at {state} in parsing file: {filepath}, current meta: {meta_data}" + ) return meta_data