Creates a graph node for clamping values to a range: clamp(x, min, max)
ggml_clamp(ctx, a, min_val, max_val)Tensor with values clamped to [min_val, max_val]
GGML context
Input tensor
Minimum value
Maximum value
GGML_OP_CLAMP has no backward pass, and the node it builds is a view
of its input. A graph containing it therefore cannot be differentiated: the
backward pass aborts with "inplace operations are currently not
supported" rather than returning an error. This matters inside
ggml_layer_custom, whose gradients flow only through
operations that implement a backward pass.
For a trainable equivalent, express the clamp with operations that do:
min(x, hi) is x - ggml_relu(ctx, x - hi) and max(x, lo)
is lo + ggml_relu(ctx, x - lo).
ggml_relu for the differentiable formulation above.