Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit cede95a

Browse files
authored
Fix const op translation (#332)
* Fix copying values from const nodes, bug caught in Windows * Update ocm submodule, test cases list updated for Myriad * Remove unused commented code
1 parent a8e59b1 commit cede95a

File tree

3 files changed

+71
-51
lines changed

3 files changed

+71
-51
lines changed

ocm

openvino_tensorflow/mark_for_clustering.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,11 @@ const std::map<std::string, SetAttributesFunction>& GetAttributeSetters() {
105105
set_attributes_map["Conv2DBackpropInput"] = SetStaticInputs({0});
106106
set_attributes_map["CropAndResize"] = SetStaticInputs({1, 2, 3});
107107
set_attributes_map["ExpandDims"] = SetStaticInputs({1});
108-
// set_attributes_map["Fill"] = SetStaticInputs({0});
109108
set_attributes_map["GatherV2"] = SetStaticInputs({2});
110109
set_attributes_map["Max"] = SetStaticInputs({1});
111110
set_attributes_map["Mean"] = SetStaticInputs({1});
112111
set_attributes_map["Min"] = SetStaticInputs({1});
113112
set_attributes_map["MirrorPad"] = SetStaticInputs({1});
114-
// set_attributes_map["NonMaxSuppression"] = SetStaticInputs({2});
115-
// set_attributes_map["NonMaxSuppressionV2"] = SetStaticInputs({2});
116-
// set_attributes_map["NonMaxSuppressionV3"] = SetStaticInputs({2});
117-
// set_attributes_map["NonMaxSuppressionV4"] = SetStaticInputs({2});
118-
// set_attributes_map["NonMaxSuppressionV5"] = SetStaticInputs({2});
119-
// set_attributes_map["OneHot"] = SetStaticInputs({1});
120113
set_attributes_map["Pad"] = SetStaticInputs({1});
121114
set_attributes_map["PadV2"] = SetStaticInputs({1});
122115
set_attributes_map["Prod"] = SetStaticInputs({1});
@@ -128,9 +121,7 @@ const std::map<std::string, SetAttributesFunction>& GetAttributeSetters() {
128121
set_attributes_map["SplitV"] = SetStaticInputs({1, 2});
129122
set_attributes_map["StridedSlice"] = SetStaticInputs({1, 2, 3});
130123
set_attributes_map["Sum"] = SetStaticInputs({1});
131-
// set_attributes_map["TopKV2"] = SetStaticInputs({1});
132124
set_attributes_map["Tile"] = SetStaticInputs({1});
133-
// set_attributes_map["Range"] = SetStaticInputs({0, 1, 2});
134125
initialized = true;
135126
}
136127
return set_attributes_map;

openvino_tensorflow/ovtf_builder.cc

Lines changed: 70 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -398,54 +398,84 @@ static Status ValuesFromConstNode(const NodeDef& node,
398398
}
399399
values->resize(n_elements);
400400

401-
auto val_lastsaved = (T)0; // cast
401+
// Extract dtype and size of the values provided in proto
402+
auto& tensor = node.attr().at("value").tensor();
403+
auto dt = node.attr().at("dtype").type();
404+
int64 val_size = 0;
405+
switch (dt) {
406+
// TODO(amprocte/NGRAPH-2502): there are more element types to support
407+
// here
408+
case DT_INT32:
409+
val_size = tensor.int_val_size();
410+
break;
411+
case DT_INT64:
412+
val_size = tensor.int64_val_size();
413+
break;
414+
case DT_FLOAT:
415+
val_size = tensor.float_val_size();
416+
break;
417+
case DT_BOOL:
418+
val_size = tensor.bool_val_size();
419+
break;
420+
case DT_DOUBLE:
421+
val_size = tensor.double_val_size();
422+
break;
423+
default:
424+
OVTF_VLOG(0) << "Const node has empty tensor and we don't know how to "
425+
"handle this element type";
426+
OVTF_VLOG(0) << node.DebugString();
427+
OVTF_VLOG(0) << shape.DebugString();
428+
return errors::Unimplemented("Encountered unknown element type ",
429+
DataType_Name(dt), " on an empty tensor");
430+
}
402431

432+
auto val_lastsaved = (T)0; // cast
403433
for (auto i = 0; i < n_elements; i++) {
404-
auto& tensor = node.attr().at("value").tensor();
405-
auto dt = node.attr().at("dtype").type();
406-
int64 val_size = 0;
407-
auto val_i = (T)0; // cast
408-
switch (dt) {
409-
// TODO(amprocte/NGRAPH-2502): there are more element types to support
410-
// here
411-
case DT_INT32:
412-
val_size = tensor.int_val_size();
413-
if (val_size > 0) val_i = tensor.int_val()[i];
414-
break;
415-
case DT_INT64:
416-
val_size = tensor.int64_val_size();
417-
if (val_size > 0) val_i = tensor.int64_val()[i];
418-
break;
419-
case DT_FLOAT:
420-
val_size = tensor.float_val_size();
421-
if (val_size > 0) val_i = tensor.float_val()[i];
422-
break;
423-
case DT_BOOL:
424-
val_size = tensor.bool_val_size();
425-
if (val_size > 0) val_i = tensor.bool_val()[i];
426-
break;
427-
case DT_DOUBLE:
428-
val_size = tensor.double_val_size();
429-
if (val_size > 0) val_i = tensor.double_val()[i];
430-
break;
431-
default:
432-
OVTF_VLOG(0)
433-
<< "Const node has empty tensor and we don't know how to "
434-
"handle this element type";
435-
OVTF_VLOG(0) << node.DebugString();
436-
OVTF_VLOG(0) << shape.DebugString();
437-
return errors::Unimplemented("Encountered unknown element type ",
438-
DataType_Name(dt),
439-
" on an empty tensor");
440-
}
434+
// Default value set to 0 and typecasted to the dtype of the const op
435+
auto val_i = (T)0;
436+
// If no values are specified for the const node, fill all the values with
437+
// default value or return error based on the TF version
441438
if (val_size == 0) {
442439
#if (TF_MAJOR_VERSION > 1 && TF_MINOR_VERSION >= 7)
443-
val_i = 0;
440+
(*values)[i] = val_i;
444441
#else
445442
return errors::InvalidArgument("Empty values vector");
446443
#endif
444+
continue;
445+
}
447446

448-
} else if (i < val_size) {
447+
// If the values are same for all the elements or repeating after certain
448+
// index, then copy the single value or the last occured value for all the
449+
// remaining indices
450+
if (i < val_size) {
451+
switch (dt) {
452+
// TODO(amprocte/NGRAPH-2502): there are more element types to support
453+
// here
454+
case DT_INT32:
455+
val_i = tensor.int_val()[i];
456+
break;
457+
case DT_INT64:
458+
val_i = tensor.int64_val()[i];
459+
break;
460+
case DT_FLOAT:
461+
val_i = tensor.float_val()[i];
462+
break;
463+
case DT_BOOL:
464+
val_i = tensor.bool_val()[i];
465+
break;
466+
case DT_DOUBLE:
467+
val_i = tensor.double_val()[i];
468+
break;
469+
default:
470+
OVTF_VLOG(0)
471+
<< "Const node has empty tensor and we don't know how to "
472+
"handle this element type";
473+
OVTF_VLOG(0) << node.DebugString();
474+
OVTF_VLOG(0) << shape.DebugString();
475+
return errors::Unimplemented("Encountered unknown element type ",
476+
DataType_Name(dt),
477+
" on an empty tensor");
478+
}
449479
(*values)[i] = val_i;
450480
val_lastsaved = val_i;
451481
} else {
@@ -4412,7 +4442,6 @@ Status Builder::TranslateGraph(
44124442
OVTF_VLOG(5) << "Not using Fused translation for "
44134443
<< "CTCGreedyDecoder and SparseToDense Ops";
44144444
}
4415-
//
44164445

44174446
const function<Status(const Node*, const std::vector<const Tensor*>&,
44184447
Builder::OpMap&)>* op_fun;

0 commit comments

Comments
 (0)