Reshape conv bias to channel-last broadcast shape and add to tmp in-place. After the convolution the activation is in channel-last layout, so the bias (shape ``[C_out]``) must be reshaped to ``[1, …, 1, -1]`` with *ndim* dimensions before being added. Does nothing when *bias* is ``None
(
P: MLXProgramBuilder, bias: Optional[Slot], tmp: Slot, ndim: int
)
| 2285 | |
| 2286 | |
| 2287 | def _emit_conv_bias( |
| 2288 | P: MLXProgramBuilder, bias: Optional[Slot], tmp: Slot, ndim: int |
| 2289 | ) -> None: |
| 2290 | """Reshape conv bias to channel-last broadcast shape and add to tmp in-place. |
| 2291 | |
| 2292 | After the convolution the activation is in channel-last layout, so the bias |
| 2293 | (shape ``[C_out]``) must be reshaped to ``[1, …, 1, -1]`` with *ndim* |
| 2294 | dimensions before being added. Does nothing when *bias* is ``None``. |
| 2295 | """ |
| 2296 | if bias is None: |
| 2297 | return |
| 2298 | _, tmp2 = P.make_tmp_slot() |
| 2299 | shape = [IntOrVid.from_literal(1)] * (ndim - 1) + [IntOrVid.from_literal(-1)] |
| 2300 | P.emit( |
| 2301 | ReshapeNode( |
| 2302 | x=P.slot_to_tid(bias), |
| 2303 | out=P.slot_to_tid(tmp2), |
| 2304 | shape=shape, |
| 2305 | ) |
| 2306 | ) |
| 2307 | P.emit( |
| 2308 | AddNode( |
| 2309 | a=P.slot_to_tid(tmp), |
| 2310 | b=P.slot_to_tid(tmp2), |
| 2311 | out=P.slot_to_tid(tmp), |
| 2312 | ) |
| 2313 | ) |
| 2314 | |
| 2315 | |
| 2316 | def _emit_conv( |
no test coverage detected