MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / scale

Function scale

python/paddle/tensor/math.py:237–358  ·  view source on GitHub ↗

Scale operator. Putting scale and bias to the input Tensor as following: ``bias_after_scale`` is True: .. math:: Out=scale*X+bias ``bias_after_scale`` is False: .. math:: Out=scale*(X+bias) Args: x (Te

(
    x: Tensor,
    scale: float | Tensor = 1.0,
    bias: float = 0.0,
    bias_after_scale: bool = True,
    act: str | None = None,
    name: str | None = None,
    *,
    out: Tensor | None = None,
)

Source from the content-addressed store, hash-verified

235
236
237def scale(
238 x: Tensor,
239 scale: float | Tensor = 1.0,
240 bias: float = 0.0,
241 bias_after_scale: bool = True,
242 act: str | None = None,
243 name: str | None = None,
244 *,
245 out: Tensor | None = None,
246) -> Tensor:
247 """
248 Scale operator.
249
250 Putting scale and bias to the input Tensor as following:
251
252 ``bias_after_scale`` is True:
253
254 .. math::
255 Out=scale*X+bias
256
257 ``bias_after_scale`` is False:
258
259 .. math::
260 Out=scale*(X+bias)
261
262 Args:
263 x (Tensor): Input N-D Tensor of scale operator. Data type can be bfloat16, float16, float32, float64, int8, int16, int32,
264 int64, uint8, complex64, complex128.
265 scale (float|Tensor): The scale factor of the input, it should be a float number or a 0-D Tensor with shape [] and data type as float32.
266 bias (float): The bias to be put on the input.
267 bias_after_scale (bool): Apply bias addition after or before scaling. It is useful for numeric stability in some circumstances.
268 act (str|None, optional): Activation applied to the output such as tanh, softmax, sigmoid, relu.
269 name (str|None, optional): Name for the operation. Default: None. For more information, please refer to :ref:`api_guide_Name`.
270
271 Keyword Args:
272 out (Tensor|None, optional): The output tensor. If set, the result will be stored in this Tensor. Default: None.
273
274 Returns:
275 Tensor: Output Tensor of scale operator, with shape and data type same as input.
276
277 Examples:
278 .. code-block:: pycon
279
280 >>> # scale as a float32 number
281 >>> import paddle
282
283 >>> data = paddle.arange(6).astype("float32").reshape([2, 3])
284 >>> print(data)
285 Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
286 [[0., 1., 2.],
287 [3., 4., 5.]])
288 >>> res = paddle.scale(data, scale=2.0, bias=1.0)
289 >>> print(res)
290 Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
291 [[1. , 3. , 5. ],
292 [7. , 9. , 11.]])
293
294 .. code-block:: pycon

Callers 7

negFunction · 0.70
benchmark_eager_scaleFunction · 0.50
TESTFunction · 0.50
TESTFunction · 0.50
TESTFunction · 0.50

Calls 9

append_opMethod · 0.95
append_activationMethod · 0.95
in_pir_modeFunction · 0.85
check_variable_and_dtypeFunction · 0.85
LayerHelperClass · 0.85
floatFunction · 0.50
scaleMethod · 0.45
assignMethod · 0.45

Tested by 5

TESTFunction · 0.40
TESTFunction · 0.40
TESTFunction · 0.40