Skip to content

Commit

Permalink
sync api change (PaddlePaddle#462)
Browse files Browse the repository at this point in the history
* sync api change

* rm test_enable_patern UT

* fix typo
  • Loading branch information
gglin001 committed Feb 21, 2022
1 parent 10be290 commit 8170905
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 94 deletions.
92 changes: 39 additions & 53 deletions python/paddle/fluid/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def set_graph_config(self,
'enable_manual_shard': enable_manual_shard,
'need_avg_shard': need_avg_shard,
}
self.set_option(conf)
self.set_options(conf)

def set_pipelining_config(self,
enable_pipelining=False,
Expand Down Expand Up @@ -638,7 +638,7 @@ def set_pipelining_config(self,
'batches_per_step': batches_per_step,
'accumulationFactor': accumulationFactor,
}
self.set_option(conf)
self.set_options(conf)

def set_half_config(self, enable_fp16=False):
"""
Expand All @@ -662,7 +662,7 @@ def set_half_config(self, enable_fp16=False):
ipu_strategy.set_half_config(enable_fp16=False)
"""
conf = {'enable_fp16': enable_fp16, }
self.set_option(conf)
self.set_options(conf)

def add_custom_op(self,
paddle_op,
Expand All @@ -683,6 +683,17 @@ def add_custom_op(self,
Returns:
None.
Examples:
.. code-block:: python
# required: ipu
import paddle
paddle.enable_static()
ipu_strategy = paddle.static.IpuStrategy()
ipu_strategy.add_custom_op('paddle_relu', 'popart_relu')
"""
if popart_op is None:
popart_op = paddle_op
Expand All @@ -692,22 +703,34 @@ def add_custom_op(self,
'domain': domain,
'version': version,
}
self.set_option({'custom_op': custom_op})
self.set_options({'custom_op': custom_op})
self.custom_op_names.append(paddle_op)
if not self.has_custom_ops:
self.has_custom_ops = True

def set_option(self, conf):
def set_options(self, options):
"""
Set option from Dict
Set options from dict.
Args:
conf(Dict): Dict of options.
options(dict): dict of options.
Returns:
None.
Examples:
.. code-block:: python
# required: ipu
import paddle
paddle.enable_static()
ipu_strategy = paddle.static.IpuStrategy()
conf = {'num_ipus':1, 'enable_fp16': True}
ipu_strategy.set_options(conf)
"""
self._ipu_strategy.set_option(conf)
self._ipu_strategy.set_option(options)

def get_option(self, option):
"""
Expand All @@ -718,44 +741,19 @@ def get_option(self, option):
Returns:
option value.
"""
return self._ipu_strategy.get_option(option)['value']

def enable_pattern(self, pattern):
"""
Enable a popart pattern.
Args:
pattern(str): name of a pattern.
Returns:
None.
"""
self._ipu_strategy.enable_pattern(pattern)
def disable_pattern(self, pattern):
"""
Disable a popart pattern.
Examples:
.. code-block:: python
Args:
pattern(str): name of a pattern.
Returns:
None.
"""
self._ipu_strategy.disable_pattern(pattern)
# required: ipu
def is_pattern_enabled(self, pattern):
"""
Check if a popart pattern is enabled.
import paddle
Args:
pattern(str): name of a pattern.
Returns:
bool.
paddle.enable_static()
ipu_strategy = paddle.static.IpuStrategy()
num_ipus = ipu_strategy.get_option('num_ipus')
"""
return self._ipu_strategy.is_pattern_enabled(pattern)
return self._ipu_strategy.get_option(option)['value']

@property
def num_ipus(self):
Expand Down Expand Up @@ -992,15 +990,3 @@ def compile(self, feed_list, fetch_list):
program.org_program = self._program

return program

def save_onnx_model(self, file_name):
"""
Save compiled IpuCompiledProgram in ONNX format.
Args:
file_name(str): path of onnx model.
Returns:
None
"""
self._backend.save_model_proto(file_name)
16 changes: 0 additions & 16 deletions python/paddle/fluid/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
'is_compiled_with_rocm',
'is_compiled_with_xpu',
'is_compiled_with_npu',
'is_compiled_with_ipu',
'Variable',
'require_version',
'device_guard',
Expand Down Expand Up @@ -547,21 +546,6 @@ def is_compiled_with_npu():
return core.is_compiled_with_npu()


def is_compiled_with_ipu():
"""
Whether this whl package can be used to run the model on IPU.
Returns (bool): support ipu or not.
Examples:
.. code-block:: python
import paddle.fluid as fluid
support_ipu = fluid.is_compiled_with_ipu()
"""
return core.is_compiled_with_ipu()


def disable_signal_handler():
"""
Reset signal handler registered by Paddle.
Expand Down
29 changes: 5 additions & 24 deletions python/paddle/fluid/tests/unittests/ipu/test_ipu_strategy_ipu.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,15 @@ def test_func(self):
confs['available_memory_proportion'] = 0.3

for k, v in confs.items():
ipu_strategy.set_option({k: v})
ipu_strategy.set_options({k: v})
assert v == ipu_strategy.get_option(
k), f"Setting option: {k} to value: {v} failed "


@unittest.skipIf(not paddle.is_compiled_with_ipu(),
"core is not compiled with IPU")
class TestEnablePattern(unittest.TestCase):
def test_enable_patern(self):
ipu_strategy = paddle.static.IpuStrategy()
pattern = 'LSTMOp'
# LSTMOp Pattern is not enabled by default
# assert not ipu_strategy.is_pattern_enabled(pattern)
ipu_strategy.enable_pattern(pattern)
assert ipu_strategy.is_pattern_enabled(pattern) == True

def test_disable_pattern(self):
ipu_strategy = paddle.static.IpuStrategy()
pattern = 'LSTMOp'
ipu_strategy.enable_pattern(pattern)
ipu_strategy.disable_pattern(pattern)
assert ipu_strategy.is_pattern_enabled(pattern) == False


@unittest.skipIf(not paddle.is_compiled_with_ipu(),
"core is not compiled with IPU")
class TestIpuStrategyLoadDict(unittest.TestCase):
def test_enable_patern(self):
def test_func(self):
ipu_strategy = paddle.static.IpuStrategy()
test_conf = {
"micro_batch_size": 23,
Expand All @@ -101,22 +82,22 @@ def test_enable_patern(self):
"save_init_onnx": True,
"save_onnx_checkpoint": True
}
ipu_strategy.set_option(test_conf)
ipu_strategy.set_options(test_conf)
for k, v in test_conf.items():
assert v == ipu_strategy.get_option(k)


@unittest.skipIf(not paddle.is_compiled_with_ipu(),
"core is not compiled with IPU")
class TestIpuStrategyEngineOptions(unittest.TestCase):
def test_enable_patern(self):
def test_func(self):
ipu_strategy = paddle.static.IpuStrategy()
engine_conf = {
'debug.allowOutOfMemory': 'true',
'autoReport.directory': 'path',
'autoReport.all': 'true'
}
ipu_strategy.set_option({'engineOptions': engine_conf})
ipu_strategy.set_options({'engineOptions': engine_conf})
for k, v in ipu_strategy.get_option('engineOptions').items():
assert v == engine_conf[k]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _test_base(self, save_otherwise_load):
is_training=self.attrs['is_training'])
ipu_strategy.set_half_config(
enable_fp16=self.attrs['enable_fp16'])
ipu_strategy.set_option({
ipu_strategy.set_options({
'save_per_n_step': self.attrs['save_at_step']
})
program = paddle.static.IpuCompiledProgram(
Expand Down

0 comments on commit 8170905

Please sign in to comment.