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-1] clean some paddle.base.dygraph.to_variable for test #61468

Merged
merged 3 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions test/collective/fleet/parallel_dygraph_control_flow_same.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)

import paddle
from paddle.base.dygraph.base import to_variable
from paddle.nn import Linear

np.random.seed(2021)
Expand Down Expand Up @@ -77,7 +76,7 @@ def get_model(self):
def run_one_loop(self, model, optimizer, batch):
x_data = np.array(list(batch))
x_data = x_data.reshape((-1, 10))
x = to_variable(x_data)
x = paddle.to_tensor(x_data)
out = model(x)
loss = out.sum() / len(batch)
return loss
Expand Down
5 changes: 2 additions & 3 deletions test/collective/fleet/parallel_dygraph_se_resnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import paddle
from paddle import base
from paddle.base.dygraph.base import to_variable
from paddle.nn import Linear

batch_size = 64
Expand Down Expand Up @@ -342,8 +341,8 @@ def run_one_loop(self, model, opt, data):
)
dy_x_data = dy_x_data / 255.0
y_data = np.array([x[1] for x in data]).astype('int64').reshape(bs, 1)
img = to_variable(dy_x_data)
label = to_variable(y_data)
img = paddle.to_tensor(dy_x_data)
label = paddle.to_tensor(y_data)
label.stop_gradient = True

out = model(img)
Expand Down
3 changes: 1 addition & 2 deletions test/collective/fleet/parallel_dygraph_sync_batch_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)

import paddle
from paddle.base.dygraph.base import to_variable
from paddle.nn import Conv2D, SyncBatchNorm


Expand Down Expand Up @@ -88,7 +87,7 @@ def run_one_loop(self, model, opt, data):
dy_x_data = np.array([x[0].reshape(3, 224, 224) for x in data]).astype(
'float32'
)
img = to_variable(dy_x_data)
img = paddle.to_tensor(dy_x_data)
img.stop_gradient = False

out = model(img)
Expand Down
3 changes: 1 addition & 2 deletions test/collective/fleet/parallel_dygraph_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import paddle
import paddle.nn.functional as F
from paddle import base
from paddle.base.dygraph import to_variable
from paddle.nn import Layer
from paddle.optimizer.lr import NoamDecay

Expand Down Expand Up @@ -1046,7 +1045,7 @@ def np_to_variable(data):
+ decoder_data_input_fields[:-1]
+ label_data_input_fields
):
var_inputs.append(to_variable(data_inputs[i], name=field))
var_inputs.append(paddle.to_tensor(data_inputs[i]))

enc_inputs = var_inputs[0 : len(encoder_data_input_fields)]
dec_inputs = var_inputs[
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,11 +895,11 @@ def _create_var_from_numpy(self, value):
if isinstance(value, tuple):
data = value[0]
lod = value[1]
v = base.dygraph.base.to_variable(value=data)
v = paddle.to_tensor(data)
v.value().get_tensor().set_recursive_sequence_lengths(lod)
return v
else:
return base.dygraph.base.to_variable(value)
return paddle.to_tensor(value)

def get_sequence_batch_size_1_input(self, lod=None, shape=None):
"""Get LoD input data whose batch size is 1.
Expand Down
5 changes: 2 additions & 3 deletions test/legacy_test/parallel_dygraph_mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)

import paddle
from paddle.base.dygraph.base import to_variable


class SimpleImgConvPool(paddle.nn.Layer):
Expand Down Expand Up @@ -125,8 +124,8 @@ def run_one_loop(self, model, opt, data):
.astype('int64')
.reshape(batch_size, 1)
)
img = to_variable(dy_x_data)
label = to_variable(y_data)
img = paddle.to_tensor(dy_x_data)
label = paddle.to_tensor(y_data)
label.stop_gradient = True

avg_loss = model(img, label)
Expand Down
3 changes: 1 addition & 2 deletions test/legacy_test/parallel_dygraph_shared_unused_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
)

import paddle
from paddle.base.dygraph.base import to_variable
from paddle.nn import Linear

np.random.seed(2021)
Expand Down Expand Up @@ -70,7 +69,7 @@ def get_model(self):
def run_one_loop(self, model, optimizer, batch):
x_data = np.array(list(batch))
x_data = x_data.reshape((-1, 10))
x = to_variable(x_data)
x = paddle.to_tensor(x_data)
out = model(x)
loss = out.sum() / len(batch)
return loss
Expand Down
5 changes: 2 additions & 3 deletions test/legacy_test/parallel_dygraph_sparse_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import paddle
from paddle import base
from paddle.base.dygraph.base import to_variable
from paddle.nn import Embedding


Expand Down Expand Up @@ -131,8 +130,8 @@ def run_one_loop(self, model, optimizer, batch):
x_data = x_data.reshape((-1, num_steps, 1))
y_data = y_data.reshape((-1, 1))

x = to_variable(x_data)
y = to_variable(y_data)
x = paddle.to_tensor(x_data)
y = paddle.to_tensor(y_data)

dy_loss = model(x, y)

Expand Down
4 changes: 2 additions & 2 deletions test/mkldnn/check_flags_mkldnn_ops_on_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def check():
helper = LayerHelper(base.unique_name.generate("test"), act="relu")
func = helper.append_activation
with base.dygraph.guard(base.core.CPUPlace()):
a = base.dygraph.to_variable(a_np)
b = base.dygraph.to_variable(b_np)
a = paddle.to_tensor(a_np)
b = paddle.to_tensor(b_np)
y = paddle.add(x=a, y=b)
y = paddle.matmul(x=y, y=b, transpose_y=True)
res1 = func(y)
Expand Down
3 changes: 2 additions & 1 deletion test/mkldnn/check_flags_use_mkldnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import numpy as np

import paddle
from paddle import base
from paddle.base.framework import _global_flags
from paddle.base.layer_helper import LayerHelper
Expand All @@ -35,7 +36,7 @@ def check():
helper = LayerHelper(base.unique_name.generate("test"), act="relu")
func = helper.append_activation
with base.dygraph.guard(base.core.CPUPlace()):
a = base.dygraph.to_variable(a_np)
a = paddle.to_tensor(a_np)
res1 = func(a)
res2 = np.maximum(a_np, 0)
np.testing.assert_array_equal(res1.numpy(), res2)
Expand Down