qualcomm/qai-appbuilder/operator-patching

Claude Code and agent skill by qualcomm/qai-appbuilder

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Install

npx vskill@latest install qualcomm/qai-appbuilder/operator-patching

SKILL.md

The same SKILL.md was published earlier as qualcomm/qai-appbuilder/operator-patching.

Operator Patching (base)

🧭 Diagnosis framework: ${APP_ROOT}/factory/chat_features/model-builder/troubleshooting/_diagnosis-framework.md; this SKILL covers unsupported operator replacement.

Responsibility

Replace unsupported operators (Einsum, GridSample, ScatterND, Mod, Floor, Ceil, Round) with QNN-compatible equivalents from supported base ops (MatMul, Reshape, Transpose, Concat, Div, Mul, Sub, Where, Add), in-memory only. Patch at whichever stage fails.

Trigger signals

  • Converter/context-binary error: operator name + unsupported / not implemented
  • 0xc26 Op validation failed on a specific node
  • --dry_run flags op as unsupported
  • Failed to compile layer 'Einsum_123'

Core knowledge

RULE 1 — check input TYPES first

Same op needs different patch for INT vs FLOAT. Determine types from producer node:

ProducerOutput type
TopK (indices)INT64
Constant data_type=7/=1INT64 / FLOAT32
Conv / MatMul / GemmFLOAT32
Softmax / Sigmoid / ReluFLOAT32
Reshape / Transposeinherits
python
import onnx
m = onnx.load("model.onnx")
for n in m.graph.node:
if n.op_type == "Mod":
print(n.name, list(n.input), list(n.output))
Approach decision tree
Can you modify the PyTorch export code?
├─ YES → Approach 1: Custom Symbolic Handlers (register before torch.onnx.export)
│ Best for torch.mod / torch.einsum / custom aten ops. Highest success (clean graph).
└─ NO → Is the op a known nn.Module?
├─ YES → Approach 2: Module Replacement (patch module.forward in-memory). High success.
└─ NO → Approach 3: ONNX Surgery (direct graph edit). Last resort; topo-sort / drift risk.
Error → Action table (type-aware)
OpTypesAction★
ModINT/INTSub(a, Mul(b, Div(a,b)))5
ModFLOAT/FLOATSub(a, Mul(b, Floor(Div(a,b)))) ⚠️ Floor may fail2
ModFLOAT/CONST(int)Div→Cast(INT)→Cast(FLOAT)→Mul→Sub; Add(0.0) after Cast2
FloorINTRemove (identity)5
FloorFLOATCast(INT32)→Cast(FLOAT) ⚠️ type issues2
CeilFLOATNeg(Floor(Neg(x)))2
RoundFLOATFloor(Add(x,0.5))2
CastOnly numerical type cast supportedWARNING — verify with actual conversion—
CastTensor mismatch 0x32 != 0x216Cast→Add(0.0)→Mul—
EinsumFLOATDecompose to MatMul+Transpose+Reshape4
ScatterNDnon-overlappingGather→Where(mask)→Add(updates)4
ScatterNDoverlappingescalate B71
GridSamplebilinearAffineGrid + Resize(bilinear)2
GridSamplenearest/bicubicconsider arch change1
MaxPooldilations: unsupportedWARNING only — conversion succeeds. Do NOT patch.5
MaxPooldilation>1Slice+Stack+ReduceMax (last resort)3
Unknown op—escalate B7—
MaxPool: PyTorch always adds dilations=[1,1]/ceil_mode=0. Dry-run warns but conversion + HTP succeed.
Einsum — 5 patterns

Einsum = batched MatMul with dim rearrangement (permute+reshape to expose MatMul):

  • A. bmchw,bnmc->bmhwn → [b*m,h*w,c]@[b*m,c,n] → reshape [b,m,h,w,n]
  • B. bchw,bkc->bkhw → [b,h*w,c]@[b,c,k] → permute → [b,k,h,w]
  • C. bij,bjk->bik → torch.matmul(A,B)
  • D. bhij,bhjk->bhik → merge [b*h,i,j]@[b*h,j,k] → reshape
  • General: shared indices=reduced; batch stays; merge batch+reduced → MatMul → reshape back.

Validation Gates (ALL after EACH patch)

GateCheckPass
1 Structuralonnx.checker.check_model()no exception
2 Converterqnn-onnx-converter --dry_runno unsupported errors
3 Numericalorig vs patched (CPUExecutionProvider)cosine ≥ 0.95, no NaN
4 Full (final)python qai_convert_fp.py --onnx ..."Conversion complete!"

Cosine: ≥0.999 correct · 0.99–0.999 OK · 0.95–0.99 investigate · <0.95 wrong pattern. On failure: Gate1→topo/names. Gate2→more patching. Gate3→wrong pattern, next row. Gate4→Add(0.0) after Cast.

⚠️ Einsum patches can silently change numerics — validate all output channels.

Discipline

❌ Forbidden✅ Required
CPU fallback / QnnCpu.dll as solutionPatch for HTP/DSP compatibility
Skip patching, CPU onlyModel MUST run on HTP

Can't patch → escalate B7. Patch in-memory only; validate each patch; stop if dry-run passes (don't over-patch).

Escalation

ConditionCodeEvidence
No pattern existsB7op name, types, search
Patch changes semanticsB4describe change, impact
7+ iterations, no progressB3patches, logs, ONNX

Iteration 5+: resolving faster than discovering → continue; new ops faster → escalate.

Full patterns + code → references/operator_patching.md.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/qualcomm/qai-appbuilder/operator-patching/badge)](https://verified-skill.com/skills/qualcomm/qai-appbuilder/operator-patching)

Something wrong with this skill or its page? Tell us.