ó ùµÈ[c@s©dZddlZddlmZddlmZddlmZddl m Z ddl m Z d „Z d „Zd „Zd „Zd „Zdefd„ƒYZdS(sFExecutor group is a convenient tool for managing a group of executors.iÿÿÿÿN(t OrderedDicti(tcontext(tndarray(tDataDesc(t_split_input_slicec Cs¢x›t|||ƒD]‡\}}}t|tjƒrD|j|ƒqt|ttfƒr‰x>t||ƒD]\}}|j|ƒqiWqx|D]\}} |dkr‰|j} |jdkpÐ| ||j k} | ry|dkr||j|j !j| ƒq†|j | j krBtj |d|d|jd|j d| ƒq†tj |d|d|jd|j ƒ} | j| ƒq–|j| ƒq|j| ƒqWqWdS(s@Load a list of arrays into a list of arrays specified by slices.itaxistbegintendtoutN( tzipt isinstancetndtNDArraytcopytotlistttupletshapetstarttstopRt slice_axis( tdatattargetst major_axistd_srct d_targetsRtsrctdstt slice_idxtd_dstRtdo_cropt d_dst_copy((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pyt _load_generals*"  "  c Csµt|tƒržg}xAtt|ƒƒD]-}|jg|D]}|j|^q;ƒq(Wg|D]%}g|D]\}}|^qm^q`} t|| |ƒnt|j||ƒdS(sLoad data into sliced arrays.N(R RtrangetlentappendRR( tbatchRRt new_batchtitbtd_targett_Rt new_targets((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pyt _load_dataAs+2c Csµt|tƒržg}xAtt|ƒƒD]-}|jg|D]}|j|^q;ƒq(Wg|D]%}g|D]\}}|^qm^q`} t|| |ƒnt|j||ƒdS(sLoad label into sliced arrays.N(R RR R!R"tlabelR( R#RRR$R%R&R'R(RR)((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pyt _load_labelMs+2c Cs¯g}x¢t||ƒD]‘\}}|dkr–t|ƒdkrT|j|dƒq§|jtjd|g|D]}|j|djƒ^qmŒƒq|j|dƒqW|S(smMerge outputs that lives on multiple context into one, so that they look like living on one context. iitdim(R R!R"R tconcatt as_in_contextR(toutputsRtretsttensorsRttensor((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pyt_merge_multi_contextYs 3cCsS|dkrdg|St|tƒrLt|ƒ|ksHtd|ƒ‚|St|tƒr9gt|ƒD] }i^qh}x¸|jƒD]ª\}}d}t|tj ƒr»|g|}nMt|ƒdkrÚ||}n.t|ƒ|kstd||fƒ‚|}x&t|ƒD]}|||||\}}||j krg|jD]}|j |^qB^q|_|jrÇgt|j ƒD]>\}}||j kr}g|jD]}|j|^q¢^q}|_n d|_g|jD]}|d^qÚ}|jrPg|D]D}||j krg|jD]}|j|j j|ƒ^q^q|_n d|_gtt|jƒƒD])}g|jD]}|j|^q^qo|_dS(s'Collect internal arrays from executors.iN(Rft enumerateR]R\targ_dictR_RTRbRgR5R`RIRGt arg_arraysRaRORcRPtindexReR R!RKRd(RsRUR(R%tetexec_RuRh((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pyt_collect_arrays3s.X9[ ; >   T cCs‚|s|j st‚d|_|j|ƒ|_|dk rR|j|ƒ|_nxºtt|j ƒƒD]£}|j |||jƒ}|dk r­|j |||jƒ}ng}|ré|j |j dt t||ƒ|j|®scss$|]}|jtjƒƒVqdS(N(R R9R(RŽR((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pys ±sN( R RGRatsumR!tastypetdtypeR RKRd(RsR‰RŠRUtblocktweight((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pyt get_paramsŸs " %" cCsÚt||j|jƒ|dkr.|j}nt|tƒr|jdk r²|dk r²|djr²t ||j|j ƒq²n1|jdk r²|jr²t ||j|j ƒnx!|j D]}|j d|ƒq¼WdS(s»Split `data_batch` according to workload and run forward on each devices. Parameters ---------- data_batch : DataBatch Or could be any object implementing similar interface. is_train : bool The hint for the backend, indicating whether we are during training phase. Default is `None`, then the value `self.for_training` will be used. Returns ------- itis_trainN( R*R_RjR5ROR RR`R+R,RkR]tforward(Rst data_batchR–R~((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pyR—´s  (cCs©|jdj}g|D]}|j^q}g}xpt|jjƒ||jƒD]P\}}}t|ƒ}|dkrˆ|j||s cSsi|]}|j|j“qS((R’RU(RŽRu((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pys s R9RWt type_dicttshared_arg_namest shared_exect group2ctxt shared_buffers iýÿÿÿiN(R5R]RMRZR7RXR<RLt simple_bindRWRGRRtintt debug_strtsplit( RsR%RfRgRtR¸RRZt input_shapest input_typesR¹texecutor((s[/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/module/executor_group.pyR„s         2cCs•g}xˆt||ƒD]w\}}t|jƒ}|dkrb|j|j|j|j||s  "