ai.onnx.ReduceLogSum

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

Description

Computes log(sum(elements)) of the input tensor along the specified axes. The output rank matches the input when keepdims is 1; reduced dimensions are pruned when keepdims is 0. Reducing an empty set of values yields negative infinity.

See the ONNX ReduceLogSum spec for the reference semantics.

Differences from the ONNX spec

  • Input axes: Passed as the axes attribute instead of a tensor input.

Inputs

Name Logical dtype Rank Shape Description Presence
data T — — Input tensor to reduce. required

Outputs

Name Logical dtype Rank Shape Description Presence
reduced T derived derived Reduced output tensor containing the log of the summed elements. required

Attributes

Default values (overridable per request):

Attribute Default Description
axes [] Values of the optional ONNX axes tensor input, supplied through this request attribute; an empty list follows noop_with_empty_axes.
keepdims 1 If 1 (default in spec), the reduced dimension is retained with size 1; if 0, it is removed from the output shape.
noop_with_empty_axes 0 When 1 and axes is empty, acts as a no-op applying only the non-reduction step (log of input); when 0 (default), reduces over all axes.

Type constraints

Variable Allowed dtypes
T float32, float16

Implementation variants

One implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.

  • subgroup_last_axis — Reduces each contiguous row (the last axis, or a trailing multi-axis suffix) with subgroup collectives, reading vec4-packed when the row width is a multiple of the vector width.

Device requirements

Some implementation variants require subgroups. Other variants run without it; which variant runs also depends on the request's shapes and dtypes.

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.ReduceLogSum", { version: 1 });

const dataData = Float32Array.of(
  0.5488135, 0.71518934, 0.60276335, 0.5448832, 0.4236548, 0.6458941, 0.4375872,
  0.891773, 0.96366274, 0.3834415, 0.79172504, 0.5288949, 0.56804454, 0.92559665,
  0.071036056, 0.0871293, 0.020218397, 0.83261985, 0.77815676, 0.87001216, 0.9786183,
  0.7991586, 0.46147937, 0.7805292, 0.11827443, 0.639921, 0.14335328, 0.9446689,
  0.5218483, 0.41466194, 0.2645556, 0.7742337, 0.45615032, 0.56843394, 0.0187898,
  0.6176355, 0.6120957, 0.616934, 0.94374806, 0.6818203, 0.3595079, 0.43703195,
  0.6976312, 0.06022547, 0.6667667, 0.67063785, 0.21038257, 0.12892629, 0.31542835,
  0.36371076, 0.57019675, 0.43860152, 0.9883738, 0.10204481, 0.20887676, 0.16130951,
  0.6531083, 0.2532916, 0.46631077, 0.2444256,
);

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

Requires WebGPU support. See the compatibility table.