MCPcopy Create free account
hub / github.com/pytorch/executorch / _emit_conv_bias

Function _emit_conv_bias

backends/mlx/ops.py:2287–2313  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

2285
2286
2287def _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
2316def _emit_conv(

Callers 2

_emit_convFunction · 0.85
_emit_conv_transposeFunction · 0.85

Calls 4

AddNodeClass · 0.85
emitMethod · 0.80
slot_to_tidMethod · 0.80
make_tmp_slotMethod · 0.45

Tested by

no test coverage detected