include_training_kernels.h#
-
namespace onnx_light
Alias that makes onnx-light headers compatible with code that references
ONNX_LIGHT_NAMESPACE(the macro used in the standard onnx package).Set to
ONNX_LIGHT_NAMESPACEso both names resolve to the same namespace.Symbol-visibility attribute for the public onnx-light C++ API.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_light(via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs fromonnx.-
namespace onnx_kernels
-
namespace kernel
-
class Adagrad : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_training_kernels.h>
Reference implementation of
ai.onnx.preview.training::Adagrad(v1).Computes one iteration of the ADAGRAD stochastic gradient based optimization algorithm for an arbitrary number
N >= 1of optimized tensors. For each optimized tensorX_i(with gradientG_iand accumulated squared gradientH_i) the kernel evaluates the pseudo-code documented in the ONNX schema:R_adjusted = R / (1 + T * decay_factor) G_reg = norm_coefficient * X + G H_new = H + G_reg * G_reg H_sqrt = sqrt(H_new) + epsilon X_new = X - R_adjusted * G_reg / H_sqrt
and returns
{X_new_1..N, H_new_1..N}. All optimized tensors share the same scalar inputsR(FLOAT) andT(INT64). Only FLOAT tensors are supported.Public Functions
-
std::vector<Tensor> operator()(const Tensor &R, const Tensor &T, const std::vector<Tensor> &Xs, const std::vector<Tensor> &Gs, const std::vector<Tensor> &Hs, float epsilon = 0.0f, float decay_factor = 0.0f, float norm_coefficient = 0.0f) const#
Computes one Adagrad iteration for
N == Xs.size()optimized tensors and allocates fresh output tensors.Xs,GsandHsmust all have the same length and pairwise-matching FLOAT shapes.Rmust be a scalar FLOAT tensor andTa scalar INT64 tensor. The trailingepsilon,decay_factorandnorm_coefficientparameters mirror the Adagrad ONNX schema attributes; defaults match the schema defaults.
-
void operator()(const Tensor &R, const Tensor &T, const std::vector<Tensor> &Xs, const std::vector<Tensor> &Gs, const std::vector<Tensor> &Hs, std::vector<Tensor> &outputs, float epsilon = 0.0f, float decay_factor = 0.0f, float norm_coefficient = 0.0f) const#
In-place overload writing into caller-allocated
outputs. The vector must contain exactly2 * Xs.size()tensors in the layout{X_new_1..N, H_new_1..N}where each output already matches the FLOAT data type, shape and buffer size of the corresponding optimized tensor.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
std::vector<Tensor> operator()(const Tensor &R, const Tensor &T, const std::vector<Tensor> &Xs, const std::vector<Tensor> &Gs, const std::vector<Tensor> &Hs, float epsilon = 0.0f, float decay_factor = 0.0f, float norm_coefficient = 0.0f) const#
-
class Adam : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_training_kernels.h>
Reference implementation of
ai.onnx.preview.training::Adam(v1).Computes one iteration of the Adam stochastic gradient based optimization algorithm for an arbitrary number
N >= 1of optimized tensors. For each optimized tensorX_i(with gradientG_i, accumulated gradientV_iand accumulated squared gradientH_i) the kernel evaluates the pseudo-code documented in the ONNX schema:G_reg = norm_coefficient * X + G V_new = alpha * V + (1 - alpha) * G_reg H_new = beta * H + (1 - beta) * G_reg * G_reg H_sqrt = sqrt(H_new) + epsilon R_adjusted = T > 0 ? R * sqrt(1 - beta^T) / (1 - alpha^T) : R X_new = X - R_adjusted * V_new / H_sqrt X_final = (1 - norm_coefficient_post) * X_new
and returns
{X_final_1..N, V_new_1..N, H_new_1..N}. All optimized tensors share the same scalar inputsR(FLOAT) andT(INT64). Only FLOAT tensors are supported.Public Functions
-
std::vector<Tensor> operator()(const Tensor &R, const Tensor &T, const std::vector<Tensor> &Xs, const std::vector<Tensor> &Gs, const std::vector<Tensor> &Vs, const std::vector<Tensor> &Hs, float alpha = 0.9f, float beta = 0.999f, float epsilon = 1e-6f, float norm_coefficient = 0.0f, float norm_coefficient_post = 0.0f) const#
Computes one Adam iteration for
N == Xs.size()optimized tensors and allocates fresh output tensors.Xs,Gs,VsandHsmust all have the same length and pairwise-matching FLOAT shapes.Rmust be a scalar FLOAT tensor andTa scalar INT64 tensor. The trailingalpha,beta,epsilon,norm_coefficientandnorm_coefficient_postparameters mirror the Adam ONNX schema attributes; defaults match the schema defaults.
-
void operator()(const Tensor &R, const Tensor &T, const std::vector<Tensor> &Xs, const std::vector<Tensor> &Gs, const std::vector<Tensor> &Vs, const std::vector<Tensor> &Hs, std::vector<Tensor> &outputs, float alpha = 0.9f, float beta = 0.999f, float epsilon = 1e-6f, float norm_coefficient = 0.0f, float norm_coefficient_post = 0.0f) const#
In-place overload writing into caller-allocated
outputs. The vector must contain exactly3 * Xs.size()tensors in the layout{X_final_1..N, V_new_1..N, H_new_1..N}where each output already matches the FLOAT data type, shape and buffer size of the corresponding optimized tensor.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
std::vector<Tensor> operator()(const Tensor &R, const Tensor &T, const std::vector<Tensor> &Xs, const std::vector<Tensor> &Gs, const std::vector<Tensor> &Vs, const std::vector<Tensor> &Hs, float alpha = 0.9f, float beta = 0.999f, float epsilon = 1e-6f, float norm_coefficient = 0.0f, float norm_coefficient_post = 0.0f) const#
-
class Momentum : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_training_kernels.h>
Reference implementation of
ai.onnx.preview.training::Momentum(v1).Computes one iteration of the SGD-with-Momentum stochastic gradient optimization algorithm for an arbitrary number
N >= 1of optimized tensors. For each optimized tensorX_i(with gradientG_iand momentum bufferV_i) the kernel evaluates the pseudo-code documented in the ONNX schema:G_reg = norm_coefficient * X + G beta_adjusted = T > 0 ? beta : 1 V_new = alpha * V + beta_adjusted * G_reg // mode == "standard": X_new = X - R * V_new // mode == "nesterov": X_new = X - R * (G_reg + alpha * V_new)
and returns
{X_new_1..N, V_new_1..N}. All optimized tensors share the same scalar inputsR(FLOAT) andT(INT64). Only FLOAT tensors are supported.Public Types
Public Functions
-
std::vector<Tensor> operator()(const Tensor &R, const Tensor &T, const std::vector<Tensor> &Xs, const std::vector<Tensor> &Gs, const std::vector<Tensor> &Vs, float alpha, float beta, float norm_coefficient, Mode mode = Mode::kStandard) const#
Computes one Momentum iteration for
N == Xs.size()optimized tensors and allocates fresh output tensors.Xs,GsandVsmust all have the same length and pairwise-matching FLOAT shapes.Rmust be a scalar FLOAT tensor andTa scalar INT64 tensor. The trailingalpha,beta,norm_coefficientandmodeparameters mirror the Momentum ONNX schema attributes.
-
void operator()(const Tensor &R, const Tensor &T, const std::vector<Tensor> &Xs, const std::vector<Tensor> &Gs, const std::vector<Tensor> &Vs, std::vector<Tensor> &outputs, float alpha, float beta, float norm_coefficient, Mode mode = Mode::kStandard) const#
In-place overload writing into caller-allocated
outputs. The vector must contain exactly2 * Xs.size()tensors in the layout{X_new_1..N, V_new_1..N}where each output already matches the FLOAT data type, shape and buffer size of the corresponding optimized tensor.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
std::vector<Tensor> operator()(const Tensor &R, const Tensor &T, const std::vector<Tensor> &Xs, const std::vector<Tensor> &Gs, const std::vector<Tensor> &Vs, float alpha, float beta, float norm_coefficient, Mode mode = Mode::kStandard) const#
-
class Adagrad : public onnx_light::onnx_kernels::kernel::KernelBase#
-
namespace kernel
-
namespace onnx_kernels