Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Onnx Onnx Doc Strings Generator

From Leeroopedia


Knowledge Sources
Domains Documentation, Operator Definitions, Core Infrastructure
Last Updated 2026-02-10 00:00 GMT

Overview

Stores comprehensive, versioned documentation strings for ONNX operators as C++ string constants, providing the canonical reference documentation embedded directly in the ONNX library.

Description

The doc_strings.cc file is a documentation resource file that contains detailed documentation strings for a subset of ONNX operators across their various versions. Each documentation string is defined as a const char array using C++ raw string literals (R"DOC(...)DOC"), named with the pattern kDoc_{OperatorName}_ver{Version}.

The file documents approximately 65 operators spanning a wide range of ONNX functionality:

Neural network layers: GRU (v14), LSTM (v14), RNN (v14), Dropout (v13), DeformConv (v19), RoiAlign (v16), InstanceNormalization (v6), NegativeLogLikelihoodLoss (v13).

Activation functions: Relu (v6), LeakyRelu (v1), Elu (v6), Selu (v6), Sigmoid (v6), HardSigmoid (v6), HardSwish (v14), Softplus (v1), Softsign (v1), ThresholdedRelu (v10), Mish (v18), PRelu (v7), Tanh (v6).

Math operations: Exp (v6), Log (v6), Pow (v13), Sqrt (v6), Reciprocal (v6), Neg (v6), Sign (v9), Erf (v9), Round (v11), Det (v11), MatMul (v9), CumSum (v11).

Trigonometric functions: Sin (v7), Cos (v7), Tan (v7), Asin (v7), Acos (v7), Atan (v7), Sinh (v9), Cosh (v9), Asinh (v9), Acosh (v9), Atanh (v9).

Tensor manipulation: Reshape (v24), Squeeze (v24), Unsqueeze (v24), Flatten (v24), Expand (v8), Tile (v6), Pad (v24), Shape (v24), Size (v24), Compress (v9), ConstantOfShape (v24), Constant (v24), SpaceToDepth (v1).

Type operations: Cast (v24), CastLike (v24), DequantizeLinear (v24).

Control flow: Loop (v23), Scan (v24).

Sampling: RandomUniform (v1), RandomNormal (v1), RandomUniformLike (v1), RandomNormalLike (v1), Bernoulli (v15), Multinomial (v7).

Other: Where (v9), NonMaxSuppression (v10), MaxUnpool (v11), EyeLike (v9), GridSample (v20), Upsample (v7), LpNormalization (v1).

Each documentation string includes a description of the operator's behavior, mathematical formulas where applicable, and in many cases detailed examples (e.g., the Cast operator has extensive tables for float8 conversion rules). The longer strings, such as for Loop (v23), Scan (v24), Cast (v24), and NegativeLogLikelihoodLoss (v13), include pseudo-code, sample graph definitions, and multiple worked examples.

The entire documentation content is conditionally compiled: when the __ONNX_NO_DOC_STRINGS preprocessor macro is defined, all constants are set to empty strings, allowing builds that minimize binary size by stripping documentation.

Usage

These documentation constants are referenced by operator schema registration code (in files like onnx/defs/nn/defs.cc, onnx/defs/math/defs.cc, etc.) to attach documentation to OpSchema objects. The strings are then accessible through the schema API for generating documentation pages, displaying help in tools, and providing user-facing descriptions through the Python interface.

Code Reference

Source Location

Signature

namespace ONNX_NAMESPACE {

#ifndef __ONNX_NO_DOC_STRINGS

// Neural network operators
extern const char kDoc_GRU_ver14[];
extern const char kDoc_LSTM_ver14[];
extern const char kDoc_RNN_ver14[];
extern const char kDoc_Dropout_ver13[];

// Activation functions
extern const char kDoc_Relu_ver6[];
extern const char kDoc_Sigmoid_ver6[];
extern const char kDoc_Tanh_ver6[];
extern const char kDoc_LeakyRelu_ver1[];

// Tensor manipulation
extern const char kDoc_Reshape_ver24[];
extern const char kDoc_Squeeze_ver24[];
extern const char kDoc_Unsqueeze_ver24[];
extern const char kDoc_Flatten_ver24[];
extern const char kDoc_Pad_ver24[];

// Type operations
extern const char kDoc_Cast_ver24[];
extern const char kDoc_DequantizeLinear_ver24[];

// Control flow
extern const char kDoc_Loop_ver23[];
extern const char kDoc_scan_24[];

// ... approximately 65 operator doc strings total ...

#else
// All doc strings are empty when __ONNX_NO_DOC_STRINGS is defined
#endif

} // namespace ONNX_NAMESPACE

Import

#include "onnx/defs/doc_strings.h"

I/O Contract

Inputs

Name Type Required Description
(none) N/A N/A This file defines constants; it takes no runtime inputs

Outputs

Name Type Description
kDoc_{Op}_ver{N} const char[] Documentation string for the specified operator and version

Usage Examples

#include "onnx/defs/doc_strings.h"
#include "onnx/defs/schema.h"

using namespace ONNX_NAMESPACE;

// Used in operator schema registration (e.g., in defs/math/defs.cc)
ONNX_OPERATOR_SET_SCHEMA(
    Relu, 6,
    OpSchema()
        .SetDoc(kDoc_Relu_ver6)
        .Input(0, "X", "Input tensor", "T", OpSchema::Single)
        .Output(0, "Y", "Output tensor", "T", OpSchema::Single)
        .TypeConstraint("T", {"tensor(float)", "tensor(double)", ...}, "...")
);

// Accessing documentation through the schema API
const OpSchema* schema = OpSchemaRegistry::Schema("Relu");
if (schema) {
    std::cout << schema->doc() << std::endl;
    // Prints the kDoc_Relu_ver6 content
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment