Agent skill

Add Shape Inference

by onnx in onnx/onnx

Add or update type and shape inference for an ONNX operator.

Apache-2.0Auto-check passedAI & LLM Engineering

Install Add Shape Inference

skills CLI
$ npx skills add onnx/onnx --skill add-shape-inference -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install onnx/onnx add-shape-inference --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/onnx/onnx.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/add-shape-inference .claude/skills/add-shape-inference && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
add-shape-inference
GitHub stars
22k
Token cost
~1.3k tokens
SKILL.md length
354 words
Files
1
Skills in repo
4
Repo updated
First seen
Licence
Apache-2.0

At a glance

Add or update type and shape inference for an ONNX operator.

  • Works in 5 steps: Always check hasNInputShapes(ctx, n)… → Always check has_dim_value() before… → Handle unknown dimensions gracefully —… → …
  • Asked to implement TypeAndShapeInferenceFunction
  • SKILL.md covers File Locations, Type Inference vs. Shape…, Common Patterns and Key Utility Functions, plus 5 more sections
  • Calls pytest and python

What it does

Add Shape Inference is an agent skill from onnx/onnx. Add or update type and shape inference for an ONNX operator. Use when asked to implement TypeAndShapeInferenceFunction, propagate shapes, add shape inference tests, fix shape inference bugs, or handle broadcasting logic.

Its SKILL.md is about 1.3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in AI & LLM Engineering, covering Deep learning. It works with ONNX. The repository describes itself as: Open standard for machine learning interoperability. The licence is Apache-2.0.

When your agent uses it

  • Asked to implement TypeAndShapeInferenceFunction
  • Propagate shapes
  • Add shape inference tests
  • Fix shape inference bugs

Example prompts

  • “/add-shape-inference”

Requirements

  • Python 3

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Always check hasNInputShapes(ctx, n) before accessing shapes
  2. Always check has_dim_value() before using dim_value()
  3. Handle unknown dimensions gracefully — leave unset, don't fail
  4. At minimum provide rank inference (correct number of output dims)
  5. Propagate symbolic dimensions (dim_param) when possible

What it can do on your machine

Read from SKILL.md and the folder at commit ab429ea. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • pytest
    • python

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Add Shape Inference loads about 1.3k tokens when it runs. Until then it costs about 60 tokens; SKILL.md has 354 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~60
When it runs · the whole SKILL.md, loaded when a task matches
~1.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from onnx/onnx at commit ab429ea, republished under its Apache-2.0 licence (© onnx). 354 words, ~1,336 tokens.

Download SKILL.mdSave it as .claude/skills/add-shape-inference/SKILL.md (or your agent's skills folder).
name
add-shape-inference
description
Add or update type and shape inference for an ONNX operator. Use when asked to implement TypeAndShapeInferenceFunction, propagate shapes, add shape inference tests, fix shape inference bugs, or handle broadcasting logic.

See also: docs/ShapeInference.md

File Locations

ComponentFile
Inference functiononnx/defs/<domain>/defs.cc (inline with schema)
Utility functionsonnx/defs/shape_inference.h
Teststests/python/shape_inference_test.py

Type Inference vs. Shape Inference

Type inference (element type) is often handled automatically by type constraints. When "T" is shared between input and output, the framework infers output type automatically.

However, many existing ops still explicitly call propagateElemTypeFromInputToOutput as a best practice for robustness.

Explicit type inference logic is only needed when:

  • Output type is determined by an attribute (e.g., Cast)
  • Output type differs from all inputs in a way not expressible via type constraints
  • The operator uses heterogeneous variadic inputs/outputs
Homogeneous vs. Heterogeneous

Applies only to variadic (repeated) inputs/outputs:

  • Homogeneous (default): All repeated arguments share the same type. Framework propagates automatically.
  • Heterogeneous: Each argument can differ. Used by Loop/Scan. The inference method must explicitly propagate types for each argument.

Common Patterns

Unary Element-wise
cpp
.TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)
Binary with Broadcasting
cpp
static void InferShapeForBinaryOp(InferenceContext& ctx) {
    propagateElemTypeFromInputToOutput(ctx, 0, 0);
    if (hasNInputShapes(ctx, 2))
        bidirectionalBroadcastShapeInference(
            ctx.getInputType(0)->tensor_type().shape(),
            ctx.getInputType(1)->tensor_type().shape(),
            *ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape());
}
Shape-Changing Op
cpp
static void InferShapeForTranspose(InferenceContext& ctx) {
    propagateElemTypeFromInputToOutput(ctx, 0, 0);
    if (!hasNInputShapes(ctx, 1)) return;

    auto input_shape = ctx.getInputType(0)->tensor_type().shape();
    int rank = input_shape.dim_size();
    std::vector<int64_t> perm;
    getRepeatedAttribute(ctx, "perm", perm);

    auto* output_shape = getOutputShape(ctx, 0);
    for (int i = 0; i < rank; ++i) {
        *output_shape->add_dim() = input_shape.dim(perm[i]);
    }
}

Key Utility Functions

FunctionPurpose
propagateElemTypeFromInputToOutput(ctx, in, out)Copy element type
propagateShapeFromInputToOutput(ctx, in, out)Copy entire shape
propagateShapeAndTypeFromFirstInput(ctx)Both type and shape from input 0
hasNInputShapes(ctx, n)Check first n inputs have shapes
getOutputShape(ctx, out)Get mutable output shape
bidirectionalBroadcastShapeInference(L, R, out)Numpy broadcasting
getRepeatedAttribute(ctx, "name", vec)Get repeated attr values
getAttribute(ctx, "name", default)Get single attr value
mergeInDimensionInfo(src, dst, dim_idx)Merge dimension info
fail_shape_inference("msg")Throw inference error
Show full SKILL.md (139 more words)Show less

Dimension Arithmetic

cpp
Dim operator*(const Dim& a, const Dim& b);
Dim operator*(const Dim& a, int64_t val);
Dim operator/(const Dim& a, int64_t divisor);
Dim multiplyDims(const TensorShapeProto& shape, int from, int upto);

Writing Tests

The _make_graph / _assert_inferred helpers are right for parameterized op-version sweeps:

python
@pytest.mark.parametrize("version", all_versions_for("OpName"))
def test_opname(self, version) -> None:
    graph = self._make_graph(
        [("X", TensorProto.FLOAT, (2, 3, 4))],
        [make_node("OpName", ["X"], ["Y"], attr_name=attr_value)],
        [],
    )
    self._assert_inferred(
        graph,
        [make_tensor_value_info("Y", TensorProto.FLOAT, expected_shape)],
        opset_imports=[helper.make_opsetid(ONNX_DOMAIN, version)],
    )

For one-off fixtures — anything with attributes, body subgraphs, or non-trivial type info — prefer the onnxtxt skill's parser-based fixtures (it also covers the C++ unk__* materialization gotcha for free dims).

Cover: known shapes, partial shapes (None), rank inference, error cases, broadcasting, attribute-dependent shapes.

Code Style: Prefer Named Functions

Define inference functions as separate named functions rather than inline lambdas. The macro expansion makes breakpoints on inline lambdas unreliable.

Short one-liners (e.g., propagateShapeAndTypeFromFirstInput) are fine as direct references.

Rules for Robust Inference

  1. Always check hasNInputShapes(ctx, n) before accessing shapes
  2. Always check has_dim_value() before using dim_value()
  3. Handle unknown dimensions gracefully — leave unset, don't fail
  4. At minimum provide rank inference (correct number of output dims)
  5. Propagate symbolic dimensions (dim_param) when possible

After Making Changes

bash
pytest tests/python/shape_inference_test.py -k "test_opname" -x
python onnx/defs/gen_doc.py
lintrunner -a --output oneline

© onnx, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/add-shape-inference of onnx/onnx.

Open the folder on GitHubat commit ab429ea

Compare with similar skills

Add Shape Inference next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Add Shape Inference compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Add Shape Inference this skillonnx/onnx22k—~1.3kAutomated safety check: PassApache-2.0
Segment Anything Model GuideOrchestra-Research/AI-Research-SKILLs13k9 repos~3.3kAutomated safety check: PassMIT
Technology Selectiondotnet/skills5.6k2 repos~2.1kAutomated safety check: PassMIT
Quark Torch Quant Perfamd/Quark181—~3kAutomated safety check: PassMIT
Domain MLmajiayu000/claude-skill-registry6661 repos~1.2kAutomated safety check: PassMIT
Embedded AI Deploymentmatlab/agent-skills-playground1811 repos~3.4kAutomated safety check: PassCustom licence

Similar skills

  • Segment Anything Model Guide

    Orchestra-Research/AI-Research-SKILLs

    Guide to using Meta's Segment Anything Model for zero-shot image segmentation with point, box or mask prompts, or automatic mask generation.

    13k GitHub starsUsed in 9 repos~3.3k tokens
    AI & LLM EngineeringAuto-check passed
  • Official

    Guides technology selection and implementation of AI and ML features in .NET 8+ applications using ML.NET, Microsoft.Extensions.AI (MEAI), Microsoft Agent Framework (MAF), GitHub Copilot SDK, ONNX…

    5.6k GitHub starsUsed in 2 repos~2.1k tokens
    AI & LLM EngineeringAuto-check passed
  • Run, resume, monitor, diagnose, and report Quark Quant-Perf workflows for PyTorch and HuggingFace transformers models.

    181 GitHub stars~3k tokensUpdated 10 days ago
    AI & LLM EngineeringAuto-check passed
  • Domain ML

    majiayu000/claude-skill-registry

    A skill your agent uses when building ML/AI apps in Rust. An agent skill from majiayu000/claude-skill-registry.

    666 GitHub starsUsed in 1 repo~1.2k tokens
    Data & AnalyticsAuto-check passed
  • Embedded AI Deployment

    matlab/agent-skills-playground

    Deploy AI models to embedded hardware using MathWorks tools (MATLAB, Simulink, Embedded Coder).

    181 GitHub starsUsed in 1 repo~3.4k tokens
    AI & LLM EngineeringAuto-check passed
  • Model Builder

    qualcomm/qai-appbuilder

    QAI ModelBuilder. An agent skill from qualcomm/qai-appbuilder.

    246 GitHub stars~4.1k tokensUpdated today
    AI & LLM EngineeringAuto-check passed

More from onnx/onnx

  • Add Op

    onnx/onnx

    Add a new ONNX operator or update an existing operator to a new opset version.

    22k GitHub stars~1.2k tokensUpdated yesterday
    Auto-check passed
  • Add a function body definition to an ONNX operator, defining how it decomposes into simpler ops.

    22k GitHub stars~1.1k tokensUpdated yesterday
    Auto-check passed
  • Onnxtxt

    onnx/onnx

    Read or write ONNX text format ("onnxtxt"). An agent skill from onnx/onnx.

    22k GitHub stars~1.3k tokensUpdated yesterday
    Auto-check passed

Works with

Questions about Add Shape Inference

What does Add Shape Inference do?

Add or update type and shape inference for an ONNX operator. Add Shape Inference is an agent skill from onnx/onnx. Add or update type and shape inference for an ONNX operator.

When should I use Add Shape Inference?

Add Shape Inference fits situations like: asked to implement TypeAndShapeInferenceFunction; propagate shapes; add shape inference tests; fix shape inference bugs.

How do I install Add Shape Inference in Claude Code?

Run `npx skills add onnx/onnx --skill add-shape-inference -a claude-code`. Or copy the skill folder (.agents/skills/add-shape-inference in onnx/onnx) into .claude/skills/add-shape-inference in your project. Claude Code loads it when a task matches its description.

How do I install Add Shape Inference in Codex?

Run `npx skills add onnx/onnx --skill add-shape-inference -a codex`. Or copy the skill folder (.agents/skills/add-shape-inference in onnx/onnx) into .agents/skills/add-shape-inference in your project. Codex loads it when a task matches its description.

Can I use Add Shape Inference in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add onnx/onnx --skill add-shape-inference -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/add-shape-inference, .gemini/skills/add-shape-inference, .github/skills/add-shape-inference and .opencode/skills/add-shape-inference in your project.

What does Add Shape Inference need to run?

Going by SKILL.md and its folder, Add Shape Inference needs the command-line tools its instructions call (pytest and python). Our summary lists: Python 3.

Does Add Shape Inference access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Add Shape Inference safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Add Shape Inference use?

Add Shape Inference is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Add Shape Inference use?

About 1.3k tokens (SKILL.md is roughly 5.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Add Shape Inference?

Skills that share tags, products or a category with Add Shape Inference: Segment Anything Model Guide (Orchestra-Research/AI-Research-SKILLs, 13k stars), Technology Selection (dotnet/skills, 5.6k stars), Quark Torch Quant Perf (amd/Quark, 181 stars) and Domain ML (majiayu000/claude-skill-registry, 666 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Add Shape Inference?

onnx (a GitHub organization) maintains it in onnx/onnx, which has 21,564 GitHub stars. The repository holds 4 skills in this directory. The repository was last updated on October 7, 2026.

Source: onnx/onnx on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.