Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #65 from tqchen/master
Browse files Browse the repository at this point in the history
rename narray to ndarray
  • Loading branch information
antinucleon committed Sep 13, 2015
2 parents acc8025 + cba8358 commit 3d53ac7
Show file tree
Hide file tree
Showing 39 changed files with 942 additions and 1,051 deletions.
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ else
CFLAGS+= -DMXNET_USE_OPENCV=0
endif

# setup opencv
ifeq ($(USE_OPENCV_DECODER),1)
CFLAGS+= -DMXNET_USE_OPENCV_DECODER=1
else
CFLAGS+= -DMXNET_USE_OPENCV_DECODER=0
endif

ifeq ($(USE_OPENMP_ITER), 1)
ifeq ($(USE_OPENMP), 1)
CFLAGS += -fopenmp
endif

Expand Down
13 changes: 7 additions & 6 deletions example/cifar10/cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def RandomInit(narray):
in_num = narray.shape[1]
out_num = narray.shape[0]
a = np.sqrt(3.0 / (in_num + out_num))
tmp = mx.narray.array(np.random.uniform(-a, a, narray.shape))
tmp = mx.nd.array(np.random.uniform(-a, a, narray.shape))
narray[:] = tmp

data = mx.symbol.Variable(name="data")
Expand Down Expand Up @@ -161,15 +161,16 @@ def RandomInit(narray):
batch_size = 128
data_shape = (batch_size, 3, 28, 28)

in_data = mx.narray.empty(data_shape, mx.gpu())
in_data = mx.nd.empty(data_shape, mx.gpu())
executor = loss.simple_bind(mx.gpu(), data = in_data)
out_narray = executor.heads()[0]
pred = mx.narray.zeros(out_narray.shape, mx.cpu())

out_narray = executor.outputs[0]
pred = mx.nd.zeros(out_narray.shape, mx.cpu())

arg_narrays, grad_narrays = executor.list_arguments()
inputs = dict(zip(loss.list_arguments(), arg_narrays))
tmp_label = mx.narray.zeros(inputs["sm_label"].shape)
momentum_narrays = [mx.narray.zeros(item.shape, mx.gpu()) for item in grad_narrays]
tmp_label = mx.nd.zeros(inputs["sm_label"].shape)
momentum_narrays = [mx.nd.zeros(item.shape, mx.gpu()) for item in grad_narrays]

block = list(zip(grad_narrays, arg_narrays, momentum_narrays))

Expand Down
14 changes: 7 additions & 7 deletions example/mnist/mlp_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ def CalAcc(out, label):
arg_shapes, out_shapes, aux_shapes = softmax.infer_shape(data=data_shape)

# create GPU NArray for data
arg_narrays = [mx.narray.zeros(shape, ctx=mx.Context("gpu")) for shape in arg_shapes]
grad_narrays = [mx.narray.zeros(shape, ctx=mx.Context("gpu")) for shape in arg_shapes]
arg_narrays = [mx.nd.zeros(shape, ctx=mx.gpu()) for shape in arg_shapes]
grad_narrays = [mx.nd.zeros(shape, ctx=mx.gpu()) for shape in arg_shapes]
inputs = dict(zip(args_list, arg_narrays))

# create CPU NArray for result stat
name2shape = dict(zip(args_list, arg_shapes))
pred = mx.narray.zeros(out_shapes[0])
pred = mx.nd.zeros(out_shapes[0])


# set random weight
np.random.seed(0)
for name, narray in inputs.items():
if "weight" in name:
tmp = mx.narray.array(np.random.uniform(-0.07, 0.07, name2shape[name]))
tmp = mx.nd.array(np.random.uniform(-0.07, 0.07, name2shape[name]))
tmp.copyto(narray)

# bind executer
# TODO(bing): think of a better bind interface
executor = softmax.bind(mx.Context('gpu'), arg_narrays, grad_narrays)
# create gradient NArray
out_narray = executor.heads()[0]
grad_narray = mx.narray.zeros(out_narray.shape, ctx=mx.Context("gpu"))
out_narray = executor.outputs[0]
grad_narray = mx.nd.zeros(out_narray.shape, ctx=mx.gpu())


# update
Expand All @@ -77,7 +77,7 @@ def Update(grad, weight):
label="data/t10k-labels-idx1-ubyte",
batch_size=batch_size, shuffle=True, flat=True, silent=False)

tmp_label = mx.narray.zeros(name2shape["sm_label"])
tmp_label = mx.nd.zeros(name2shape["sm_label"])

def test_mlp():
acc_train = 0.
Expand Down
8 changes: 4 additions & 4 deletions example/mnist/mlp_multi_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ def updater(key, grad, weight):
np.random.seed(0)
for idx in sync_indices:
shape = param_shapes[idx]
val = mx.narray.zeros(shape)
val = mx.nd.zeros(shape)
if "weight" in param_names[idx]:
val[:] = np.random.uniform(-0.07, 0.07, shape)
mx.kvstore.init(idx, val)

# allocate device's memory
params = [[mx.narray.zeros(s, d) for s in param_shapes] for d in devs]
grads = [[mx.narray.zeros(s, d) for s in param_shapes] for d in devs]
params = [[mx.nd.zeros(s, d) for s in param_shapes] for d in devs]
grads = [[mx.nd.zeros(s, d) for s in param_shapes] for d in devs]

# create executors for devices
executors = [mlp.bind(devs[d], params[d], grads[d]) for d in range(num_devs)]
forward_out = [mx.narray.zeros(e.heads()[0].shape) for e in executors]
forward_out = [mx.nd.zeros(e.heads()[0].shape) for e in executors]

# data reader
get_data.GetMNIST_ubyte()
Expand Down
Loading

0 comments on commit 3d53ac7

Please sign in to comment.