apple / apple/coremltools

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

Open
#2,747 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

## 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
- PR #2725 (PyTorch frontend fix)
- Issue #2687 (original overflow report)
- Issue #2359 (Mish fp16 errors)

Contributor guide

Open the contributing guide

Research direction

Start at coremltools/converters/mil/frontend/tensorflow/ops.py:2149 and compare the TensorFlow Softplus converter with the stable PyTorch change in PR #2725. Apply the stable Softplus handling to the TensorFlow path, or confirm a graph-rewrite approach covers it, and verify that the converter no longer emits the native softplus operation for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.