Skip to content
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

【Fix PIR Unittest No.127 BUAA】Fix some test case in PIR #66289

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion python/paddle/tensor/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,9 @@ def _compute_quantile(
)
for q_num in q:
# we do not validate tensor q in static mode
if not in_dynamic_or_pir_mode() and isinstance(q_num, Variable):
if not in_dynamic_mode() and isinstance(
q_num, (Variable, paddle.pir.Value)
):
break
if q_num < 0 or q_num > 1:
raise ValueError("q should be in range [0, 1]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,24 @@ def check_grad(x, q, axis, target_gard, apis=None):
opt.minimize(loss)
exe = paddle.static.Executor()
exe.run(paddle.static.default_startup_program())
o = exe.run(
paddle.static.default_main_program(),
feed={"x": x, "q": np.array(q, dtype="float32")},
fetch_list=["x@GRAD"],
)[0]
np.testing.assert_allclose(
o,
np.array(target_gard, dtype="float32"),
rtol=1e-05,
equal_nan=True,
)
if paddle.framework.use_pir_api():
o = exe.run(
paddle.static.default_main_program(),
feed={"x": x, "q": np.array(q, dtype="float32")},
fetch_list=[],
)
else:
o = exe.run(
paddle.static.default_main_program(),
feed={"x": x, "q": np.array(q, dtype="float32")},
fetch_list=["x@GRAD"],
)[0]
np.testing.assert_allclose(
o,
np.array(target_gard, dtype="float32"),
rtol=1e-05,
equal_nan=True,
)
paddle.disable_static()

check_grad([1, 2, 3], 0.5, 0, [0, 1, 0])
Expand Down