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 unit test temp file, test=develop #43155

Merged
merged 1 commit into from
Jun 8, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

import unittest

import os
import numpy as np
import tempfile
import paddle
import paddle.static
from paddle.fluid.tests.unittests.ipu.op_test_ipu import IPUOpTest
Expand All @@ -30,6 +32,8 @@ def setUp(self):
self.set_data_feed()
self.set_feed_attr()
self.set_attrs()
self.temp_dir = tempfile.TemporaryDirectory()
self.model_path = os.path.join(self.temp_dir.name, "weight_decay")

def set_atol(self):
self.atol = 1e-6
Expand Down Expand Up @@ -88,7 +92,7 @@ def exclude_fn(param):
place = paddle.CPUPlace()
exe = paddle.static.Executor(place)
exe.run(startup_prog)
paddle.static.save(main_prog, "weight_decay")
paddle.static.save(main_prog, self.model_path)

if run_ipu:
feed_list = [image.name]
Expand Down
8 changes: 6 additions & 2 deletions python/paddle/fluid/tests/unittests/test_load_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import unittest
import numpy as np
import os
import tempfile
from op_test import OpTest, randomize_probability
import paddle.fluid as fluid
import paddle.fluid.layers as layers
Expand All @@ -29,6 +31,8 @@ class TestLoadOpXpu(unittest.TestCase):
"""

def setUp(self):
self.temp_dir = tempfile.TemporaryDirectory()
self.model_path = os.path.join(self.temp_dir.name, "model")
self.ones = np.ones((4, 4)).astype('float32')
main_prog = fluid.Program()
start_prog = fluid.Program()
Expand All @@ -44,15 +48,15 @@ def setUp(self):
exe = fluid.Executor(fluid.XPUPlace(0))
exe.run(start_prog)
fluid.io.save_persistables(exe,
dirname="./model",
dirname=self.model_path,
main_program=main_prog)

def test_load_xpu(self):
main_prog = fluid.Program()
start_prog = fluid.Program()
with fluid.program_guard(main_prog, start_prog):
var = layers.create_tensor(dtype='float32')
layers.load(var, file_path='./model/w')
layers.load(var, file_path=self.model_path + '/w')

exe = fluid.Executor(fluid.XPUPlace(0))
exe.run(start_prog)
Expand Down