Skip to content

Commit

Permalink
Fix matmul and fix attach IPU (PaddlePaddle#225)
Browse files Browse the repository at this point in the history
* fix matmul
* fix attach ipu
  • Loading branch information
yaozhixin committed Oct 21, 2021
1 parent 494d2f0 commit c104ae7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions paddle/fluid/framework/ipu/ipu_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ void IpuBackend::AttachDevice(int id) {
if (ipu_model) {
return;
}
if (is_attached_) {
return;
} else {
is_attached_ = true;
}
device_ = popart::DeviceManager::createDeviceManager().acquireAvailableDevice(
UpperIpuNum());
PADDLE_ENFORCE_NOT_NULL(
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/framework/ipu/ipu_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class IpuBackend {
std::unique_ptr<Executor> executor_;
std::shared_ptr<popart::DeviceInfo> device_;
bool is_prepared_ = false;
bool is_attached_ = false;

// not own
const Scope *scope_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ Node *matmul_handler(Graph *graph, Node *node) {
y_node = y_node->outputs[0];
}
if (is_float_equal(alpha, 1.0)) {
return CreateBaseOp(graph, node, "popart_matmul", {x_node, y_node},
node->outputs);
} else {
auto o_node =
CreateBaseOp(graph, node, "popart_matmul", {x_node, y_node}, {});
auto attr = MakeConstAttrMapFromValue(alpha, {1}, ONNXDataType::FLOAT);
auto const_node = CreateConst(graph, node, {}, {}, attr);
return CreateBaseOp(graph, node, "popart_mul",
{o_node->outputs[0], const_node->outputs[0]},
node->outputs);
} else {
return CreateBaseOp(graph, node, "popart_matmul", {x_node, y_node},
node->outputs);
}
}

Expand Down
11 changes: 11 additions & 0 deletions python/paddle/fluid/tests/unittests/ipu/test_matmul_op_ipu.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ def set_feed(self):
}


class TestCase7(TestBase):
def set_feed(self):
self.feed = {
"x": np.random.uniform(size=[1, 12, 128, 64]).astype('float32'),
"y": np.random.uniform(size=[1, 12, 128, 64]).astype('float32'),
}

def set_attrs(self):
self.attrs = {"transpose_x": False, "transpose_y": True, "alpha": 0.125}


@unittest.skip("not supported")
class TestCase6_2(TestCase6):
def set_feed(self):
Expand Down

0 comments on commit c104ae7

Please sign in to comment.