Cleanup LSTM tests: Set the weights and biases, and apply the delegate only once.

The previous comment was not correct.

PiperOrigin-RevId: 322829351
Change-Id: I7f1683a3e01ffa812e9f9dbcec82d843ede3135b
This commit is contained in:
Robert David 2020-07-23 11:33:13 -07:00 committed by TensorFlower Gardener
parent 0ff8f604fe
commit 6bfea7624a

View File

@ -134,7 +134,10 @@ class LSTMOpModel : public SingleOpModel {
LSTMKernelType_FULL, asymmetric_quantize_inputs)
.Union());
BuildInterpreter({}); // Input sizes are already set up.
// Input shapes are already set up, no need to pass them again.
BuildInterpreter(/*input_shapes=*/{}, /*num_threads=*/-1,
/*allow_fp32_relax_to_fp16=*/false,
/*apply_delegate=*/false);
}
void SetInputToInputWeights(const std::vector<float>& f) {
@ -329,15 +332,11 @@ class BaseLstmOpTest
// Compares output up to tolerance to the result of the lstm given the input.
void VerifyGoldens(LSTMOpModel* lstm, float tolerance) {
// Weights are set twice:
// - The delegate, if used, needs to know the scales and zero-points of
// quantized tensors, which are computed dynamically when weights are set,
// so weights have to be set before applying the delegate.
// - Applying a delegate will invalidate the tensor data so weights have to
// be set a second time.
// The delegate, if used, needs to know the scales and zero-points of
// quantized tensors, which are computed dynamically when weights are set,
// so weights have to be set before applying the delegate.
SetAllWeightsAndBiases(lstm);
lstm->ApplyDelegate();
SetAllWeightsAndBiases(lstm);
const int num_batches = lstm_input_.size();
EXPECT_GT(num_batches, 0);