Skip to content

TensorFlow frontend Softplus converter still emits native softplus op (fp16 overflow risk on ANE) #2747

Description

@Ashutosh0x

Problem

The TensorFlow/Keras frontend's Softplus converter at coremltools/converters/mil/frontend/tensorflow/ops.py:2149 still emits the native mb.softplus MIL op:

python
def Softplus(context, node):
...
x = mb.softplus(x=x, name=node.name) # native op → fp16/ANE overflow

This is the same native op that overflows in fp16 on Apple Neural Engine at x ≈ 10.4, causing output collapse to 0.

Context

PR #2725 fixes this for the PyTorch frontend by replacing mb.softplus() with the numerically stable decomposition max(x,0) + log(1+exp(-|x|)). The TF frontend was intentionally left out of scope since both original issues (#2687, #2359) originated from PyTorch models.

Proposed Fix

Apply the same _stable_softplus_mil(x) helper to the TF Softplus converter. Alternatively, implement this at the MIL graph-rewrite pass level so all frontends are covered (the DRY fix, as suggested by @ChinChangYang in the PR #2725 review).

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions