Skip to content

Conversation

@LLSGYN
Copy link
Contributor

@LLSGYN LLSGYN commented Aug 27, 2025

PR Category

User Experience

PR Types

New features

Description

  • 添加 rand_like API
  • 修改 multinomial 支持 out 参数
  • 修改 var 支持 correctionout 参数

@paddle-bot
Copy link

paddle-bot bot commented Aug 27, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

seed: int = 0,
name: str | None = None,
*,
place: PlaceLike | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个应该不需要修改

if not isinstance(dtype, (core.VarDesc.VarType, core.DataType)):
dtype = convert_np_dtype_to_dtype_(dtype)

tensor = uniform(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个可以用paddle.rand吗,paddle.rand 也升级了,这些dtype、requires_grad都会被处理,这个API就只需要转发一下就行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以的,预计按照这种方式进行修改:

    tensor = rand(input.shape, dtype=dtype, name=name)
    if device is not None:
        tensor = tensor.to(device)

@LLSGYN LLSGYN force-pushed the feat/out_ops1-new branch from 27ed42c to 24aaa86 Compare August 27, 2025 11:15
>>> print(out4.stop_gradient)
False
"""
if dtype is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这几个参数,randn全部都有,无需再特殊处理

infoflow 2025-08-27 21-44-17

Copy link
Contributor Author

@LLSGYN LLSGYN Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们需要调用的是均匀分布的rand而不是randn,而rand并不支持这几个参数

@codecov-commenter
Copy link

codecov-commenter commented Aug 27, 2025

Codecov Report

❌ Patch coverage is 92.30769% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@0113151). Learn more about missing BASE report.

Files with missing lines Patch % Lines
python/paddle/tensor/stat.py 91.66% 2 Missing ⚠️
python/paddle/tensor/random.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #74920   +/-   ##
==========================================
  Coverage           ?   92.30%           
==========================================
  Files              ?        2           
  Lines              ?       39           
  Branches           ?        0           
==========================================
  Hits               ?       36           
  Misses             ?        3           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

False
"""
if dtype is None:
dtype = input.dtype
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个无需要处理,后面的API会自行处理dtype=None的情况,取这个有点损耗

dtype = convert_np_dtype_to_dtype_(dtype)

tensor = paddle.rand(input.shape, dtype=dtype, name=name)
if device is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里进行了一些额外的处理,会有一些损耗,底层kernel已经支持了place,需要利用起来。

参考paddle.randn的实现方式吧,这个实现比较标准:

https://github.com/PaddlePaddle/Paddle/pull/74849/files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个应该就是之前我利用uniform kernel实现的思路。我先去利用它修改一下rand,然后使用rand_like转发rand来实现。

@LLSGYN LLSGYN force-pushed the feat/out_ops1-new branch from 24aaa86 to 479a28e Compare August 28, 2025 14:51
@LLSGYN
Copy link
Contributor Author

LLSGYN commented Aug 28, 2025

image

参考randn_like / randn。

False
"""
if dtype is None:
dtype = input.dtype
Copy link
Contributor

@zhwesky2010 zhwesky2010 Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只在最后一个API里处理dtype=None的情况,前面的API就直接将None往后面传,不用一直取None下的dtype。

如果其他的API不符合这个写法,做了冗余操作,帮忙一起处理下。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rand_like/randn_like必须要在前面处理dtype=None的情况,因为目标是获取和输入Tensor一致的dtype。

*,
out: Tensor | None = None,
device: PlaceLike | None = None,
requires_grad: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是不是还有一个pin_memory,参考下最新的rand代码

)
self.assertEqual(x.data_ptr(), y.data_ptr())

def test_rand(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个新建一个文件吧,会和这个冲突

https://github.com/PaddlePaddle/Paddle/pull/74949/files

@LLSGYN LLSGYN force-pushed the feat/out_ops1-new branch from 7c5751c to d42d7e5 Compare August 29, 2025 07:32
Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhwesky2010 zhwesky2010 requested a review from SigureMo August 29, 2025 08:21
paddle.disable_static()
x = paddle.to_tensor(self.x)
if self.use_correction:
out = paddle.var(

This comment was marked as resolved.

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhwesky2010 zhwesky2010 merged commit 7a6ddc9 into PaddlePaddle:develop Aug 29, 2025
98 of 101 checks passed
@LLSGYN LLSGYN deleted the feat/out_ops1-new branch August 30, 2025 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants