Repository navigation
Consolidate scalar sigmoid onto a shared overflow-safe helper - #317
Merged
Merged
Conversation
DetectionDecoder and SegmentationPostprocessor each defined their own scalar `sigmoid(_:)`. The video decoder's branches on the sign so the exponent argument stays non-positive (overflow-safe); the segmenter's naive `1/(1+exp(-x))` underflows large-negative logits to exactly 0. Add one shared `sigmoid` in CoreAIShared/Runtime/VectorMath.swift (the sign-branched form) and route both subsystems and their tests through it, deleting the two duplicates. VectorMathTests characterizes both extremes. Intended behavior change: the segmenter path now returns a tiny positive value instead of exactly 0 for large-negative logits — negligible for any threshold > 0. WS4 PR2.
stikves
requested review from
alejandro-isaza,
carinapeng,
kevchengcodes and
tjia1818
October 1, 2026 18:14
- Condense the `sigmoid` doc comment and mark it `@inline(__always)` (it runs per-pixel on the detector/segmenter paths). - Delete the `sigmoidKnownValues` (image-segmenter) and `sigmoidStability` (video-segmenter) tests: `VectorMathTests` already covers both the known values and the overflow-safe extremes.
kevchengcodes
approved these changes
Oct 5, 2026
kevchengcodes
left a comment
Contributor
There was a problem hiding this comment.
Looks like you addressed the comments in #320 here. Thanks for doing that, I'll leave it up to you to determine PR merge strategy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both
DetectionDecoder(CoreAIVideoSegmenter) andSegmentationPostprocessor(CoreAIImageSegmenter) defined their own scalarsigmoid(_:). The video decoder branches on the sign ofxso the exponent argument stays non-positive (overflow-safe); the segmenter's naive1 / (1 + exp(-x))underflows large-negative logits to exactly0. This folds both onto one sharedsigmoidinCoreAIShared/Runtime/VectorMath.swift(the sign-branched form) and routes both subsystems and their tests through it.Behavior change: the segmenter now returns a tiny positive value instead of
0for large-negative logits, well below any threshold it applies.Adds
VectorMathTestsfor both extremes; the existing segmenter and tracker-score suites were migrated to the shared function and pass.Part of the shared-utility cleanup.