Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pea.sparse on IPU #16

Merged
merged 3 commits into from
Apr 28, 2023
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
4 changes: 2 additions & 2 deletions poptorch_experimental_addons/_impl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def autograd_proxy(fwd: Tensor, proxy: Tensor) -> Tensor:
(y,) = poptorch.custom_op(
[fwd, proxy],
name="AutogradProxy",
domain="ai.graphcore.pea",
domain="ai.graphcore",
domain_version=1,
example_outputs=[fwd],
)
Expand Down Expand Up @@ -93,7 +93,7 @@ def distance_matrix(tensor1: Tensor, tensor2: Tensor, p: int) -> Tensor:
(y,) = poptorch.custom_op(
name=f"L{p}Distance",
domain_version=1,
domain="ai.graphcore.pea",
domain="ai.graphcore",
inputs=[tensor1, tensor2],
example_outputs=[
torch.zeros(
Expand Down
2 changes: 1 addition & 1 deletion poptorch_experimental_addons/_impl/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def block_coo_spmm_ipu(sparse: Tensor, dense: Tensor, mode: str) -> Tensor:
(y,) = poptorch.custom_op(
[dense],
name="StaticSparseMatmul",
domain="ai.graphcore.pea",
domain="ai.graphcore",
domain_version=1,
example_outputs=[
torch.zeros(output_shape, dtype=dense.dtype, device=dense.device)
Expand Down
4 changes: 2 additions & 2 deletions poptorch_experimental_addons/cpp/autograd_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ struct Opx : popart::popx::Opx {
}
};

const popart::OperatorIdentifier Op::ID = {"ai.graphcore.pea", "AutogradProxy", 1};
const popart::OperatorIdentifier GradOp::ID = {"ai.graphcore.pea", "AutogradProxyGrad", 1};
const popart::OperatorIdentifier Op::ID = {"ai.graphcore", "AutogradProxy", 1};
const popart::OperatorIdentifier GradOp::ID = {"ai.graphcore", "AutogradProxyGrad", 1};
popart::OpDefinition::DataTypes T = {popart::DataType::FLOAT16, popart::DataType::FLOAT};
popart::OpCreator<Op> opCreator(
{{Op::ID,
Expand Down
8 changes: 4 additions & 4 deletions poptorch_experimental_addons/cpp/distance_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ poplar::Tensor l2distancegrad(poplar::Graph& graph,
return grad;
}

const popart::OperatorIdentifier L1DistanceId = {"ai.graphcore.pea", "L1Distance", 1};
const popart::OperatorIdentifier L2DistanceId = {"ai.graphcore.pea", "L2Distance", 1};
const popart::OperatorIdentifier L1DistanceGradId = {"ai.graphcore.pea", "L1DistanceGrad", 1};
const popart::OperatorIdentifier L2DistanceGradId = {"ai.graphcore.pea", "L2DistanceGrad", 1};
const popart::OperatorIdentifier L1DistanceId = {"ai.graphcore", "L1Distance", 1};
const popart::OperatorIdentifier L2DistanceId = {"ai.graphcore", "L2Distance", 1};
const popart::OperatorIdentifier L1DistanceGradId = {"ai.graphcore", "L1DistanceGrad", 1};
const popart::OperatorIdentifier L2DistanceGradId = {"ai.graphcore", "L2DistanceGrad", 1};

class L1DistanceOp;
class L1DistanceGradOpx;
Expand Down
31 changes: 30 additions & 1 deletion poptorch_experimental_addons/cpp/static_spmm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <popart/op.hpp>
#include <popart/opmanager.hpp>
#include <popart/opserialiser.hpp>
#include <popart/popx/opx.hpp>
#include <popart/popx/opxmanager.hpp>
#pragma GCC diagnostic pop
Expand Down Expand Up @@ -136,6 +137,32 @@ struct CustomOp : popart::Op {
? std::vector<int64_t>{static_cast<int>(matrix.numRows), input.dim(1)}
: std::vector<int64_t>{input.dim(0), static_cast<int>(matrix.numColumns)}};
}
void appendAttributes(popart::OpSerialiserBase& os) const final {
popart::Op::appendAttributes(os);
appendLocalAttributes(os);
}
void appendOutlineAttributes(popart::OpSerialiserBase& os) const final {
popart::Op::appendOutlineAttributes(os);
appendLocalAttributes(os);
}

private:
template <class T>
static std::string vectorToString(const std::vector<T>& v) {
std::ostringstream str;
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(str, " "));
return str.str();
}
void appendLocalAttributes(popart::OpSerialiserBase& os) const {
os.appendAttribute("mode", mode);
os.appendAttribute("numRows", matrix.numRows);
os.appendAttribute("numColumns", matrix.numColumns);
os.appendAttribute("blockSizeRows", matrix.getBlockDimensions()[0]);
os.appendAttribute("blockSizeColumns", matrix.getBlockDimensions()[1]);
os.appendAttribute("rowIndices", vectorToString(matrix.rowIndices));
os.appendAttribute("columnIndices", vectorToString(matrix.columnIndices));
os.appendAttribute("nzValues", vectorToString(matrix.nzValues));
}
};

struct CustomOpx : popart::popx::Opx {
Expand All @@ -153,7 +180,9 @@ struct CustomOpx : popart::popx::Opx {
}
};

const popart::OperatorIdentifier CustomOp::ID = {"ai.graphcore.pea", "StaticSparseMatmul", 1};
// We cannot use "ai.graphcore.pea", since shape inference tries to call
// `Ir::getDefaultOpsetVersion` which cannot be extended to custom domains
const popart::OperatorIdentifier CustomOp::ID = {"ai.graphcore", "StaticSparseMatmul", 1};
popart::OpDefinition::DataTypes T = {popart::DataType::FLOAT16, popart::DataType::FLOAT};
popart::OpCreator<CustomOp> opCreator(
{{CustomOp::ID,
Expand Down