MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / linear

Function linear

imperative/python/megengine/functional/nn.py:132–150  ·  view source on GitHub ↗

r"""Applies a linear transformation to the input tensor. Refer to :class:`~.module.linear.Linear` for more information. Args: inp: input tensor with shape `(N, in_features)`. weight: weight with shape `(out_features, in_features)`. bias: bias with shape `(out_featur

(
    inp: Tensor, weight: Tensor, bias: Optional[Tensor] = None, compute_mode="default",
)

Source from the content-addressed store, hash-verified

130
131
132def linear(
133 inp: Tensor, weight: Tensor, bias: Optional[Tensor] = None, compute_mode="default",
134) -> Tensor:
135 r"""Applies a linear transformation to the input tensor.
136
137 Refer to :class:`~.module.linear.Linear` for more information.
138
139 Args:
140 inp: input tensor with shape `(N, in_features)`.
141 weight: weight with shape `(out_features, in_features)`.
142 bias: bias with shape `(out_features,)`. Default: None
143 """
144 compute_mode = _config._get_actual_op_param(compute_mode, _config.__compute_mode)
145 ret = _matmul(inp, weight, transpose_b=True, compute_mode=compute_mode)
146 if bias is not None:
147 if amp._enabled:
148 bias = bias.astype("float16")
149 ret += bias
150 return ret
151
152
153def conv1d(

Callers 2

calc_linearMethod · 0.85

Calls 2

_matmulFunction · 0.85
astypeMethod · 0.45

Tested by 1