Skip to content

映射文档 No.384-387 #6119

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

Merged
merged 1 commit into from
Aug 25, 2023
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
@@ -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 实例,仅参数名不一致。 |