-
Notifications
You must be signed in to change notification settings - Fork 765
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
【Hackathon 7th No.41】NO.41 为 Paddle 代码转换工具新增 API 转换规则(第 8 组) #6887
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第8组只有这一个API吗
|
那你在PR描述里,先标注一个 -PART1 |
@@ -0,0 +1,7 @@ | |||
## [功能缺失 ]torch.distributions.constraints.Constraint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不是功能缺失,仔细查阅paddle源码,以源代码为准
@@ -0,0 +1,7 @@ | |||
## [ 功能缺失 ]torch.distributions.transforms.PositiveDefiniteTransform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的好的,目前正在修改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经全都弄好了,请review
| --------- | ------------ | ------------------------------------------------------------------------------------ | | ||
| median | loc | 输入 Tensor,仅参数名不一致。 | | ||
| sigma | scale | 输入 Tensor,仅参数名不一致。 | | ||
| * | - | 其他参数 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 表示后面为指定关键字参数,不代表某个形参。这个去学习下相关的python语法。
| ------- | ------------ | ----------------------------- | | ||
| p | probs | 输入 Tensor,仅参数名不一致。 | | ||
|
||
| * | - | 其他参数 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,先查阅python相关语法
### [paddle.Tensor._is_inference](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html) | ||
|
||
```python | ||
paddle.Tensor._is_inference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
抱歉,这个是我搞错了,他是CompiledProgram类的属性
|
||
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 | ||
|
||
### 参数映射 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
组合实现有参数映射吗??认真查阅模板
| dim | dim | 表示输入的参数。 | | ||
| concentration | concentration | 表示输入的参数。 | | ||
| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | | ||
| - | sample_method | pytorch无此参数,保持默认即可。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddle保持默认即可
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
开发注意事项:
- 务必按照 映射文档模板 编写,一比一对照编写(可适当补充内容但不能减少内容),提交review前先自查一遍
- 本次放出来的API,内部已初步分析过,基本上都有相关功能,功能缺失的可能性较小。需尽可能去寻找组合替代实现,判定为功能缺失要慎重,除非paddle完全无相类似功能
- 先写好映射文档,再根据合入的文档来实现Matcher,注意不要出现文档与Matcher的diff。如果后面实现Matcher时,发现文档有误,需及时返工更正文档
@@ -0,0 +1,15 @@ | |||
## [ 无参数 ]torch.Tensor.is_inference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加一个 torch.is_inference.md
的文档吧,这两个API是一样的
有个问题:这个看起来和stop_gradient不是完全一致的,如果没有更好的替代实现,就在文档里注明是近似实现吧,至少让读者知道存在差异
https://www.cnblogs.com/ToryRegulus/p/18141257
@@ -0,0 +1,22 @@ | |||
## [ 仅参数名不一致 ]torch.Tensor.geometric_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
torch参数更多
x.random_(from=0, to=10) | ||
|
||
# Paddle 写法 | ||
paddle.assign(paddle.cast(paddle.randint(low=0, high=2, shape=x.shape), dtype='float32'), x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddle.Tensor.uniform_ 能否实现?
尽量找更好的组合
### [paddle.distributed.shard_optimizer](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/distributed/shard_optimizer_cn.html) | ||
|
||
```python | ||
paddle.distributed.shard_optimizer(optimizer, shard_fn=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个和 paddle.distributed.fleet.distributed_optimizer
哪个更能对应上?
### [paddle.distributed.rpc.rpc_async](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/rpc/rpc_async_cn.html#rpc-async) | ||
|
||
```python | ||
paddle.distributed.rpc.rpc_async(to, fn, args=None, kwargs=None, timeout=- 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeout=-1)
paddle.distribution.constraint.Constraint() | ||
``` | ||
|
||
功能一致,无参数。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上面的torch签名是无参数??
|
||
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 | ||
|
||
### 参数映射 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
组合替代实现 不需要参数映射
PaddlePaddle/PaConvert#495 |
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| --------- | ------------ | ------------------------------------------------------------------------------------ | | ||
| median | loc | 输入 Tensor,仅参数名不一致。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数功能简述,是不是都不对
| PyTorch | PaddlePaddle | 备注 | | ||
| --------- | ------------ | ------------------------------------------------------------------------------------ | | ||
| median | loc | 输入 Tensor,仅参数名不一致。 | | ||
| sigma | scale | 输入 Tensor,仅参数名不一致。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数功能简述,是不是都不对
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ----------------------------- | | ||
| p | probs | 输入 Tensor,仅参数名不一致。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数功能简述,是不是都不对
paddle.Tensor.stop_gradient | ||
``` | ||
|
||
两者功能一致,无参数。 `is_inference` 会强制关闭梯度记录。并且不能在中途设置梯度,`Paddle` 为近似实现。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stop_gradient也解释下。你需要证明清楚是近似实现
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ----------------------------------------------------------- | | ||
| from | min | 最小值 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没写清楚
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ----------------------------------------------------------- | | ||
| from | min | 最小值 | | ||
| to | max | 最大值 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没写清楚
| optimizer_class | optimizer | 优化器。 | | ||
| params_rref | - | 初始化方法,paddle 无此参数,需要转写方式。 | | ||
| args | - | 优化器实例化参数。 | | ||
| kwargs | - | 优化器实例化参数 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是字典参数
torch.is_inference(input) | ||
``` | ||
|
||
Paddle 无此 API,需要组合是实现。 `is_inference` 会强制关闭梯度记录。并且不能在中途设置梯度,`Paddle` 为近似实现。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写一下paddle的stop_gradient的功能及两者差异,证明是近似实现
@@ -0,0 +1,19 @@ | |||
## [ 组合替代实现 ]torch.is_inference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这个写得和torch.Tensor.is_inference的分类和内容不一样,两者应该都是 无参数
y = PositiveDefiniteTransform()(tensor1) | ||
|
||
# Paddle 写法 | ||
T = tensor1.tril(-1) + tensor1.diagonal(-2, -1).exp().diag_embed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个你还是用x来表示,不然与下面的.T容易混淆
|
||
# Paddle 写法 | ||
T = tensor1.tril(-1) + tensor1.diagonal(-2, -1).exp().diag_embed() | ||
y = T @ T.mT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddle没有.mT
| concentration | concentration | 表示输入的参数。 | | ||
| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | | ||
| - | sample_method | pytorch 无此参数,paddle 保持默认即可。 | | ||
| 输出 | 输出 | pytorch 比 Paddle 多一个维度,需转写。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个写返回值
|
||
### 转写示例 | ||
|
||
```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
转写值需要写:转写的是谁
参考下其他API返回值的转写
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------------------------------------- | | ||
| df | df | 自由度,是一个正数。 | | ||
| loc | loc | 分布的均值位置, Paddle 中,若 df 为 Tensor 类型,则 loc 也应该为 Tensor 类型。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的描述不规范:
Paddle是什么样不重要,需要看torch是什么样,再看paddle的处理方案
| ------------- | ------------ | ------------------------------------------------------------------------------------- | | ||
| df | df | 自由度,是一个正数。 | | ||
| loc | loc | 分布的均值位置, Paddle 中,若 df 为 Tensor 类型,则 loc 也应该为 Tensor 类型。 | | ||
| scale | scale | 分布的标准差的比例, Paddle 中,若 df 为 Tensor 类型,则 scale 也应该为 Tensor 类型。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的描述不规范:
Paddle是什么样不重要,需要看torch是什么样,再看paddle的处理方案
paddle.Tensor.stop_gradient | ||
``` | ||
|
||
两者功能一致,无参数。 `is_inference` 会强制关闭梯度记录。并且不能在中途设置梯度,而 `stop_gradient` 仅为停止计算该算子梯度,可在中途重新设为 `True` ,`Paddle` 为近似实现。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
给个转写示例
torch.is_inference(x) | ||
|
||
# Paddle 写法 | ||
not x.stop_gradient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个和torch.Tensor.is_inference应该要对上,映射分类和转写示例都需要对上
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| --------- | ------------ | ------------------------------------------------------------------------------------ | | ||
| from | min | 随机数生成范围的起始值,仅参数名不一致。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from这个参数名确定吗?这个应该触发了python的关键字from
,应该会报错
已经改了,请review |
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------------------------------------- | | ||
| df | df | 自由度,是一个正数。 | | ||
| loc | loc | 分布的均值位置, Pytorch 中,可为 float 或 Tensor 类型,但在 Paddle 中, loc 应于 df 同类型。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段话有错别字
| ------------- | ------------ | ------------------------------------------------------------------------------------- | | ||
| df | df | 自由度,是一个正数。 | | ||
| loc | loc | 分布的均值位置, Pytorch 中,可为 float 或 Tensor 类型,但在 Paddle 中, loc 应于 df 同类型。 | | ||
| scale | scale | 分布的标准差的比例, Pytorch 中,可为 float 或 Tensor 类型,但在 Paddle 中, scale 应于 df 同类型。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段话有错别字
y = torch.distributions.lkj_cholesky.LKJCholesky(dim=3, concentration=torch.tensor([1.0])).sample() | ||
|
||
# Paddle 写法 | ||
y = paddle.unsqueeze(paddle.distribution.LKJCholesky(dim=3, concentration=paddle.to_tensor([1.0]).sample(), axis=0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以分两行写
|
||
# Paddle 写法 | ||
x = paddle.to_tensor(3) | ||
y = paddle.reshape(paddle.distribution.StudentT(df=x, loc = paddle.to_tensor(0.0), scale=paddle.to_tensor(1.0)).sample(), x.shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以分多行写,目前写的不够直观
已经改好了,请review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.