tensorflow / tensorflow/tflite-micro

Fix "Fouble" (Fake Double) precision errors across TFLM Kernels

Open
#3,271 0 comments 0 reactions 1 assignee View on GitHub

@veblush is already working on this.

Since Dec 18, 2025.

type:feature
Dominant language
C++
Stars
3.1k
Forks
1.1k
Avg merge
1d 5h
Merged PRs (30d)
43

Description

Problem Statement

Multiple kernels perform intermediate scaling calculations using 32-bit float precision before assigning to a 64-bit double variable. This "Fouble" (Fake Double) pattern leads to precision loss and state drift in recurrent models.

// Example values that require more than 24 bits of mantissa (float precision)
float input_scale = 1.2345678f;
float feature_scale = 1.2345678f;

// (BAD) Fouble: Multiplication happens in float, then is cast to double
double fouble_result = static_cast<double>(input_scale * feature_scale);

// (GOOD) Defoubled: At least one operand is cast to double first
double defoubled_result = static_cast<double>(input_scale) * feature_scale;

This issue has been identified and addressed in several previous PRs (e.g., #1492). However, those attempts were ultimately discarded because the fix requires a synchronized change within the main TFLite codebase.

Proposed Changes

Force double-precision arithmetic by casting an operand early (e.g., static_cast(a) * b).

Hard Constraints & Coordination:
  • Bit-Exactness: All changes must maintain parity with TFLite reference kernels. Coordination with the main TensorFlow repository is required.

  • Vendor Kernels: Optimized implementations for specific hardware (e.g., ARM, Cadence) must be updated in tandem with reference changes to ensure consistent behavior across platforms.

  • Rollout Strategy: We will avoid a single monolithic PR. Instead, we will submit incremental PRs grouped by source file to facilitate easier regression testing and binary-size monitoring.

Target Files:
  • kernels/activations_common.cc
  • kernels/div.cc
  • kernels/elementwise.cc
  • kernels/hard_swish_common.cc
  • kernels/leaky_relu_common.cc
  • kernels/softmax_common.cc
  • kernels/squared_difference.cc
  • kernels/sub_common.cc
  • kernels/svdf_common.cc

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.