quark-onnx-shapeshifter-run
SkillAI & modelsLets your agent clean up and optimize an ONNX model by applying ready-made graph transforms like folding BatchNorm.
Available today. Use it from your connected AI after setup.
No other account needed.
Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.
Then ask your AI: use the quark-onnx-shapeshifter-run skill
About this skill
Apply existing ShapeShifter graph passes to an .onnx model via the quark-cli shapeshifter CLI or a ShapeShifter YAML. Trigger for "run ShapeShifter on my .onnx", "apply an onnx_ pass", "fold batch norm / simplify / convert opset / fuse LayerNorm on my ONNX model", "preprocess my .onnx before quantiz
What this skill tells your AI
The instructions your AI receives, as published by amd/quark in skills/quark-onnx-shapeshifter-run/SKILL.md and read by ahel’s review.
Purpose
Apply one or more existing ShapeShifter ONNX passes to an .onnx model by authoring a
ShapeShifter YAML config and running the quark-cli shapeshifter CLI. ShapeShifter is Quark's
pass-based graph-transformation framework; this skill covers invoking its built-in onnx_*
passes (fold BatchNorm, simplify, convert opset, fuse LayerNorm/GELU, align scales, XINT8/NPU
adaptation, etc.) as a standalone file→file transform — separate from authoring a new pass
(quark-create-shapeshifter-pass) and from a full quantization run (quark-onnx-ptq). It exists so
graph preprocessing/postprocessing can be run and inspected on its own, and so the driving YAML is
a reusable, reviewable artifact.
Inputs
- Required: path to an
.onnxmodel (optionally with an adjacent.onnx_dataexternal-weights file). - Required: the pass(es) to apply and their config keys. If the user names an effect ("fold
batch norm") rather than a pass name, map it to the pass via the catalog in
docs/source/quark_shapeshifter_onnx_passes.rst. - Required: an output
.onnxpath. - Optional: whether these are preprocessing (float model) or postprocessing (quantized Q/DQ model) passes — affects which passes are valid and the recommended order.
Outputs: shapeshifter_config.yaml
The primary artifact is the ShapeShifter YAML config that drives the run — reusable and reviewable.
Side effect: the transformed model written to the user's output .onnx path.
input_model_path: /path/to/model.onnx
passes:
onnx_convert_opset_version:
target_opset_version: 21
onnx_simplify:
simplify: true
onnx_fold_batch_norm:
fold_batch_norm: true
output_model_path: /path/to/model_out.onnx
No JSON schema — this is a ShapeShifter CLI config (see quark/shapeshifter/utils.py), not a
cross-skill contract artifact.
Interaction Flow
- Intake — confirm the input
.onnxpath exists, capture the requested transformation(s) and the output path. Map effect words to concrete pass names. - Route — verify every requested pass is an ONNX pass (
onnx_*) and exists inquark/shapeshifter/passes/. If the user asked to create a pass, hand off toquark-create-shapeshifter-pass; if they asked to quantize, hand off toquark-onnx-ptq. - Plan — present the YAML config (pass order + config keys) before writing. Confirm the config key for each pass (many passes are a silent no-op without their enable flag — see Recovery).
- Confirm — get approval before running the CLI (it writes the output file).
- Execute or Summarize — write
shapeshifter_config.yaml, run the CLI, then verify the output model loads and the transformation took effect. Summarize what changed.
Invoking the CLI
Write the YAML (see Outputs), then:
quark-cli shapeshifter shapeshifter_config.yaml
The CLI loads the model, runs each pass in the order listed (each on the previous pass's
output), and writes output_model_path. JSON configs also work. An explicit model config is
equivalent to the flat form and clearer when in doubt:
input_model_config:
model_type: onnx # discriminator
input_model_path: /path/to/model.onnx
passes: { ... }
output_model_path: /path/to/model_out.onnx
Pass Selection
Full catalog + config keys: docs/source/quark_shapeshifter_onnx_passes.rst. Common choices:
| Intent | Pass | Config key |
|---|---|---|
| Constant-fold / clean graph | onnx_simplify | simplify: true |
| Upgrade opset | onnx_convert_opset_version | target_opset_version: 21 |
| Fold BatchNorm into Conv/Gemm | onnx_fold_batch_norm | fold_batch_norm: true |
| Fuse LayerNorm / GELU | onnx_fuse_layer_norm / onnx_fuse_gelu | fuse_layer_norm: true / fuse_gelu: true |
| Layout NCHW→NHWC | onnx_convert_nchw_to_nhwc | convert_nchw_to_nhwc: true |
| Cross-layer equalization | onnx_cross_layer_equalization | cross_layer_equalization: true |
| Align Q/DQ scales (quantized) | onnx_align_scale | align_scale: [Concat, MaxPool] |
| XINT8/NPU adapt (quantized) | onnx_xint8_adjust / onnx_xint8_simulate | xint8_adjust: true / xint8_simulate: true |
Preprocessing passes run on the float model (before quantization); postprocessing
passes (onnx_align_scale, onnx_adjust_bias_scale, onnx_xint8_*, bfloat16 passes) expect a
quantized Q/DQ model. Do not run postprocessing passes on a float model.
Ordering tip: put opset conversion and onnx_simplify first (some fusions require a newer
opset and a cleaner graph), then folding/fusion, then per-node initializer passes.
Relationship to quantization
If the goal is to run these passes as part of quantization rather than standalone, they can be
driven from the quantizer instead via extra_options={"ShapeShifterYaml": "config.yaml"} with
preprocess_passes: / postprocess_passes: groups — that path belongs to quark-onnx-ptq. Use
this skill only for the standalone file→file transform.
Recovery
- Pass ran but nothing changed (silent no-op) — most passes require their enable flag; e.g.
onnx_convert_clip_to_reluneedsconvert_clip_to_relu: true. A missing/falseflag logs a warning and returns the model unchanged. Re-check the config key against the docs. Pass '<name>' is not registered— misspelled pass name or apytorch_*name. List valid names withls quark/shapeshifter/passes/; this skill is ONNX-only.ValueError: ... is not an ONNX pass— apytorch_*pass slipped into the config. All passes in one run must be ONNX.- Postprocessing pass errors on a float model —
onnx_align_scale/onnx_xint8_*need a quantized Q/DQ model. Quantize first (quark-onnx-ptq), then apply. - CLI errors / onnxruntime traceback — hand off to
quark-onnx-debugwith the exact message. - Output opset too low for a fusion —
onnx_fuse_gelu(opset ≥ 20) andonnx_fuse_layer_norm(opset ≥ 17) auto-skip on lower opsets; addonnx_convert_opset_versionearlier in the list.
Notes
- CLI wrapper:
quark/experimental/cli/shapeshifter.py(the deprecatedonnx-adapteralias still works). Config loader:quark/shapeshifter/utils.py(LoadConfigFromFileOrDict— accepts a dict, JSON string, or YAML/JSON file path). Execution loop + model-type detection:quark/shapeshifter/engine.py. - Passes run sequentially in listed order; there is no parallelism (deterministic by design).
- For an in-memory (no-disk) transform in Python, the
shapeshifter()API takes amodel=arg and returns the transformedModelProto— but this skill is the CLI file→file path. - Do not silently skip output verification; confirm the model loads and the intended nodes changed.
Signals
- GitHub stars
- 174
- Forks
- 35
- Last commit
- Sep 2026
Advanced
- Item type
- skill
- Key
quark-onnx-shapeshifter-run- Source
- github.com/amd/quark