16
16
import multiprocessing
17
17
import framework
18
18
import executor
19
+ import sys
19
20
20
21
__all__ = ['ParallelExecutor' ]
21
22
@@ -125,6 +126,30 @@ def __init__(self,
125
126
126
127
def run (self , fetch_list , feed = None , feed_dict = None ):
127
128
"""
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
+
128
153
129
154
Args:
130
155
fetch_list(list): The fetched variable names
@@ -133,12 +158,14 @@ def run(self, fetch_list, feed=None, feed_dict=None):
133
158
the feed is a list, each element of the list will be copied
134
159
to each device.
135
160
feed_dict: Alias for feed parameter, for backward compatibility.
161
+ This parameter is deprecated.
136
162
137
163
Returns: fetched result list.
138
164
139
165
"""
140
166
if feed is None :
141
167
feed = feed_dict
168
+ print >> sys .stderr , "`feed_dict` is deprecated. Please use `feed=`"
142
169
143
170
if isinstance (feed , dict ):
144
171
feed_tensor_dict = dict ()
0 commit comments