Skip to content

Commit 4260fff

Browse files
chihuahuajart
authored andcommitted
Guard no input or output args for functions (#399)
Previously, if a function lacks input_args or lacks output_args, the graph explorer would be unable to load a graph because input_arg['name'] triggers an error (due to input_arg being undefined). And indeed, functions without inputs (such as one with this signature) as possible: Likewise, nothing stops the `function.Defun` API from making a function without outputs (and only side effects). This change guards those cases. Fixes #375.
1 parent a1901da commit 4260fff

File tree

1 file changed

+49
-40
lines changed
  • tensorboard/plugins/graph/tf_graph_common

1 file changed

+49
-40
lines changed

tensorboard/plugins/graph/tf_graph_common/graph.ts

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,35 +1070,39 @@ export function build(
10701070
attr: [],
10711071
});
10721072

1073-
// Makes an OpNode out of either an input_arg of a library
1074-
// function.
1075-
let currentInputIndex = 0;
1076-
const processInput = (arg) => {
1077-
const opNode = processRawNode({
1078-
name: functionNodeName + NAMESPACE_DELIM + arg.name,
1079-
input: [],
1080-
device: '',
1081-
op: 'input_arg',
1082-
attr: [{
1083-
key: 'T',
1084-
value: {
1085-
type: arg.type,
1086-
},
1087-
}],
1088-
});
1089-
opNode.functionInputIndex = currentInputIndex;
1090-
currentInputIndex++;
1091-
};
1092-
1093-
// Make nodes for input args of the function. Unfortunately, the
1094-
// pbtxt configuration language is not rich enough to
1095-
// differentiate between an array with 1 item vs 1 object property.
1096-
if (func.signature.input_arg['name']) {
1097-
// There is only 1 input arg.
1098-
processInput(func.signature.input_arg);
1099-
} else {
1100-
// There are several input args.
1101-
_.each(func.signature.input_arg, processInput);
1073+
// If the function has inputs, make nodes out of them.
1074+
if (func.signature.input_arg) {
1075+
// Makes an OpNode out of either an input_arg of a library
1076+
// function.
1077+
let currentInputIndex = 0;
1078+
const processInput = (arg) => {
1079+
const opNode = processRawNode({
1080+
name: functionNodeName + NAMESPACE_DELIM + arg.name,
1081+
input: [],
1082+
device: '',
1083+
op: 'input_arg',
1084+
attr: [{
1085+
key: 'T',
1086+
value: {
1087+
type: arg.type,
1088+
},
1089+
}],
1090+
});
1091+
opNode.functionInputIndex = currentInputIndex;
1092+
currentInputIndex++;
1093+
};
1094+
1095+
// Make nodes for input args of the function. Unfortunately, the
1096+
// pbtxt configuration language is not rich enough to
1097+
// differentiate between an array with 1 item vs 1 object
1098+
// property.
1099+
if (func.signature.input_arg['name']) {
1100+
// There is only 1 input arg.
1101+
processInput(func.signature.input_arg);
1102+
} else {
1103+
// There are several input args.
1104+
_.each(func.signature.input_arg, processInput);
1105+
}
11021106
}
11031107

11041108
// Make nodes for output args of the function. Track the names of
@@ -1107,17 +1111,22 @@ export function build(
11071111
// node_defs of the library function.
11081112
let currentOutputIndex = 0;
11091113
const outputArgNames = {};
1110-
const processOutput = arg => {
1111-
outputArgNames[functionNodeName + NAMESPACE_DELIM + arg.name] =
1112-
currentOutputIndex;
1113-
currentOutputIndex++;
1114-
};
1115-
if (func.signature.output_arg['name']) {
1116-
// There is only 1 output arg.
1117-
processOutput(func.signature.output_arg);
1118-
} else {
1119-
// There are several output args.
1120-
_.each(func.signature.output_arg, processOutput);
1114+
1115+
// If the function has outputs, make nodes out of them.
1116+
if (func.signature.output_arg) {
1117+
const processOutput = arg => {
1118+
outputArgNames[
1119+
functionNodeName + NAMESPACE_DELIM + arg.name] =
1120+
currentOutputIndex;
1121+
currentOutputIndex++;
1122+
};
1123+
if (func.signature.output_arg['name']) {
1124+
// There is only 1 output arg.
1125+
processOutput(func.signature.output_arg);
1126+
} else {
1127+
// There are several output args.
1128+
_.each(func.signature.output_arg, processOutput);
1129+
}
11211130
}
11221131

11231132
_.each(func.node_def, rawNode => {

0 commit comments

Comments
 (0)