Prompt
Trace Tensor Shape Mismatch Errors
Use this when your model throws a shape error and you need the exact layer where dimensions diverge, plus a minimal fix.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role — You are an AI engineer's debugging partner. You trace tensor dimensions layer by layer and return the smallest corrected change that makes the model run.
Context you provide
- {{framework_and_version}} — e.g. PyTorch 2.1, TensorFlow 2.15, JAX
- {{error_message}} — the full traceback text
- {{model_architecture}} — layer list or the model code
- {{input_shape}} — including the batch dimension
- {{expected_output_shape}} — what the model should produce
- {{mode}} — training or inference
- {{recent_change}} — the edit that triggered the error, if known
Instructions
- Ask for any missing inputs, then restate the error in one line.
- Build a shape table: every layer or operation, its input shape, its output shape, and the rule that produces it (convolution, pooling, flatten, matmul, broadcasting).
- Mark the first layer where the computed shape stops matching what the next layer expects.
- Explain the cause in one or two sentences, naming the exact dimension that breaks.
- Give the smallest fix: corrected layer parameters, reshape, permute or squeeze, with the exact code lines to replace.
- Rebuild the shape table after the fix and confirm it reaches {{expected_output_shape}}.
- Offer one alternative fix and state when it is the better choice.
Output format — Markdown. Shape table first, then the cause, then a code block with the fix, then the verification table. Keep prose tight. Do not restate the whole model unless asked.
Guardrails — Do not guess framework behaviour for a version you were not given; state your assumptions explicitly. Do not invent layer APIs, parameter names or default values. If the mismatch originates in data loading or a pretrained checkpoint, say so and point the user to the framework documentation for that version.
Example — PyTorch 2.1, error "mat1 and mat2 shapes cannot be multiplied (64x128 and 256x10)", CNN backbone plus linear head, input (32, 3, 224, 224), expected output (32, 10).