Skip to content

Commit

Permalink
Fix some Bugs of Undefined Variable (#33488)
Browse files Browse the repository at this point in the history
* fix Undefined variables

* fix Undefined variables
  • Loading branch information
Jiangxinz committed Jun 11, 2021
1 parent ab41a9e commit b2afc8d
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion python/paddle/distributed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from contextlib import closing
import socket
from paddle.fluid import core
from distutils.util import strtobool

__all__ = [ #noqa
'get_host_name_ip',
Expand Down Expand Up @@ -384,7 +385,7 @@ def add_arguments(argname, type, default, help, argparser, **kwargs):
add_argument("name", str, "Jonh", "User name.", parser)
args = parser.parse_args()
"""
type = distutils.util.strtobool if type == bool else type
type = strtobool if type == bool else type
argparser.add_argument(
"--" + argname,
default=default,
Expand Down
1 change: 0 additions & 1 deletion python/paddle/fluid/dataloader/collate.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def default_collate_fn(batch):

raise TypeError("batch data con only contains: tensor, numpy.ndarray, "
"dict, list, number, but got {}".format(type(sample)))
return outputs


def default_convert_fn(batch):
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

from __future__ import print_function

import warnings
import numpy as np
import six
import os
import logging
from collections import defaultdict

import paddle
import paddle.fluid as fluid
from paddle.fluid.distribute_lookup_table import find_distributed_lookup_table
from paddle.fluid.framework import Program, Variable, name_scope, default_main_program, default_startup_program, device_guard

Expand Down Expand Up @@ -1469,7 +1471,7 @@ def __init__(self,
assert isinstance(
num_trainers, int
), "The type of num_trainers should be 'int', but received %s" % type(
value)
num_trainers)
assert num_trainers > 0, "The value of num_trainers should be greater than 0!"

self._num_trainers = num_trainers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np
import paddle.fluid.core as core
from paddle.fluid.tests.unittests.op_test import OpTest
from paddle import enable_static

from paddle.fluid.tests.unittests.test_conv2d_transpose_op import conv2dtranspose_forward_naive, TestConv2DTransposeOp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def executor_main(self):
def pe_main(self):
image, label, loss = simple_fc_net()
loss.persistable = False
persitables, non_persistables = get_persistables_and_non_persistables(
persistables, non_persistables = get_persistables_and_non_persistables(
fluid.default_main_program(), [loss.name])

exe = fluid.Executor(self.place)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import paddle.fluid as fluid
from paddle.fluid import Program, program_guard
import paddle
from test_pool2d_op import adaptive_start_index, adaptive_end_index

paddle.enable_static()

Expand Down
2 changes: 1 addition & 1 deletion python/paddle/optimizer/lr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ def step(self, metrics, epoch=None):
if isinstance(metrics, (Tensor, numpy.ndarray)):
assert len(metrics.shape) == 1 and metrics.shape[0] == 1, "the metrics.shape " \
"should be (1L,), but the current metrics.shape is {}. Maybe that " \
"you should call paddle.mean to process it first.".format(loss.shape)
"you should call paddle.mean to process it first.".format(metrics.shape)
elif not isinstance(metrics,
(int, float, numpy.float32, numpy.float64)):
raise TypeError(
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@ def set_state_dict(self, state_dict):

assert model_np.shape == load_para_np.shape, \
"Parameter shape not match, Dygraph Parameter [ {} ] need tensor with shape {} but load tensor with shape {}".format(
item.name, model_np.shape, load_para_np.shape)
model_np.name, model_np.shape, load_para_np.shape)

assert model_np.dtype == load_para_np.dtype, \
"Parameter dtype not match, Dygraph Parameter [ {} ] need tensor with dtype {} but load tensor with dtype {}".format(
item.name, model_np.dtype, load_para_np.dtype)
model_np.name, model_np.dtype, load_para_np.dtype)

tensor.set(load_para_np, framework._current_expected_place())

Expand Down
2 changes: 1 addition & 1 deletion python/paddle/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class TestModel(unittest.TestCase):
@classmethod
def setUpClass(cls):
if not fluid.is_compiled_with_cuda():
self.skipTest('module not tested when ONLY_CPU compling')
cls.skipTest('module not tested when ONLY_CPU compling')
cls.device = paddle.set_device('gpu')
fluid.enable_dygraph(cls.device)

Expand Down
1 change: 1 addition & 0 deletions python/paddle/text/datasets/wmt14.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import print_function

import six
import tarfile
import numpy as np
import gzip
Expand Down

2 comments on commit b2afc8d

@pmajchrzak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this commit an issue is observed:

+ python python/paddle/fluid/contrib/slim/tests/save_quant_model.py --quant_model_path=/data/PaddlePaddle/trained_models/ERNIE/Ernie_qat/float --int8_model_save_path=/data/PaddlePaddle/trained_models/ERNIE/ernie_int8 --ops_to_quantize=fc,reshape2,transpose2
/usr/lib/python3/dist-packages/setuptools/depends.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
Traceback (most recent call last):
  File "python/paddle/fluid/contrib/slim/tests/save_quant_model.py", line 24, in <module>
    import paddle
  File "/usr/local/lib/python3.6/dist-packages/paddle/__init__.py", line 25, in <module>
    from .fluid import monkey_patch_variable
  File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/__init__.py", line 58, in <module>
    from . import contrib
  File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/contrib/__init__.py", line 35, in <module>
    from . import optimizer
  File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/contrib/optimizer.py", line 14, in <module>
    from paddle.fluid.optimizer import Optimizer
  File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/optimizer.py", line 25, in <module>
    import paddle.fluid as fluid
AttributeError: module 'paddle' has no attribute 'fluid'

Used:

CMAKE_FLAGS='-DCMAKE_BUILD_TYPE=Release -DWITH_GPU=OFF -DWITH_MKLDNN=ON -DWITH_TESTING=ON -DWITH_PROFILER=ON -DWITH_STYLE_CHECK=OFF -DON_INFER=ON -DWITH_INFERENCE_API_TEST=ON -DPY_VERSION=3.6'

@Shixiaowei02
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have received your problem but cannot reproduce it locally, are you sure that this submission caused the problem?

Please sign in to comment.