Skip to content

Commit 76b63c2

Browse files
author
Yancey
authored
move transpiler files into transpiler folder (#10415)
1 parent 55e714e commit 76b63c2

File tree

7 files changed

+47
-36
lines changed

7 files changed

+47
-36
lines changed

python/paddle/fluid/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,14 @@
4040
import regularizer
4141
import average
4242
import metrics
43+
import transpiler
4344
from param_attr import ParamAttr, WeightNormParamAttr
4445
from data_feeder import DataFeeder
4546
from core import LoDTensor, CPUPlace, CUDAPlace, CUDAPinnedPlace
46-
from distribute_transpiler import DistributeTranspiler
47-
from distribute_transpiler_simple import SimpleDistributeTranspiler
47+
from transpiler import DistributeTranspiler, SimpleDistributeTranspiler, InferenceTranspiler, memory_optimize, release_memory
4848
from concurrency import (Go, make_channel, channel_send, channel_recv,
4949
channel_close, Select)
50-
from inference_transpiler import InferenceTranspiler
5150
import clip
52-
from memory_optimization_transpiler import memory_optimize, release_memory
5351
import profiler
5452
import unique_name
5553
import recordio_writer
@@ -58,7 +56,7 @@
5856
Tensor = LoDTensor
5957

6058
__all__ = framework.__all__ + executor.__all__ + concurrency.__all__ +\
61-
trainer.__all__ + inferencer.__all__ + [
59+
trainer.__all__ + inferencer.__all__ + transpiler.__all__ + [
6260
'io',
6361
'initializer',
6462
'layers',
@@ -76,11 +74,6 @@
7674
'WeightNormParamAttr',
7775
'DataFeeder',
7876
'clip',
79-
'SimpleDistributeTranspiler',
80-
'DistributeTranspiler',
81-
'InferenceTranspiler',
82-
'memory_optimize',
83-
'release_memory',
8477
'profiler',
8578
'unique_name',
8679
'recordio_writer',
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from distribute_transpiler import DistributeTranspiler
15+
from inference_transpiler import InferenceTranspiler
16+
from memory_optimization_transpiler import memory_optimize, release_memory
17+
from distribute_transpiler_simple import SimpleDistributeTranspiler
18+
19+
__all__ = [
20+
"DistributeTranspiler", "InferenceTranspiler", "SimpleDistributeTranspiler",
21+
"memory_optimize", "release_memory"
22+
]

python/paddle/fluid/distribute_transpiler.py renamed to python/paddle/fluid/transpiler/distribute_transpiler.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
import math
1818

1919
import distributed_splitter as splitter
20-
import framework
21-
from framework import Program, default_main_program, Variable, Parameter
22-
from . import core
20+
from .. import core
21+
from ..framework import Program, default_main_program, Variable, Parameter
2322

2423
LOOKUP_TABLE_TYPE = "lookup_table"
2524
LOOKUP_TABLE_GRAD_TYPE = "lookup_table_grad"
@@ -135,6 +134,16 @@ def split_dense_variable(var_list,
135134
return blocks
136135

137136

137+
def delete_ops(block, ops):
138+
try:
139+
start = list(block.ops).index(ops[0])
140+
end = list(block.ops).index(ops[-1])
141+
[block.remove_op(start) for _ in xrange(end - start + 1)]
142+
except Exception, e:
143+
raise e
144+
block.program.sync_with_cpp()
145+
146+
138147
class DistributeTranspiler:
139148
def transpile(self,
140149
trainer_id,
@@ -317,7 +326,7 @@ def transpile(self,
317326

318327
def get_trainer_program(self):
319328
# remove optimize ops and add a send op to main_program
320-
self.delete_ops(self.origin_program.global_block(), self.optimize_ops)
329+
delete_ops(self.origin_program.global_block(), self.optimize_ops)
321330
# FIXME(typhoonzero): serialize once will fix error occurs when clone.
322331
self.origin_program.__str__()
323332
return self.origin_program
@@ -601,7 +610,7 @@ def _replace_lookup_table_op_with_prefetch(self, program, rpc_client_var,
601610
attrs={"axis": 0})
602611

603612
# delete lookup_table_op
604-
self.delete_ops(program.global_block(), [op])
613+
delete_ops(program.global_block(), [op])
605614
# break for loop
606615
break
607616

@@ -1164,12 +1173,3 @@ def _is_adam_connected_op(self, op):
11641173
in_name.startswith("beta2_pow_acc"):
11651174
return True
11661175
return False
1167-
1168-
def delete_ops(self, block, ops):
1169-
try:
1170-
start = list(block.ops).index(ops[0])
1171-
end = list(block.ops).index(ops[-1])
1172-
[block.remove_op(start) for _ in xrange(end - start + 1)]
1173-
except Exception, e:
1174-
raise e
1175-
block.program.sync_with_cpp()

python/paddle/fluid/distribute_transpiler_simple.py renamed to python/paddle/fluid/transpiler/distribute_transpiler_simple.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import framework
16-
from framework import Program, default_main_program, Parameter, Variable
17-
import optimizer
18-
from layer_helper import LayerHelper
15+
from ..framework import Program, default_main_program, Parameter, Variable
16+
from ..layer_helper import LayerHelper
1917

2018

2119
def hash_name_to_server(params_grads, pserver_endpoints):

python/paddle/fluid/inference_transpiler.py renamed to python/paddle/fluid/transpiler/inference_transpiler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414

1515
import numpy as np
16-
from framework import Program
17-
from executor import global_scope
18-
from . import core
16+
from .. import core
17+
from ..framework import Program
18+
from ..executor import global_scope
1919

2020

2121
class InferenceTranspiler:

python/paddle/fluid/memory_optimization_transpiler.py renamed to python/paddle/fluid/transpiler/memory_optimization_transpiler.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
# limitations under the License.
1414

1515
from collections import defaultdict
16-
import framework
17-
from framework import Program, default_main_program, Parameter, Variable
18-
import backward
19-
from backward import _rename_arg_
20-
from . import core
16+
from .. import core
17+
from ..framework import Program, default_main_program, Parameter, Variable
18+
from ..backward import _rename_arg_
2119

2220
dtype_to_size = {
2321
core.VarDesc.VarType.FP16: 2,

0 commit comments

Comments
 (0)