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

Add string versions of argument funcs in jit Node #45464

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions torch/csrc/jit/ir/ir.cpp
Expand Up @@ -846,22 +846,40 @@ void Value::replaceAllUsesAfterNodeWith(const Node* node, Value* newValue) {
uses_.end());
}

size_t findArgument(const FunctionSchema& the_schema, Symbol name) {
auto name_str = name.toUnqualString();
size_t findArgument(
const FunctionSchema& the_schema,
const std::string& unqualName) {
for (size_t i = 0; i < the_schema.arguments().size(); ++i) {
const Argument* arg = &the_schema.arguments()[i];
if (arg->name() == name_str) {
if (arg->name() == unqualName) {
return i;
}
}
throw std::runtime_error(
std::string("Couldn't find an argument called ") + name.toQualString());
std::string("Couldn't find an argument called ") + unqualName);
}

size_t findArgument(const FunctionSchema& the_schema, Symbol name) {
const auto unqualName = name.toUnqualString();
return findArgument(the_schema, unqualName);
}

c10::optional<IValue> Node::get(Symbol name) const {
return toIValue(namedInput(name));
}

bool Node::hasNamedInput(const std::string& name) const {
for (const auto& argument : schema().arguments()) {
if (argument.name() == name) {
return true;
}
}
return false;
}

Value* Node::namedInput(const std::string& unqualName) const {
return input(findArgument(schema(), unqualName));
}
Value* Node::namedInput(Symbol name) const {
return input(findArgument(schema(), name));
}
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/jit/ir/ir.h
Expand Up @@ -414,6 +414,8 @@ struct TORCH_API Node {
return inputs_.at(i);
}

bool hasNamedInput(const std::string& unqualName) const;
Value* namedInput(const std::string& unqualName) const;
Value* namedInput(Symbol name) const;

c10::optional<IValue> get(Symbol name) const;
Expand Down