ai.onnx.Elu

ai.onnx · standard ONNX operator · ONNX opset ≥ 6

Description

Applies the Exponential Linear Unit activation elementwise: f(x) = x for x >= 0, and f(x) = alpha * (exp(x) - 1) for x < 0. The alpha coefficient controls the saturation value for negative inputs.

See the ONNX Elu spec for the reference semantics.

Inputs

Name Upstream name Logical dtype Rank Shape Description Presence
x X T — — Values transformed elementwise by the ELU activation. required

Outputs

Name Upstream name Logical dtype Rank Shape Description Presence
y Y T same as x same as x Output tensor with ELU applied elementwise; same shape as X. required

Attributes

Default values (overridable per request):

Attribute Default Description
alpha 1 Scaling coefficient applied to the exponential term for negative inputs; defaults to 1.0.

Type constraints

Variable Allowed dtypes
T float32, float16

Files

Use with @huggingface/kernels

npm install --save-exact @huggingface/kernels@0.0.1-preview.4

Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.

Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.

The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version. It follows the v1 branch as fixes land. To pin exact artifact bytes, pass a 40-character commit revision instead of version.

import { getKernel } from "@huggingface/kernels";

const kernel = await getKernel("webgpu-kernels/ai.onnx.Elu", { version: 1 });

const xData = Float32Array.of(
  1.7640524, 0.4001572, 0.978738, 2.2408931, 1.867558, -0.9772779, 0.95008844,
  -0.1513572, -0.10321885, 0.41059852, 0.14404356, 1.4542735, 0.7610377, 0.121675014,
  0.44386324, 0.33367434, 1.4940791, -0.20515826, 0.3130677, -0.85409576, -2.5529897,
  0.6536186, 0.8644362, -0.742165, 2.2697546, -1.4543657, 0.045758516, -0.18718386,
  1.5327792, 1.4693588, 0.15494743, 0.37816253, -0.88778573, -1.9807965, -0.34791216,
  0.15634897, 1.2302907, 1.2023798, -0.3873268, -0.30230275, -1.048553, -1.420018,
  -1.7062702, 1.9507754, -0.5096522, -0.4380743, -1.2527953, 0.7774904, -1.6138978,
  -0.21274029, -0.89546657, 0.3869025, -0.51080513, -1.1806322, -0.028182229, 0.42833188,
  0.06651722, 0.3024719, -0.6343221, -0.36274117,
);

const { y } = await kernel({ x: { data: xData, shape: [3, 4, 5] } });
console.log({ y });
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.