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

[CodeStyle][py2] Clean up all usages of six package and __future__ imports in docs #5352

Merged
merged 7 commits into from
Nov 1, 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
1 change: 0 additions & 1 deletion ci_scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pytest' >requirements && \
RUN echo 'Pillow\n\
numpy\n\
gast==0.3.3\n\
six\n\
protobuf\n\
urllib3\n\
certifi\n\
Expand Down
8 changes: 5 additions & 3 deletions ci_scripts/check_api_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
import json
import argparse
import os.path as osp
Expand Down Expand Up @@ -51,8 +50,11 @@ def parse_args():
parser = argparse.ArgumentParser(description='check api parameters')
parser.add_argument('--debug', dest='debug', action="store_true")
for item in arguments:
parser.add_argument(
item[0], dest=item[1], help=item[4], type=item[2], default=item[3])
parser.add_argument(item[0],
dest=item[1],
help=item[4],
type=item[2],
default=item[3])

args = parser.parse_args()
return args
Expand Down
1 change: 0 additions & 1 deletion ci_scripts/check_pr_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
import sys
import json

Expand Down
16 changes: 6 additions & 10 deletions docs/api/paddle/static/Program_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,21 @@ Program,当 ``for_test=True`` 时返回一个新的、仅包含当前 Program

.. code-block:: python

import six

def print_prog(prog):
for name, value in sorted(six.iteritems(prog.block(0).vars)):
for name, value in sorted(prog.block(0).vars.items()):
print(value)
for op in prog.block(0).ops:
print("op type is {}".format(op.type))
print("op inputs are {}".format(op.input_arg_names))
print("op outputs are {}".format(op.output_arg_names))
for key, value in sorted(six.iteritems(op.all_attrs())):
for key, value in sorted(op.all_attrs().items()):
if key not in ['op_callstack', 'op_role_var']:
print(" [ attrs: {}: {} ]".format(key, value))

1. 克隆一个 Program,示例代码如下。

.. code-block:: python

import six
import paddle
import paddle.static as static
import paddle.utils as utils
Expand All @@ -148,13 +145,13 @@ Program,当 ``for_test=True`` 时返回一个新的、仅包含当前 Program
paddle.enable_static()

def print_prog(prog):
for name, value in sorted(six.iteritems(prog.block(0).vars)):
for name, value in sorted(prog.block(0).vars.items()):
print(value)
for op in prog.block(0).ops:
print("op type is {}".format(op.type))
print("op inputs are {}".format(op.input_arg_names))
print("op outputs are {}".format(op.output_arg_names))
for key, value in sorted(six.iteritems(op.all_attrs())):
for key, value in sorted(op.all_attrs().items()):
if key not in ['op_callstack', 'op_role_var']:
print(" [ attrs: {}: {} ]".format(key, value))

Expand Down Expand Up @@ -192,7 +189,6 @@ Program,当 ``for_test=True`` 时返回一个新的、仅包含当前 Program

.. code-block:: python

import six
import paddle
import paddle.static as static
import paddle.utils as utils
Expand All @@ -201,13 +197,13 @@ Program,当 ``for_test=True`` 时返回一个新的、仅包含当前 Program
paddle.enable_static()

def print_prog(prog):
for name, value in sorted(six.iteritems(prog.block(0).vars)):
for name, value in sorted(prog.block(0).vars.items()):
print(value)
for op in prog.block(0).ops:
print("op type is {}".format(op.type))
print("op inputs are {}".format(op.input_arg_names))
print("op outputs are {}".format(op.output_arg_names))
for key, value in sorted(six.iteritems(op.all_attrs())):
for key, value in sorted(op.all_attrs().items()):
if key not in ['op_callstack', 'op_role_var']:
print(" [ attrs: {}: {} ]".format(key, value))

Expand Down
2 changes: 1 addition & 1 deletion docs/api/paddle/static/nn/multi_box_head_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ multi_box_head
min_sizes = []
max_sizes = []
step = int(math.floor(((max_ratio - min_ratio)) / (num_layer - 2)))
for ratio in six.moves.range(min_ratio, max_ratio + 1, step):
for ratio in range(min_ratio, max_ratio + 1, step):
min_sizes.append(base_size * ratio / 100.)
max_sizes.append(base_size * (ratio + step) / 100.)
min_sizes = [base_size * .10] + min_sizes
Expand Down
3 changes: 1 addition & 2 deletions docs/api/paddle/static/py_func_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Tensor|tuple(Tensor)|list[Tensor],前向函数的输出 ``out``
.. code-block:: python

import paddle
import six
import numpy as np

paddle.enable_static()
Expand All @@ -64,7 +63,7 @@ Tensor|tuple(Tensor)|list[Tensor],前向函数的输出 ``out``

def simple_net(img, label):
hidden = img
for idx in six.moves.range(4):
for idx in range(4):
hidden = paddle.static.nn.fc(hidden, size=200)
new_hidden = create_tmp_var(name='hidden_{}'.format(idx),
dtype=hidden.dtype, shape=hidden.shape)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ tasks through different startup commands.

.. code-block:: python

from __future__ import print_function
from args import parse_args
import os
import sys
Expand Down
2 changes: 0 additions & 2 deletions docs/guides/model_convert/update_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ $ python -m paddle.distributed.launch train.py
launch 方式启动训练,以文件为单位启动多进程,需要在启动时调用 ``paddle.distributed.launch`` ,对于进程的管理要求较高。飞桨框架 2.0 版本增加了 ``spawn`` 启动方式,可以更好地控制进程,在日志打印、训练退出时更友好。使用示例如下:

```python
from __future__ import print_function

import paddle
import paddle.nn as nn
import paddle.optimizer as opt
Expand Down
4 changes: 0 additions & 4 deletions docs/guides/model_convert/update_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,6 @@ $ python -m paddle.distributed.launch train.py
Launch method need to start multiple processes as a file. You need to call ``paddle.distributed.launch`` at launch time with a higher process management requirements. PaddlePaddle framework 2.0 added ``spawn`` launch method, for better controlling the process and more friendly in the log printing and training exit. Usage examples are as follows.

```python
from __future__ import print_function

import paddle
import paddle.nn as nn
import paddle.optimizer as opt
Expand Down Expand Up @@ -435,8 +433,6 @@ if __name__ == '__main__':
# {0,1,2,3,4,5,6,7}, but you do not have the right to configure CUDA_VISIBLE_DEVICES, then you can
# Specify the parameter selected_gpus to select the card you wish to use, e.g. selected_gpus='4,5'.
# You can specify the use of card #4 and card #5

Translated with www.DeepL.com/Translator (free version)
if __name__ == '__main__':
dist.spawn(train, nprocs=2, selected_gpus='4,5')

Expand Down
4 changes: 0 additions & 4 deletions docs/install/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

> 请[安装 nccl2](https://developer.nvidia.com/nccl/nccl-download)

- 报错`Cannot uninstall 'six'.`

> 此问题可能与系统中已有 Python 有关,请使用`pip install paddlepaddle --ignore-installed six`(CPU)或`pip install paddlepaddle --ignore-installed six`(GPU)解决

- CentOS6 下如何编译 python2.7 为共享库?

> 使用以下指令:
Expand Down
1 change: 0 additions & 1 deletion docs/practices/gan/dcgan_face/dcgan_face.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@
"import time\n",
"import paddle\n",
"from paddle.io import Dataset\n",
"import six\n",
"from PIL import Image as PilImage\n",
"from paddle.static import InputSpec\n",
"paddle.enable_static()\n",
Expand Down