Replace the MPSGraph-based sigmoid_backward_out_mps with a native Metal kernel registered through the shared sigmoid_backward_stub.
Complex types are handled via the conjugated derivative (grad * conj((1 - output) * output)), matching CUDA's behavior.
Microbenchmark (us per call, A/B from the same script with only the impl
swapped):
shape|dtype mpsgraph metal speedup
1024|float32 12.81 7.43 1.72x
1024|float16 14.82 7.10 2.09x
1024|bfloat16 12.11 7.15 1.69x
1024x1024|float16 18.56 14.67 1.26x
1024x1024|float32 45.02 40.06 1.12x
8x1024x1024|float32 382.21 376.67 1.01x
32x1024x1024|float32 1487.84 1493.75 1.00x
Metal wins on dispatch overhead at small sizes; parity at large sizes where
the op is memory-bandwidth bound, as expected for ~3 FLOPs/element.
Co-Authored-By: Claude Opus 4.7 [email protected]
Pull Request resolved: #187151
Approved by: https://github.com/Skylion007
SOCIAL SHARE CARD GENERATOR