Skip to content

Commit

Permalink
[tflchef] Tidy more disabled codes (#13667)
Browse files Browse the repository at this point in the history
This will tidy more disabled codes that was extract to separate methods.

ONE-DCO-1.0-Signed-off-by: SaeHie Park <[email protected]>
  • Loading branch information
seanshpark authored Aug 18, 2024
1 parent e61c5b0 commit f3d7383
Showing 1 changed file with 0 additions and 138 deletions.
138 changes: 0 additions & 138 deletions compiler/tflchef/core/src/ModelChef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,60 +888,6 @@ void ModelChef::cook(const ::tflchef::ModelRecipe &model_recipe)

gather_operator_codes(model_recipe);

#if 0
// Create OperatorCode with Builtin Operator
_builtin_code_map = gather_builtincode_map(model_recipe);
for (auto const &opcode : _builtin_code_map)
{
tflite::OperatorCodeBuilder code_builder{*_flatbuffer_builder};
// 127 is BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES
// This is the way to handle deprecated builtin code
// See
// https://github.com/tensorflow/tensorflow/blob/a0afe8f9218be5eb9ed5dffc2dff652996da8c28/tensorflow/lite/schema/schema.fbs#L1061-L1077
if (opcode.first < 127)
{
code_builder.add_deprecated_builtin_code(opcode.first);
}
else
{
code_builder.add_deprecated_builtin_code(
::tflite::BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES);
}
code_builder.add_version(opcode.second);
code_builder.add_builtin_code(opcode.first);
auto code = code_builder.Finish();
// Update OperatorCode vector
_code_vec.emplace_back(code);
}

// Create OperatorCode with Custom Operator
std::set<std::string> custom_code_set = gather_customcode_set(model_recipe);
_custom_code_vec = {custom_code_set.begin(), custom_code_set.end()};

for (auto opcode : _custom_code_vec)
{
auto custom_code = _flatbuffer_builder->CreateString(opcode);
tflite::OperatorCodeBuilder code_builder{*_flatbuffer_builder};
code_builder.add_deprecated_builtin_code(tflite::BuiltinOperator_CUSTOM);
code_builder.add_custom_code(custom_code);
code_builder.add_builtin_code(tflite::BuiltinOperator_CUSTOM);
auto code = code_builder.Finish();
// Update OperatorCode vector
_code_vec.emplace_back(code);
}
#endif

#if 0
// Create an Empty Buffer
//
// Buffer 0 SHOULD be an empty buffer in TensorFlow Lite model file
// (Please refer to the comment for Tensor.buffer field in schema)
{
tflite::BufferBuilder buffer_builder{*_flatbuffer_builder};
_buffer_vec.emplace_back(buffer_builder.Finish());
}
#endif

//
// Create Main graph
//
Expand Down Expand Up @@ -973,90 +919,6 @@ void ModelChef::cook(const ::tflchef::ModelRecipe &model_recipe)

gather_signature_defs(model_recipe);

#if 0
// Create Signature-Def
//
for (int s = 0; s < model_recipe.signature_def_size(); ++s)
{
// load from recipe
const auto &rec_signature_def = model_recipe.signature_def(s);

std::vector<flatbuffers::Offset<::tflite::TensorMap>> tensormap_inputs;
std::vector<flatbuffers::Offset<::tflite::TensorMap>> tensormap_outputs;

// which subgraph index to cook
auto subgraph_index = 0;
if (rec_signature_def.has_subgraph_index())
{
subgraph_index = rec_signature_def.subgraph_index();
}
assert(subgraph_index < _symbol_tables.size());
auto &symbol_table = _symbol_tables[subgraph_index];

// cook for inputs
for (int si = 0; si < rec_signature_def.inputs_size(); ++si)
{
// recipe for input TensorMap
auto rec_tm_input = rec_signature_def.inputs(si);
auto name = _flatbuffer_builder->CreateString(rec_tm_input.name());
uint32_t tensor_index = 0;
// either tensor or tensor_index should exist
assert(rec_tm_input.has_tensor() || rec_tm_input.has_tensor_index());
if (rec_tm_input.has_tensor())
{
// we can get tensor_index from symbol_table
auto tensor = rec_tm_input.tensor();
tensor_index = symbol_table[tensor];
}
else
{
// or we can use tensor_index itself
tensor_index = rec_tm_input.tensor_index();
}

::tflite::TensorMapBuilder tensormap_builder{*_flatbuffer_builder};
tensormap_builder.add_name(name);
tensormap_builder.add_tensor_index(tensor_index);
tensormap_inputs.push_back(tensormap_builder.Finish());
}
// cook for outputs, same as inputs
for (int so = 0; so < rec_signature_def.outputs_size(); ++so)
{
auto rec_tm_output = rec_signature_def.outputs(so);
auto name = _flatbuffer_builder->CreateString(rec_tm_output.name());
uint32_t tensor_index = 0;
assert(rec_tm_output.has_tensor() || rec_tm_output.has_tensor_index());
if (rec_tm_output.has_tensor())
{
auto tensor = rec_tm_output.tensor();
tensor_index = symbol_table[tensor];
}
else
{
tensor_index = rec_tm_output.tensor_index();
}

::tflite::TensorMapBuilder tensormap_builder{*_flatbuffer_builder};
tensormap_builder.add_name(name);
tensormap_builder.add_tensor_index(tensor_index);
tensormap_outputs.push_back(tensormap_builder.Finish());
}

auto inputs = _flatbuffer_builder->CreateVector(tensormap_inputs);
auto outputs = _flatbuffer_builder->CreateVector(tensormap_outputs);
auto signature_key = _flatbuffer_builder->CreateString(rec_signature_def.signature_key());
// TODO add validation for signature_key

::tflite::SignatureDefBuilder signature_def_builder{*_flatbuffer_builder};
signature_def_builder.add_inputs(inputs);
signature_def_builder.add_outputs(outputs);
signature_def_builder.add_signature_key(signature_key);
signature_def_builder.add_subgraph_index(rec_signature_def.subgraph_index());

_signdef_vec.emplace_back(signature_def_builder.Finish());
}
#endif

// Create "Model" arguments
auto buffers = _flatbuffer_builder->CreateVector(_buffer_vec);
auto signdefs = _flatbuffer_builder->CreateVector(_signdef_vec);
Expand Down

0 comments on commit f3d7383

Please sign in to comment.