Skip to content

[API Compatibility] Add alias paddle.random.get_rng_state#78472

Open
algorithm1832 wants to merge 2 commits intoPaddlePaddle:developfrom
algorithm1832:improvement_get_rng_state
Open

[API Compatibility] Add alias paddle.random.get_rng_state#78472
algorithm1832 wants to merge 2 commits intoPaddlePaddle:developfrom
algorithm1832:improvement_get_rng_state

Conversation

@algorithm1832
Copy link
Copy Markdown
Contributor

PR Category

User Experience

PR Types

Improvements

Description

  • Add alias paddle.random.get_rng_state for paddle.get_rng_state
  • Add corresponding test

Used AI Studio

是否引起精度变化

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Mar 25, 2026

你的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.

@paddle-bot paddle-bot bot added the contributor External developers label Mar 25, 2026
@algorithm1832
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@algorithm1832
Copy link
Copy Markdown
Contributor Author

coverage CI 似乎有问题

image

@algorithm1832
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

1 similar comment
@algorithm1832
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@@ -33,3 +33,15 @@ def initial_seed() -> int:
>>> s = paddle.random.initial_seed()
"""
return core.default_cpu_generator().initial_seed()


def __getattr__(name):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这里可以直接导入到这个文件里来吗,是有循环导入的问题吗?因为只有一个API,影响较小,可考虑直接换个实现位置

@zhwesky2010
Copy link
Copy Markdown
Contributor

尽量先用简单方式实现,绕不过再使用特殊技巧。

def test_api_compatibility(self):
paddleObj = paddle.get_rng_state
aliasObj = paddle.random.get_rng_state
self.assertTrue(type(paddleObj) == type(aliasObj))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这俩 type 有啥好比的?

@@ -71,6 +71,11 @@ def test_invalid_device_raises(self):
finally:
paddle.set_rng_state(original_state)

def test_api_compatibility(self):
paddleObj = paddle.get_rng_state
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

python 为啥用 camelCase

@@ -19,6 +19,10 @@
import paddle
from paddle.base import core

# Note: paddle.random.get_rng_state is an alias for paddle.get_rng_state
# however due to circular import issues, implementation has been moved to paddle.random
Copy link
Copy Markdown
Member

@SigureMo SigureMo Apr 4, 2026

Choose a reason for hiding this comment

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

这是 AI 写的吗?没用的注释

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
python/paddle/random.py 60.00% 8 Missing ⚠️

❌ Your patch status has failed because the patch coverage (61.90%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #78472   +/-   ##
==========================================
  Coverage           ?   61.90%           
==========================================
  Files              ?        2           
  Lines              ?       21           
  Branches           ?        0           
==========================================
  Hits               ?       13           
  Misses             ?        8           
  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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants