Skip to content

Commit 943c33d

Browse files
authored
[Cleanup][B-17]Replace to_variable (#61539)
1 parent f5c01c7 commit 943c33d

10 files changed

+27
-27
lines changed

test/legacy_test/test_smooth_l1_loss.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def test_static():
8484
with base.dygraph.guard():
8585
smooth_l1_loss = paddle.nn.loss.SmoothL1Loss()
8686
dy_ret = smooth_l1_loss(
87-
base.dygraph.to_variable(input_np),
88-
base.dygraph.to_variable(label_np),
87+
paddle.to_tensor(input_np),
88+
paddle.to_tensor(label_np),
8989
)
9090
dy_ret_value = dy_ret.numpy()
9191
self.assertIsNotNone(dy_ret_value)
@@ -132,8 +132,8 @@ def test_static():
132132
with base.dygraph.guard():
133133
smooth_l1_loss = paddle.nn.loss.SmoothL1Loss(reduction='sum')
134134
dy_ret = smooth_l1_loss(
135-
base.dygraph.to_variable(input_np),
136-
base.dygraph.to_variable(label_np),
135+
paddle.to_tensor(input_np),
136+
paddle.to_tensor(label_np),
137137
)
138138
dy_ret_value = dy_ret.numpy()
139139
self.assertIsNotNone(dy_ret_value)
@@ -180,8 +180,8 @@ def test_static():
180180
with base.dygraph.guard():
181181
smooth_l1_loss = paddle.nn.loss.SmoothL1Loss(reduction='none')
182182
dy_ret = smooth_l1_loss(
183-
base.dygraph.to_variable(input_np),
184-
base.dygraph.to_variable(label_np),
183+
paddle.to_tensor(input_np),
184+
paddle.to_tensor(label_np),
185185
)
186186
dy_ret_value = dy_ret.numpy()
187187
self.assertIsNotNone(dy_ret_value)
@@ -229,8 +229,8 @@ def test_static():
229229
with base.dygraph.guard():
230230
smooth_l1_loss = paddle.nn.loss.SmoothL1Loss(delta=delta)
231231
dy_ret = smooth_l1_loss(
232-
base.dygraph.to_variable(input_np),
233-
base.dygraph.to_variable(label_np),
232+
paddle.to_tensor(input_np),
233+
paddle.to_tensor(label_np),
234234
)
235235
dy_ret_value = dy_ret.numpy()
236236
self.assertIsNotNone(dy_ret_value)

test/legacy_test/test_softmax_mask_fuse_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def test_dygraph(self):
142142
mask = np.random.randint(0, 2, (1, 1, 8, 32)).astype("float32")
143143
mask_in_np = np.where(mask == 1, -10000.0, mask)
144144
rst_np = _get_softmax(x_in_np, mask_in_np, False)
145-
input_x = base.dygraph.to_variable(x_in_np)
146-
input_mask = base.dygraph.to_variable(mask_in_np)
145+
input_x = paddle.to_tensor(x_in_np)
146+
input_mask = paddle.to_tensor(mask_in_np)
147147

148148
rst = incubate.softmax_mask_fuse(input_x, input_mask)
149149
np.testing.assert_allclose(rst, rst_np, rtol=1e-05)

test/legacy_test/test_softmax_mask_fuse_upper_triangle_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_dygraph(self):
122122
with base.dygraph.guard(base.CUDAPlace(0)):
123123
x_in_np = np.random.random((1, 4, 32, 32)).astype(dtype)
124124
rst_np = _get_softmax_upper(x_in_np, dtype == 'float16')
125-
input_x = base.dygraph.to_variable(x_in_np)
125+
input_x = paddle.to_tensor(x_in_np)
126126

127127
rst = incubate.softmax_mask_fuse_upper_triangle(input_x)
128128
np.testing.assert_allclose(rst, rst_np, rtol=1e-05)

test/legacy_test/test_solve_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ def test_dygraph(self):
578578
with base.dygraph.guard(place):
579579
input_x_np = np.ones([4, 4]).astype(self.dtype)
580580
input_y_np = np.ones([4, 4]).astype(self.dtype)
581-
input_x = base.dygraph.to_variable(input_x_np)
582-
input_y = base.dygraph.to_variable(input_y_np)
581+
input_x = paddle.to_tensor(input_x_np)
582+
input_y = paddle.to_tensor(input_y_np)
583583
try:
584584
result = paddle.linalg.solve(input_x, input_y)
585585
except RuntimeError as ex:

test/legacy_test/test_stack_op.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,16 @@ def test_out(self):
318318
data2 = np.array([[3.0, 4.0]])
319319
data3 = np.array([[5.0, 6.0]])
320320
with base.dygraph.guard():
321-
x1 = base.dygraph.to_variable(data1)
322-
x2 = base.dygraph.to_variable(data2)
323-
x3 = base.dygraph.to_variable(data3)
321+
x1 = paddle.to_tensor(data1)
322+
x2 = paddle.to_tensor(data2)
323+
x3 = paddle.to_tensor(data3)
324324
result = paddle.stack([x1, x2, x3])
325325
result_np = result.numpy()
326326
expected_result = np.stack([data1, data2, data3])
327327
np.testing.assert_allclose(expected_result, result_np, rtol=1e-05)
328328

329329
with base.dygraph.guard():
330-
y1 = base.dygraph.to_variable(data1)
330+
y1 = paddle.to_tensor(data1)
331331
result = paddle.stack([y1], axis=0)
332332
result_np_2 = result.numpy()
333333
expected_result_2 = np.stack([data1], axis=0)

test/legacy_test/test_traced_layer_err_msg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_trace_err(self):
6363
if base.framework.in_dygraph_mode():
6464
return
6565
with base.dygraph.guard():
66-
in_x = base.dygraph.to_variable(
66+
in_x = paddle.to_tensor(
6767
np.random.random((self.batch_size, self.feature_size)).astype(
6868
'float32'
6969
)
@@ -108,7 +108,7 @@ def test_set_strategy_err(self):
108108
if base.framework.in_dygraph_mode():
109109
return
110110
with base.dygraph.guard():
111-
in_x = base.dygraph.to_variable(
111+
in_x = paddle.to_tensor(
112112
np.random.random((self.batch_size, self.feature_size)).astype(
113113
'float32'
114114
)
@@ -145,7 +145,7 @@ def test_save_inference_model_err(self):
145145
if base.framework.in_dygraph_mode():
146146
return
147147
with base.dygraph.guard():
148-
in_x = base.dygraph.to_variable(
148+
in_x = paddle.to_tensor(
149149
np.random.random((self.batch_size, self.feature_size)).astype(
150150
'float32'
151151
)
@@ -216,7 +216,7 @@ def _train_simple_net(self):
216216
)
217217

218218
for i in range(5):
219-
in_x = base.dygraph.to_variable(
219+
in_x = paddle.to_tensor(
220220
np.random.random(
221221
(self.batch_size, self.feature_size)
222222
).astype('float32')

test/legacy_test/test_transpose_op.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,23 +619,23 @@ def test_static_out(self):
619619
def test_dygraph_out(self):
620620
with base.dygraph.guard():
621621
np_x = np.random.random([10]).astype("float64")
622-
data = base.dygraph.to_variable(np_x)
622+
data = paddle.to_tensor(np_x)
623623
z = paddle.t(data)
624624
np_z = z.numpy()
625625
z_expected = np.array(np.transpose(np_x))
626626
self.assertEqual((np_z == z_expected).all(), True)
627627

628628
with base.dygraph.guard():
629629
np_x = np.random.random([10, 5]).astype("float64")
630-
data = base.dygraph.to_variable(np_x)
630+
data = paddle.to_tensor(np_x)
631631
z = paddle.t(data)
632632
np_z = z.numpy()
633633
z_expected = np.array(np.transpose(np_x))
634634
self.assertEqual((np_z == z_expected).all(), True)
635635

636636
with base.dygraph.guard():
637637
np_x = np.random.random([1, 5]).astype("float64")
638-
data = base.dygraph.to_variable(np_x)
638+
data = paddle.to_tensor(np_x)
639639
z = paddle.t(data)
640640
np_z = z.numpy()
641641
z_expected = np.array(np.transpose(np_x))

test/legacy_test/test_tril_triu_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def test_api_with_dygraph(self):
287287
np.random.uniform(-1, 1, [1, 9, 9, 4])
288288
+ 1j * np.random.uniform(-1, 1, [1, 9, 9, 4])
289289
).astype(dtype)
290-
x = base.dygraph.to_variable(data)
290+
x = paddle.to_tensor(data)
291291
tril_out, triu_out = (
292292
tensor.tril(x).numpy(),
293293
tensor.triu(x).numpy(),

test/legacy_test/test_unfold_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def setUp(self):
221221
def test_dygraph(self):
222222
for place in self.places:
223223
with base.dygraph.guard(place):
224-
input = base.dygraph.to_variable(self.inputs['X'])
224+
input = paddle.to_tensor(self.inputs['X'])
225225
m = paddle.nn.Unfold(**self.attrs)
226226
m.eval()
227227
result = m(input)

test/xpu/test_unfold_op_xpu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def setUp(self):
159159
def test_dygraph(self):
160160
for place in self.places:
161161
with base.dygraph.guard(place):
162-
input = base.dygraph.to_variable(self.inputs['X'])
162+
input = paddle.to_tensor(self.inputs['X'])
163163
m = paddle.nn.Unfold(**self.attrs)
164164
m.eval()
165165
result = m(input)

0 commit comments

Comments
 (0)