未验证 提交 443cf71a 编写于 作者: Z zhangchunle 提交者: GitHub

fix undefined-variable (#33355)

上级 599e9e48
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
from __future__ import print_function from __future__ import print_function
import sys import sys
import paddle
from paddle.optimizer import Optimizer from paddle.optimizer import Optimizer
from paddle.fluid.clip import ClipGradByGlobalNorm from paddle.fluid.clip import ClipGradByGlobalNorm
from ...utils.hybrid_parallel_util import fused_allreduce_gradients from ...utils.hybrid_parallel_util import fused_allreduce_gradients
...@@ -22,6 +23,8 @@ from paddle.fluid.dygraph import base as imperative_base ...@@ -22,6 +23,8 @@ from paddle.fluid.dygraph import base as imperative_base
from paddle.fluid import framework from paddle.fluid import framework
from paddle.fluid.framework import Variable from paddle.fluid.framework import Variable
from ...utils.log_util import logger from ...utils.log_util import logger
from paddle.fluid import core
from paddle.fluid import layers
__all__ = [] __all__ = []
......
...@@ -150,6 +150,7 @@ def _format_summary(collected_ops_list): ...@@ -150,6 +150,7 @@ def _format_summary(collected_ops_list):
''' '''
_verify_dependent_package() _verify_dependent_package()
from prettytable import PrettyTable
summary_table = PrettyTable( summary_table = PrettyTable(
["No.", "TYPE", "INPUT", "OUTPUT", "PARAMs", "FLOPs"]) ["No.", "TYPE", "INPUT", "OUTPUT", "PARAMs", "FLOPs"])
summary_table.align = 'r' summary_table.align = 'r'
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
import six import six
import unittest import unittest
import time import time
......
...@@ -268,7 +268,7 @@ class AutoCheckpointTest(AutoCheckPointACLBase): ...@@ -268,7 +268,7 @@ class AutoCheckpointTest(AutoCheckPointACLBase):
def test_checker(self): def test_checker(self):
os.environ.pop("PADDLE_JOB_ID", None) os.environ.pop("PADDLE_JOB_ID", None)
try: try:
checker = AutoCheckpointChecker() checker = acp.AutoCheckpointChecker()
self.assertFalse(True) self.assertFalse(True)
except Exception as e: except Exception as e:
pass pass
......
...@@ -333,7 +333,7 @@ class TestDynamicRNNErrors(unittest.TestCase): ...@@ -333,7 +333,7 @@ class TestDynamicRNNErrors(unittest.TestCase):
hidden = fluid.layers.fc(input=[word, memory], hidden = fluid.layers.fc(input=[word, memory],
size=10, size=10,
act='tanh') act='tanh')
out = np.ones(1).astype('float32') out = numpy.ones(1).astype('float32')
drnn.update_memory(ex_mem=memory, new_mem=hidden) drnn.update_memory(ex_mem=memory, new_mem=hidden)
drnn.output(hidden, out) drnn.output(hidden, out)
......
...@@ -47,7 +47,7 @@ class TestExportWithTensor(unittest.TestCase): ...@@ -47,7 +47,7 @@ class TestExportWithTensor(unittest.TestCase):
self.x_spec = paddle.static.InputSpec( self.x_spec = paddle.static.InputSpec(
shape=[None, 128], dtype='float32') shape=[None, 128], dtype='float32')
def test_with_tensor(): def test_with_tensor(self):
model = LinearNet() model = LinearNet()
paddle.onnx.export(model, 'linear_net', input_spec=[self.x_spec]) paddle.onnx.export(model, 'linear_net', input_spec=[self.x_spec])
......
...@@ -163,7 +163,7 @@ def init_communicator(program, rank, nranks, wait_port, current_endpoint, ...@@ -163,7 +163,7 @@ def init_communicator(program, rank, nranks, wait_port, current_endpoint,
}) })
elif core.is_compiled_with_npu(): elif core.is_compiled_with_npu():
hccl_id_var = block.create_var( hccl_id_var = block.create_var(
name=unique_name.generate('hccl_id'), name=fluid.unique_name.generate('hccl_id'),
persistable=True, persistable=True,
type=core.VarDesc.VarType.RAW) type=core.VarDesc.VarType.RAW)
endpoint_to_index_map = {e: idx for idx, e in enumerate(endpoints)} endpoint_to_index_map = {e: idx for idx, e in enumerate(endpoints)}
...@@ -710,10 +710,10 @@ class DynamicGraphAdapter(object): ...@@ -710,10 +710,10 @@ class DynamicGraphAdapter(object):
enable=self._amp_level != 'O0', **self._amp_custom_lists): enable=self._amp_level != 'O0', **self._amp_custom_lists):
if self._nranks > 1: if self._nranks > 1:
outputs = self.ddp_model.forward( outputs = self.ddp_model.forward(
* [to_variable(x) for x in inputs]) *[to_variable(x) for x in inputs])
else: else:
outputs = self.model.network.forward( outputs = self.model.network.forward(
* [to_variable(x) for x in inputs]) *[to_variable(x) for x in inputs])
losses = self.model._loss(*(to_list(outputs) + labels)) losses = self.model._loss(*(to_list(outputs) + labels))
losses = to_list(losses) losses = to_list(losses)
...@@ -732,7 +732,7 @@ class DynamicGraphAdapter(object): ...@@ -732,7 +732,7 @@ class DynamicGraphAdapter(object):
metrics = [] metrics = []
for metric in self.model._metrics: for metric in self.model._metrics:
metric_outs = metric.compute(*(to_list(outputs) + labels)) metric_outs = metric.compute(*(to_list(outputs) + labels))
m = metric.update(* [to_numpy(m) for m in to_list(metric_outs)]) m = metric.update(*[to_numpy(m) for m in to_list(metric_outs)])
metrics.append(m) metrics.append(m)
return ([to_numpy(l) for l in losses], metrics) \ return ([to_numpy(l) for l in losses], metrics) \
...@@ -746,7 +746,7 @@ class DynamicGraphAdapter(object): ...@@ -746,7 +746,7 @@ class DynamicGraphAdapter(object):
labels = labels or [] labels = labels or []
labels = [to_variable(l) for l in to_list(labels)] labels = [to_variable(l) for l in to_list(labels)]
outputs = self.model.network.forward(* [to_variable(x) for x in inputs]) outputs = self.model.network.forward(*[to_variable(x) for x in inputs])
if self.model._loss: if self.model._loss:
losses = self.model._loss(*(to_list(outputs) + labels)) losses = self.model._loss(*(to_list(outputs) + labels))
losses = to_list(losses) losses = to_list(losses)
...@@ -777,7 +777,7 @@ class DynamicGraphAdapter(object): ...@@ -777,7 +777,7 @@ class DynamicGraphAdapter(object):
self._merge_count[self.mode + '_batch'] = samples self._merge_count[self.mode + '_batch'] = samples
metric_outs = metric.compute(*(to_list(outputs) + labels)) metric_outs = metric.compute(*(to_list(outputs) + labels))
m = metric.update(* [to_numpy(m) for m in to_list(metric_outs)]) m = metric.update(*[to_numpy(m) for m in to_list(metric_outs)])
metrics.append(m) metrics.append(m)
if self.model._loss and len(metrics): if self.model._loss and len(metrics):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册