Ejemplo n.º 1
0
    def __init__(self, network):
        ''' The constructor of MVNetParamManager

        The constructor will associate the parameter with multiverso array
        table.  The initial value of ArrayTableHandler will be same as the
        parameters of network. If different parameters are used in different
        processes, the average of them will be used as the initial value
        '''
        self.shapes = []
        self.dtypes = []
        self.sizes = []
        self.all_param_list = []
        self.network = network
        for arr in lasagne.layers.get_all_param_values(self.network):
            self.shapes.append(arr.shape)
            # TODO: Now only float32 is supported in multiverso. So I store all
            # the parameters in a float32 array. This place need modification
            # after other types are supported
            assert(np.dtype("float32") == arr.dtype)
            self.dtypes.append(arr.dtype)
            self.sizes.append(arr.size)
            self.all_param_list.extend([i for i in np.nditer(arr)])
        self.all_param_list = np.array(self.all_param_list)

        self.tbh = mv.ArrayTableHandler(len(self.all_param_list), init_value=self.all_param_list)
        mv.barrier()  # add barrier to make sure the initial values have token effect
        self.all_param_list = self.tbh.get()
        self._set_all_param_to_net()
Ejemplo n.º 2
0
    def _test_array(self, size):
        tbh = mv.ArrayTableHandler(size)
        mv.barrier()

        for i in xrange(100):
            tbh.add(range(1, size + 1))
            tbh.add(range(1, size + 1))
            mv.barrier()
            for j, actual in enumerate(tbh.get()):
                self.assertEqual((j + 1) * (i + 1) * 2 * mv.workers_num(),
                                 actual)
            mv.barrier()
Ejemplo n.º 3
0
    def __init__(self, svobj):
        '''Constructor of the MVSharedVariable

        The constructor will create ArrayTableHandler and associate the shared
        variable with it. The initial value of ArrayTableHandler will be same
        as the value of SharedVariable. If different initial value is used in
        different processes, the average of them will be used as the initial
        value
        '''
        assert(isinstance(svobj, SharedVariable))
        self._svobj = svobj
        self._mv_array = mv.ArrayTableHandler(self._svobj.get_value().size,
                                              init_value=self._svobj.get_value().reshape((-1,)))

        mv.barrier()  # add barrier to make sure the initial values have token effect
        # _last_mv_data restore a copy of value. It will be used for calculate
        # the update for multiverso when calling mv_sync
        self._last_mv_data = self._mv_array.get().reshape(self._svobj.get_value().shape)
        self._svobj.set_value(self._last_mv_data, borrow=False)