Skip to content

Commit

Permalink
Add api_difference (#6119)
Browse files Browse the repository at this point in the history
  • Loading branch information
co63oc authored Aug 25, 2023
1 parent bc8d5cb commit 09e2032
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.nn.Module.get_buffer

### [torch.nn.Module.get_buffer](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.get_buffer)

```python
torch.nn.Module.get_buffer(target)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# Pytorch 写法
module.get_buffer("target")

# Paddle 写法
getattr(module, "target")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.nn.Module.get_parameter

### [torch.nn.Module.get_parameter](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.get_parameter)

```python
torch.nn.Module.get_parameter(target)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# Pytorch 写法
module.get_parameter("target")

# Paddle 写法
getattr(module, "target")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.nn.Module.get_submodule

### [torch.nn.Module.get_submodule](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.get_submodule)

```python
torch.nn.Module.get_submodule(target)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# Pytorch 写法
module.get_submodule("target")

# Paddle 写法
getattr(module, "target")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## [仅参数名不一致]torch.nn.Module.register_parameter

### [torch.nn.Module.register_parameter](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.register_parameter)

```python
torch.nn.Module.register_parameter(name, param)
```

### [paddle.nn.Layer.add_parameter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#add-parameter-name-parameter)

```python
paddle.nn.Layer.add_parameter(name, parameter)
```

两者功能一致,仅参数名不一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | -------------------------------- |
| name | name | 参数名。 |
| param | parameter | Parameter 实例,仅参数名不一致。 |

0 comments on commit 09e2032

Please sign in to comment.