Fix attribute renaming bug in function inliner (#12445)

* Fix attribute renaming bug in function inliner

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>

* Fix attr name

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
This commit is contained in:
G. Ramalingam 2022-08-22 08:19:42 -07:00 committed by GitHub
parent a078c8d99b
commit 53090f620e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View file

@ -359,7 +359,10 @@ private:
// if the call-node contains the attribute. Otherwise, this attribute must be removed.
auto entry = attr_map.find(attr.ref_attr_name());
if (entry != attr_map.cend()) {
// Copy value of attribute, but retain original name:
std::string name = attr.name();
attr = entry->second;
attr.set_name(name);
} else {
attr_iter = attributes.erase(attr_iter);
continue;

View file

@ -59,7 +59,7 @@ static void Check(const char* source,
std::vector<OrtValue> fetches;
status = session_object.Run(run_options, feeds, AsSpan({std::string(output_name)}), &fetches);
ASSERT_TRUE(status.IsOK()) << "Session Run failed.";
ASSERT_TRUE(status.IsOK()) << "Session Run failed: " << status.ErrorMessage() << std::endl;
auto& tensor = fetches[0].Get<Tensor>();
size_t size = static_cast<size_t>(tensor.Shape().Size());
@ -287,5 +287,34 @@ TEST(FunctionTest, CallInConditional) {
Check(code, "x", {1.0, 2.0, 3.0}, "y", {6.0, 12.0, 18.0});
}
// Test use of attibute references, especially where source/target attribute
// names are not the same. In this example, the "start : int = @s" attribute-reference
// binds the attribute named "start" of the Shape op to the attribute named "s"
// of the containing function myfun.
TEST(FunctionTest, AttrName) {
const char* code = R"(
<
ir_version: 8,
opset_import: [ "" : 16, "local" : 1 ]
>
agraph (float[N] x) => (float[N] y)
{
y = local.myfun <s = 0> (x)
}
<
opset_import: [ "" : 16 ],
domain: "local"
>
myfun <s> (lx) => (ly) {
d = Shape <start : int = @s> (lx)
df = Cast <to = 1> (d)
ly = Mul (lx, df)
}
)";
Check(code, "x", {1.0, 2.0, 3.0}, "y", {3.0, 6.0, 9.0});
}
} // namespace test
} // namespace onnxruntime