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

fix bug in 'device' type kvstore #12350

Merged
merged 2 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/kvstore/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ class CommDevice : public Comm {
void Init(int key, const NDArrayStorageType stype, const TShape& shape,
int dtype = mshadow::kFloat32) override {
sorted_key_attrs_.emplace_back(key, shape, dtype);
inited_ = false;
}

void InitBuffersAndComm(const std::vector<NDArray>& src) {
Expand Down Expand Up @@ -701,8 +702,10 @@ class CommDevice : public Comm {
}
// Delayed allocation - as the dense merged buffer might not be used at all if push()
// only sees sparse arrays
bool delay_alloc = true;
buf.merged = NDArray(shape, ctx, delay_alloc, type);
if (buf.merged.is_none()) {
bool delay_alloc = true;
buf.merged = NDArray(shape, ctx, delay_alloc, type);
}
ctx_info[ctx.dev_id].second += shape.Size();
}
inited_ = true;
Expand Down
17 changes: 17 additions & 0 deletions tests/python/unittest/test_kvstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ def check_init(kv, key):
check_init(mx.kv.create(), 3)
check_init(mx.kv.create(), 'a')

@with_seed()
def test_pull():
"""test pull"""
def check_pull(kv):
a = mx.nd.ones(shape)
b = mx.nd.zeros(shape)
kv.init('1', mx.nd.zeros(shape))
kv.push('1', [a,a,a,a])
kv.pull('1', b)
check_diff_to_scalar(b, 4)
kv.init('2', mx.nd.zeros(shape))
kv.pull('2', b)
check_diff_to_scalar(b, 0)

check_pull(mx.kv.create('device'))
check_pull(mx.kv.create())

@with_seed()
def test_list_kv_pair():
"""list key-value pair push & pull"""
Expand Down