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

[Cleanup][B-2] clean some paddle.base.dygraph.to_variable for test #61904

Merged
merged 11 commits into from
Feb 23, 2024
Prev Previous commit
Next Next commit
✏️ Fixed error
  • Loading branch information
PommesPeter committed Feb 21, 2024
commit 530916a0b671a3a05dc9af93fd5324a44aa78817
2 changes: 1 addition & 1 deletion test/dygraph_to_static/simnet_dygraph_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
5 changes: 0 additions & 5 deletions test/dygraph_to_static/test_basic_api_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
np.random.seed(SEED)


def dyfunc_to_variable(x):
res = paddle.to_tensor(x)
return res


def dyfunc_to_tensor(x):
res1 = paddle.to_tensor(x, dtype=None, place=None, stop_gradient=True)
res2 = paddle.tensor.to_tensor(data=res1)
Expand Down
14 changes: 6 additions & 8 deletions test/dygraph_to_static/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
test_ast_only,
test_legacy_and_pt_and_pir,
)
from test_basic_api_transformation import dyfunc_to_variable

import paddle
from paddle.framework import use_pir_api
Expand All @@ -35,6 +34,11 @@
from paddle.static import InputSpec


def call_to_tensor(x):
res = paddle.to_tensor(x)
return res


def create_simple_net():
class SimpleNet(Layer):
def __init__(self):
Expand Down Expand Up @@ -370,7 +374,7 @@ class TestDeclarativeAPI(Dy2StTestBase):
@test_ast_only
@test_legacy_and_pt_and_pir
def test_error(self):
func = paddle.jit.to_static(dyfunc_to_variable)
func = paddle.jit.to_static(call_to_tensor)

paddle.enable_static()

Expand All @@ -379,12 +383,6 @@ def test_error(self):
with self.assertRaises(RuntimeError):
func(np.ones(5).astype("int32"))

with enable_to_static_guard(False):
with self.assertRaises(AssertionError):
# AssertionError: We Only support to_variable in imperative mode,
# please use base.dygraph.guard() as context to run it in imperative Mode
func(np.ones(5).astype("int32"))

paddle.disable_static()


Expand Down