Skip to content

Commit 7286954

Browse files
committed
Add more comments
1 parent a1d910b commit 7286954

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

python/paddle/fluid/parallel_executor.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import multiprocessing
1717
import framework
1818
import executor
19+
import sys
1920

2021
__all__ = ['ParallelExecutor']
2122

@@ -125,6 +126,30 @@ def __init__(self,
125126

126127
def run(self, fetch_list, feed=None, feed_dict=None):
127128
"""
129+
Run a parallel executor with fetch_list.
130+
131+
The feed parameter can be a dict or a list. If feed is a dict, the
132+
feed data will be split into multiple devices. If feed is a list, we
133+
assume the data has been splitted into multiple devices, the each
134+
element in the list will be copied to each device directly.
135+
136+
For example, if the feed is a dict:
137+
>>> exe = ParallelExecutor()
138+
>>> # the image will be splitted into devices. If there is two devices
139+
>>> # each device will process an image with shape (24, 1, 28, 28)
140+
>>> exe.run(feed={'image': numpy.random.random(size=(48, 1, 28, 28))})
141+
142+
For example, if the feed is a list:
143+
>>> exe = ParallelExecutor()
144+
>>> # each device will process each element in the list.
145+
>>> # the 1st device will process an image with shape (48, 1, 28, 28)
146+
>>> # the 2nd device will process an image with shape (32, 1, 28, 28)
147+
>>> #
148+
>>> # you can use exe.device_count to get the device number.
149+
>>> exe.run(feed=[{"image": numpy.random.random(size=(48, 1, 28, 28))},
150+
>>> {"image": numpy.random.random(size=(32, 1, 28, 28))},
151+
>>> ])
152+
128153
129154
Args:
130155
fetch_list(list): The fetched variable names
@@ -133,12 +158,14 @@ def run(self, fetch_list, feed=None, feed_dict=None):
133158
the feed is a list, each element of the list will be copied
134159
to each device.
135160
feed_dict: Alias for feed parameter, for backward compatibility.
161+
This parameter is deprecated.
136162
137163
Returns: fetched result list.
138164
139165
"""
140166
if feed is None:
141167
feed = feed_dict
168+
print >> sys.stderr, "`feed_dict` is deprecated. Please use `feed=`"
142169

143170
if isinstance(feed, dict):
144171
feed_tensor_dict = dict()

0 commit comments

Comments
 (0)