A diagnostic triage guide for common mistakes in linear algebra, PyTorch training, tabular pipelines, and cloud runners. For each failure, look up the symptom, run the check, apply the fix, and review the concept.
1. Shapes That Don't Match
Dimension Mismatch
Symptom
RuntimeError: mat1 and mat2 shapes cannot be multiplied (32x10 and 64x10)
# or in NumPy:
ValueError: operands could not be broadcast together with shapes (32, 10) (64, 10)
How to Check
Print the shape of every tensor before the multiplying line. In matrix multiplication $A \times B$, the inner dimensions must match: $(N, K) \times (K, M) \to (N, M)$.
print(f"X: {X.shape}, W: {W.shape}")
# If X is (32, 10) and W is (64, 10), inner dimensions are 10 and 64 — they do not match!
The Fix
Transpose the weight matrix with .T or .t(), or check your nn.Linear(in_features, out_features) definition. In PyTorch, nn.Linear(10, 64) stores weight with shape (64, 10) and performs $x W^T$.
# NumPy fix: transpose W
out = X @ W.T # (32, 10) @ (10, 64) -> (32, 64)
# PyTorch Flatten fix after Conv2d:
x = torch.flatten(x, start_dim=1) # preserve batch dimension (N, -1)
The loss prints nan after a few training steps, or weights turn into nan / inf.
How to Check
Check if raw probabilities hit $0$ or $1$, or if activations produce huge numbers before an exponential.
assert not torch.isnan(loss), "Loss is NaN!"
print("max logit:", logits.max().item(), "min prob:", probs.min().item())
The Fix
Never take the raw torch.log(torch.softmax(logits)) or torch.log(torch.sigmoid(logits)). Use numerically stable fused loss functions that work in logit space: nn.CrossEntropyLoss() or nn.BCEWithLogitsLoss(). In custom code, clamp probabilities with an epsilon $\varepsilon = 10^{-12}$.
# Bad: prone to log(0) -> -inf -> NaN
loss = -torch.log(torch.sigmoid(logits))
# Good: numerically stable log-sum-exp
loss_fn = nn.BCEWithLogitsLoss()
loss = loss_fn(logits, targets)
Validation accuracy is 99.8% or $R^2 = 1.00$ on the very first attempt on dirty tabular data, but drops to chance when evaluated in production.
How to Check
Inspect feature importances or correlations with the target. If one feature has feature importance $> 0.85$ or correlation $> 0.95$, suspect leakage.
# Check feature correlation with target:
corrs = df.corr()['target'].abs().sort_values(ascending=False)
print(corrs.head())
The Fix
Proxy / Consequent variables: Drop columns recorded after the outcome happened (e.g., outage_end_time when predicting outage duration, or resolution_code).
Split before preprocessing: Never fit a StandardScaler, SimpleImputer, or CountVectorizer on the entire dataset. Always use a Pipeline fit strictly on X_train:
from sklearn.pipeline import make_pipeline
pipe = make_pipeline(StandardScaler(), LogisticRegression())
pipe.fit(X_train, y_train) # Scaler never sees X_test!
Time structure: When rows represent time series or events, use TimeSeriesSplit or date cutoffs rather than random train_test_split.
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
# or pip install hangs indefinitely
How to Check
Check the right-hand Settings drawer in your Kaggle Notebook under Notebook options.
The Fix
Verify your Kaggle account is phone-verified (unverified accounts cannot toggle internet).
In the right sidebar, expand Settings → find Internet → toggle it to Internet on. The notebook kernel will restart with external networking enabled.
For competition kernels where Internet must be disabled at submission time, upload your package wheels or pretrained weights as a private Kaggle Dataset, then install locally:
Halve the batch size: If using batch_size=64, reduce it to 32 or 16.
Use gradient accumulation: Simulate larger batch sizes without the VRAM footprint:
accum_steps = 4
for i, (x, y) in enumerate(loader):
loss = loss_fn(model(x), y) / accum_steps
loss.backward()
if (i + 1) % accum_steps == 0:
optimizer.step()
optimizer.zero_grad()
Disable gradients during evaluation: Wrap validation in with torch.no_grad():.
Clicking "Run" on an interactive code box in a lesson keeps spinning, produces no output, or shows an error in the developer console.
How to Check
Open Developer Tools (F12 or Cmd+Option+I) and select the Console tab. Look for failed requests to cdn.jsdelivr.net/pyodide/ or Content Security Policy warnings.
The Fix
Initial download: Pyodide compiles Python to WebAssembly in your browser (~10 MB one-time cache). On slower connections, the first run can take 5–10 seconds to load the runtime.
Supported packages: In-browser code boxes support Python standard library, NumPy, pandas, scikit-learn, and sqlite3. They do not run full PyTorch or CUDA code (PyTorch code runs in Colab or Kaggle).
Content blockers: If an aggressive privacy extension or ad blocker blocks scripts from jsdelivr.net, allow the domain or disable extensions for the page.
State reset: If variable definitions get tangled across cells, refresh the page to restart a clean WebAssembly session.