Skip to content

Commit 0c7727b

Browse files
committed
Sync from upstream TF.
1 parent bbf70db commit 0c7727b

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

tensorflow/lite/core/c/common.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,4 +649,12 @@ TfLiteRunStep TfLiteTensorGetShapeKnownStep(const TfLiteTensor* t) {
649649
return kTfLiteRunStepUnknown;
650650
}
651651

652+
// Returns a sentinel value to be used as the user_data field of a TfLiteNode
653+
// when the kernel initialization fails.
654+
void* TfLiteKernelInitFailed() {
655+
static const char dummy_object = 0;
656+
const void* sentinel = &dummy_object;
657+
return const_cast<void*>(sentinel);
658+
}
659+
652660
} // extern "C"

tensorflow/lite/core/c/common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,11 @@ typedef struct TfLiteRegistration {
11611161
/// NOTE: if the data is already in the desired format, simply implement this
11621162
/// function to return `nullptr` and implement the free function to be a
11631163
/// no-op.
1164+
///
1165+
/// NOTE: For a Delegate kernel, returns `TfLiteKernelInitFailed()` if it
1166+
/// fails on the initialization. This eventually causes user's API call to
1167+
/// InterpreterBuilder::operator() or Interpreter::ModifyGraphWithDelegate()
1168+
/// to return an error.
11641169
void* (*init)(TfLiteContext* context, const char* buffer, size_t length);
11651170

11661171
/// The pointer `buffer` is the data previously returned by an init
@@ -1499,6 +1504,10 @@ TfLiteRunStep TfLiteTensorGetDataKnownStep(const TfLiteTensor* t);
14991504
/// operations.
15001505
TfLiteRunStep TfLiteTensorGetShapeKnownStep(const TfLiteTensor* t);
15011506

1507+
/// Returns a sentinel value to be used as the user_data field of a TfLiteNode
1508+
/// when the kernel initialization fails.
1509+
void* TfLiteKernelInitFailed();
1510+
15021511
/** @} */
15031512
// Ends `\addtogroup`, it's important for the doc generator that this doesn't
15041513
// include the CC code below.

tensorflow/lite/kernels/internal/portable_tensor_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ inline void BatchQuantizeFloats(const float* float_data_ptr, int n_batch,
170170
tensor_utils::SymmetricQuantizeFloats(
171171
float_data_ptr + offset, n_data, quantized_data_ptr + offset,
172172
&unused_min, &unused_max, &scaling_factors[b]);
173+
if (zero_points) zero_points[b] = 0;
173174
}
174175
}
175176
}

0 commit comments

Comments
 (0)