(y: HLOTensor, dy: HLOTensor, axis: int = -1)
| 720 | |
| 721 | |
| 722 | def softmax_grad(y: HLOTensor, dy: HLOTensor, axis: int = -1): |
| 723 | assert isinstance(axis, int), f"axis should be int, but get {axis}({type(axis)})" |
| 724 | ydy = y * dy |
| 725 | ydy_sum = ydy.sum(axis=axis, keepdims=True) |
| 726 | dx = ydy - y * ydy_sum |
| 727 | return dx |
| 728 | |
| 729 | |
| 730 | @register_lower_rule(mops.Softmax) |
no test coverage detected