Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
1 change: 1 addition & 0 deletions docs/IR.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ name|string|The name of the function
domain|string|The domain to which this function belongs
doc_string|string|Human-readable documentation for this function. Markdown is allowed.
attribute|string[]|The attribute parameters of the function
attribute_proto|Attribute[]| (IR version 9+) The attribute parameters with default values of the function. A function attribute shall be represented either as a string attribute or an Attribute, not both.
input|string[]|The input parameters of the function
output|string[]|The output parameters of the function.
node|Node[]|A list of nodes, forming a partially ordered computation graph. It must be in topological order.
Expand Down
2 changes: 1 addition & 1 deletion docs/Syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The grammar below describes the syntax:
graph ::= id value-info-list '=>' value-info-list node-list
other-data ::= id ':' value
other-data-list ::= '<' other-data (',' other-data)* '>'
fun-attr-list ::= '<' id-list '>'
fun-attr-list ::= '<' id | attr (',' id | attr)* '>'
fun-input-list ::= '(' id-list ')'
fun-output-list ::= '(' id-list ')'
function ::= other-data-list? id fun-attr-list? fun-input-list '=>' fun-output-list node-list
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified onnx/backend/test/data/node/test_constant_pad/model.onnx
Binary file not shown.
Binary file modified onnx/backend/test/data/node/test_constant_pad_axes/model.onnx
Binary file not shown.
Binary file modified onnx/backend/test/data/node/test_edge_pad/model.onnx
Binary file not shown.
Binary file modified onnx/backend/test/data/node/test_equal/model.onnx
Binary file not shown.
Binary file modified onnx/backend/test/data/node/test_equal_bcast/model.onnx
Binary file not shown.
Binary file modified onnx/backend/test/data/node/test_equal_string/model.onnx
Binary file not shown.
Binary file not shown.
Binary file modified onnx/backend/test/data/node/test_reflect_pad/model.onnx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified onnx/backend/test/data/node/test_wrap_pad/model.onnx
Binary file not shown.
8 changes: 8 additions & 0 deletions onnx/checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,14 @@ void check_node(const NodeProto& node, const CheckerContext& ctx, const LexicalS
}
auto domain_version = dit->second;

// for ops referencing local functions, there is no schema to verify it.
// will add a check to verify consistency between these ops and local functions.
std::unordered_set<std::string> seen_attr_names{};
for (const auto& attr : node.attribute()) {
if (!seen_attr_names.insert(attr.name()).second) {
fail_check("Attribute '", attr.name(), "' appeared multiple times.");
};

check_attribute(attr, ctx, lex_ctx);
}

Expand Down Expand Up @@ -994,6 +1001,7 @@ void check_model(const ModelProto& model, CheckerContext& ctx) {

if (ctx.get_ir_version() >= 0x00000008) {
check_model_local_functions(model, ctx, lex_ctx);
// TODO: check consistency between local functions and ops referencing it.
}
}

Expand Down
32 changes: 31 additions & 1 deletion onnx/defs/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ Status OnnxParser::Parse(char open, IdList& idlist, char close) {
return Status::OK();
}

Status OnnxParser::Parse(IdList& idlist, AttrList& attrlist) {
idlist.Clear();
attrlist.Clear();
do {
std::string id;
ParseIdentifier(id);
auto next = NextChar();
if (next == ':' || next == '=')
Parse(*attrlist.Add(), id);
else
*idlist.Add() = id;
} while (Matches(','));
return Status::OK();
}

Status OnnxParser::Parse(char open, IdList& idlist, AttrList& attrlist, char close) {
if (Matches(open)) {
PARSE(idlist, attrlist);
MATCH(close);
} else {
idlist.Clear();
attrlist.Clear();
}
return Status::OK();
}

Status OnnxParser::Parse(TensorShapeProto& shape) {
shape.clear_dim();
do {
Expand Down Expand Up @@ -424,6 +450,10 @@ Status OnnxParser::Parse(AttributeProto& attr) {
attr.Clear();
std::string name;
CHECK_PARSER_STATUS(ParseIdentifier(name));
return Parse(attr, name);
}

Status OnnxParser::Parse(AttributeProto& attr, std::string& name) {
attr.set_name(name);
if (Matches(':')) {
CHECK_PARSER_STATUS(ParseIdentifier(name));
Expand Down Expand Up @@ -559,7 +589,7 @@ Status OnnxParser::Parse(FunctionProto& fn) {
ParseIdentifier(id);
fn.set_name(id);

PARSE('<', *fn.mutable_attribute(), '>');
PARSE('<', *fn.mutable_attribute(), *fn.mutable_attribute_proto(), '>');
PARSE('(', *fn.mutable_input(), ')');
MATCH('=');
MATCH('>', false);
Expand Down
6 changes: 6 additions & 0 deletions onnx/defs/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ class OnnxParser : public ParserBase {

Status Parse(AttributeProto& attr);

Status Parse(AttributeProto& attr, std::string& name);

Status Parse(AttrList& attrlist);

Status Parse(NodeProto& node);
Expand All @@ -411,6 +413,10 @@ class OnnxParser : public ParserBase {

Status Parse(char open, IdList& idlist, char close);

Status Parse(IdList& idlist, AttrList& attrlist);

Status Parse(char open, IdList& idlist, AttrList& attrlist, char close);

Status ParseSingleAttributeValue(AttributeProto& attr);

Status Parse(ValueInfoProto& valueinfo);
Expand Down
4 changes: 4 additions & 0 deletions onnx/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,13 @@ def make_function(
nodes: Sequence[NodeProto],
opset_imports: Sequence[OperatorSetIdProto],
attributes: Optional[Sequence[str]] = None,
attribute_protos: Optional[Sequence[AttributeProto]] = None,
doc_string: Optional[str] = None,
) -> FunctionProto:
if attributes is None:
attributes = []
if attribute_protos is None:
attribute_protos = []
f = FunctionProto()
f.domain = domain
f.name = fname
Expand All @@ -260,6 +263,7 @@ def make_function(
f.node.extend(nodes)
f.opset_import.extend(opset_imports)
f.attribute.extend(attributes)
f.attribute_proto.extend(attribute_protos)
if doc_string:
f.doc_string = doc_string
return f
Expand Down
16 changes: 13 additions & 3 deletions onnx/onnx-ml.proto
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ enum Version {
// - Implicitly add inference graph into each TrainingInfoProto's algorithm.
IR_VERSION_2020_5_8 = 0x0000000000000007;

// IR VERSION 8 published on <TBD>
// IR VERSION 8 published on July 30, 2021
// Introduce TypeProto.SparseTensor
// Introduce TypeProto.Optional
// Added a list of FunctionProtos local to the model
// Deprecated since_version and operator status from FunctionProto
IR_VERSION = 0x0000000000000008;
IR_VERSION_2021_7_30 = 0x0000000000000008;

// IR VERSION 9 published on TBD
// Added AttributeProto to FunctionProto so that default attribute values can be set.
IR_VERSION = 0x0000000000000009;
}

// Attributes
Expand Down Expand Up @@ -795,9 +798,16 @@ message FunctionProto {
repeated string input = 4;
repeated string output = 5;

// The attributes of the function.
// The attribute parameters of the function.
// It is for function parameters without default values.
repeated string attribute = 6;

// The attribute protos of the function.
// It is for function attributes with default values.
// A function attribute shall be represented either as
// a string attribute or an AttributeProto, not both.
repeated AttributeProto attribute_proto = 11;

// The nodes in the function.
repeated NodeProto node = 7;
// A human-readable documentation for this function. Markdown is allowed.
Expand Down
16 changes: 13 additions & 3 deletions onnx/onnx-ml.proto3
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ enum Version {
// - Implicitly add inference graph into each TrainingInfoProto's algorithm.
IR_VERSION_2020_5_8 = 0x0000000000000007;

// IR VERSION 8 published on <TBD>
// IR VERSION 8 published on July 30, 2021
// Introduce TypeProto.SparseTensor
// Introduce TypeProto.Optional
// Added a list of FunctionProtos local to the model
// Deprecated since_version and operator status from FunctionProto
IR_VERSION = 0x0000000000000008;
IR_VERSION_2021_7_30 = 0x0000000000000008;

// IR VERSION 9 published on TBD
// Added AttributeProto to FunctionProto so that default attribute values can be set.
IR_VERSION = 0x0000000000000009;
}

// Attributes
Expand Down Expand Up @@ -795,9 +798,16 @@ message FunctionProto {
repeated string input = 4;
repeated string output = 5;

// The attributes of the function.
// The attribute parameters of the function.
// It is for function parameters without default values.
repeated string attribute = 6;

// The attribute protos of the function.
// It is for function attributes with default values.
// A function attribute shall be represented either as
// a string attribute or an AttributeProto, not both.
repeated AttributeProto attribute_proto = 11;

// The nodes in the function.
repeated NodeProto node = 7;
// A human-readable documentation for this function. Markdown is allowed.
Expand Down
16 changes: 13 additions & 3 deletions onnx/onnx.in.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ enum Version {
// - Implicitly add inference graph into each TrainingInfoProto's algorithm.
IR_VERSION_2020_5_8 = 0x0000000000000007;

// IR VERSION 8 published on <TBD>
// IR VERSION 8 published on July 30, 2021
// Introduce TypeProto.SparseTensor
// Introduce TypeProto.Optional
// Added a list of FunctionProtos local to the model
// Deprecated since_version and operator status from FunctionProto
IR_VERSION = 0x0000000000000008;
IR_VERSION_2021_7_30 = 0x0000000000000008;

// IR VERSION 9 published on TBD
// Added AttributeProto to FunctionProto so that default attribute values can be set.
IR_VERSION = 0x0000000000000009;
}

// Attributes
Expand Down Expand Up @@ -796,9 +799,16 @@ message FunctionProto {
repeated string input = 4;
repeated string output = 5;

// The attributes of the function.
// The attribute parameters of the function.
// It is for function parameters without default values.
repeated string attribute = 6;

// The attribute protos of the function.
// It is for function attributes with default values.
// A function attribute shall be represented either as
// a string attribute or an AttributeProto, not both.
repeated AttributeProto attribute_proto = 11;

// The nodes in the function.
repeated NodeProto node = 7;
// A human-readable documentation for this function. Markdown is allowed.
Expand Down
16 changes: 13 additions & 3 deletions onnx/onnx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ enum Version {
// - Implicitly add inference graph into each TrainingInfoProto's algorithm.
IR_VERSION_2020_5_8 = 0x0000000000000007;

// IR VERSION 8 published on <TBD>
// IR VERSION 8 published on July 30, 2021
// Introduce TypeProto.SparseTensor
// Introduce TypeProto.Optional
// Added a list of FunctionProtos local to the model
// Deprecated since_version and operator status from FunctionProto
IR_VERSION = 0x0000000000000008;
IR_VERSION_2021_7_30 = 0x0000000000000008;

// IR VERSION 9 published on TBD
// Added AttributeProto to FunctionProto so that default attribute values can be set.
IR_VERSION = 0x0000000000000009;
}

// Attributes
Expand Down Expand Up @@ -779,9 +782,16 @@ message FunctionProto {
repeated string input = 4;
repeated string output = 5;

// The attributes of the function.
// The attribute parameters of the function.
// It is for function parameters without default values.
repeated string attribute = 6;

// The attribute protos of the function.
// It is for function attributes with default values.
// A function attribute shall be represented either as
// a string attribute or an AttributeProto, not both.
repeated AttributeProto attribute_proto = 11;

// The nodes in the function.
repeated NodeProto node = 7;
// A human-readable documentation for this function. Markdown is allowed.
Expand Down
16 changes: 13 additions & 3 deletions onnx/onnx.proto3
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ enum Version {
// - Implicitly add inference graph into each TrainingInfoProto's algorithm.
IR_VERSION_2020_5_8 = 0x0000000000000007;

// IR VERSION 8 published on <TBD>
// IR VERSION 8 published on July 30, 2021
// Introduce TypeProto.SparseTensor
// Introduce TypeProto.Optional
// Added a list of FunctionProtos local to the model
// Deprecated since_version and operator status from FunctionProto
IR_VERSION = 0x0000000000000008;
IR_VERSION_2021_7_30 = 0x0000000000000008;

// IR VERSION 9 published on TBD
// Added AttributeProto to FunctionProto so that default attribute values can be set.
IR_VERSION = 0x0000000000000009;
}

// Attributes
Expand Down Expand Up @@ -779,9 +782,16 @@ message FunctionProto {
repeated string input = 4;
repeated string output = 5;

// The attributes of the function.
// The attribute parameters of the function.
// It is for function parameters without default values.
repeated string attribute = 6;

// The attribute protos of the function.
// It is for function attributes with default values.
// A function attribute shall be represented either as
// a string attribute or an AttributeProto, not both.
repeated AttributeProto attribute_proto = 11;

// The nodes in the function.
repeated NodeProto node = 7;
// A human-readable documentation for this function. Markdown is allowed.
Expand Down
28 changes: 28 additions & 0 deletions onnx/test/cpp/parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,34 @@ square (x) => (y) {
)ONNX";

CheckModel(code);

const char* code_function_with_attributes = R"ONNX(
<
ir_version: 9,
opset_import: [ "" : 15, "custom_domain" : 1]
>
agraph (float[N] x) => (float[N] out)
{
out = custom_domain.foo<alpha=2.0, gamma=3.0>(x)
}

<
domain: "custom_domain",
opset_import: [ "" : 15],
doc_string: "function foo"
>
foo
<alpha: float=4.0, gamma>
(X) => (C)
{
constant_alpha = Constant<value_float: float=@alpha>()
constant_gamma = Constant<value_float: float=@gamma>()
constant_alpha_x = Mul(constant_alpha, X)
C = Add(constant_alpha_x, constant_gamma)
}
)ONNX";

CheckModel(code_function_with_attributes);
}

TEST(ParserTest, TypesModelTest1) {
Expand Down
Loading