-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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.23】NO.23 为 Paddle 新增 ParameterDict API -part #68270
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
|
这个好像是需要你这里同意? |
|
python/paddle/nn/layer/container.py
Outdated
... tmp = self._helper.create_variable_for_type_inference('float32') | ||
... self._helper.append_op( | ||
... type="mul", | ||
... inputs={"X": x, | ||
... "Y": p}, | ||
... outputs={"Out": tmp}, | ||
... attrs={"x_num_col_dims": 1, | ||
... "y_num_col_dims": 1}) | ||
... x = tmp |
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.
please use public APIs instead of non-public APIs(self._helper.create_variable_for_type_inference
and self._helper.append_op
) in the example code. for example, x = paddle.multiply(x, p)
or x = x * p
|
||
def forward(self, x): | ||
for i, (key, _) in enumerate(self.params): | ||
x = _legacy_C_ops.mul(x, self.params[key]) |
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.
it better to use public API to increase maintainability, e.g. paddle.matmul
?
Yes, adding a public API requires confirmation. You don't need to handle this CI temporarily. Once you solve other problems and approved, PR-CI-Static-Check will pass |
please add link of rfc and docs in description above. |
已经将相应的链接加上去了,需要修改的也已经修改完毕。劳烦再review一下。另外也请review一下这个#68268 我觉得ci似乎有问题,我在 test/legacy_test/test_audio_functions.py 中的修改并没有执行,导致我一开始的单侧覆盖率一直过不去,后来我新加一个文件后,他却提示数据对不上,但我在本身的window电脑、aistudio的linux环境以及我朋友的mac电脑里面都是可以的,另外您也是可以看到,代码使用的都是paddle已经实现的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.
LGTM for PR-CI-Distribute-stable
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
915b5b9
你好,请问这个PI-CI-Static-Check需要怎么解决的? @sunzhongkai588 |
Sorry to inform you that 915b5b9's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
|
你好,请问能否review一下? @sunzhongkai588 |
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 @SigureMo review一下type annotation
python/paddle/nn/layer/container.py
Outdated
self, | ||
parameters: ( | ||
ParameterDict | ||
| typing.Mapping[str, 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.
为什么要用 typing.Mapping
而不是已经 import 了的 collections.abc.Mapping
?
python/paddle/nn/layer/container.py
Outdated
def __len__(self) -> int: | ||
return len(self._parameters) | ||
|
||
def __iter__(self) -> Iterator[tuple[str, 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.
为什么这个 __iter__
返回结果的语义与 Python 的 dict 不一样,不是 dict 的 key 的 iterator,而是 key-value pair 的 iterator?这里的设计是基于什么?
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.
抱歉,这里是多加了的,参考layerdict然后看岔了
python/paddle/nn/layer/container.py
Outdated
self, | ||
parameters: ( | ||
ParameterDict | ||
| typing.Mapping[str, 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/nn/layer/container.py
Outdated
... super().__init__() | ||
... # create ParameterDict with iterable Parameters | ||
... self.params = paddle.nn.ParameterDict( | ||
... {'t' + str(i): paddle.create_parameter(shape=[2, 2], dtype='float32') for i in range(num_stacked_param)}) |
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.
... {'t' + str(i): paddle.create_parameter(shape=[2, 2], dtype='float32') for i in range(num_stacked_param)}) | |
... {f"t{i}": paddle.create_parameter(shape=[2, 2], dtype='float32') for i in range(num_stacked_param)}) |
python/paddle/nn/layer/container.py
Outdated
raise ValueError( | ||
"The length of the " | ||
+ str(i) | ||
+ "'s element in parameters is " | ||
+ str(len(kv)) | ||
+ ", which must be 2." | ||
) |
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.
用 f-string
python/paddle/nn/layer/container.py
Outdated
def __len__(self) -> int: | ||
return len(self._parameters) | ||
|
||
def __iter__(self) -> Iterator[tuple[str, 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.
def __iter__(self) -> Iterator[tuple[str, Tensor]]: | |
def __iter__(self) -> Iterator[str]: |
- 类型提示没改
param_guard
不需要,因为返回的 iterator 访问不到参数
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.
好的好的,已经修改了
|
CI 出了点问题,遇到类似问题可以考虑直接用一个空的 commit 重新触发 CI,或者 convert to draft + ready to review 来重新触发 CI 帮你用了另一种方式重新触发了全部 CI(lock + unlock,你没权限,但前两种你是有权限的) |
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.
PR Category
Inference
PR Types
Others
Description
【Hackathon 7th No.23】NO.23 为 Paddle 新增 ParameterDict API
RFC:PaddlePaddle/community#959
Docs:PaddlePaddle/docs#6874