pytorch-shape-lab / VALIDATION.md
nityanandmathur's picture
Add a tested PyTorch shape lesson
853be10 verified
|
Raw History Blame
3.63 kB

Validation

This page models a fixed CPU-compatible PyTorch example. It does not execute Python in the browser or provide a general-purpose shape inference engine.

The JavaScript tests cover the canonical mismatch, batch-preserving fixed head, non-square inputs, floor pooling for odd dimensions, adaptive-pooling dimensions, unsafe reshape, and invalid input rejection. The separate Python check invokes actual PyTorch Conv2d, ReLU, MaxPool2d, Flatten, Linear and AdaptiveAvgPool2d, then compares their shapes and errors with the JavaScript calculator for 21 cases. For successful paths it also compares full-batch and per-image outputs.

Executed checks — October 11, 2026

Environment: Node.js 26.5.0, Python 3.12.14, PyTorch 2.7.1, CPU. No dependencies were downloaded or installed for this check.

  • 5 JavaScript tests passed, zero failures and zero skips.
  • 21 actual PyTorch comparisons passed: all three heads for batch/image combinations (1,16,16), (2,16,16), (5,16,16), (2,16,20), (3,17,19), (2,8,8) and (1,3,3).
  • Successful paths preserved the number of samples, and full-batch outputs matched concatenated per-image outputs (atol=1e-6, rtol=1e-5).
  • JavaScript syntax checks passed for both application modules.

Representative observations:

Input NCHW Flatten before optional adaptive pool Original 128 head Fixed 512 head Adaptive pool + 8 head
[2,3,16,16] [2,512] Exact error (2x512 and 128x5) [2,5] [2,5]
[2,3,16,20] [2,640] Mismatch Exact error (2x640 and 512x5) [2,5]
[3,3,17,19] [3,576] Mismatch Mismatch [3,5]
[2,3,8,8] [2,128] [2,5] Mismatch [2,5]
[1,3,3,3] [1,8] Mismatch Mismatch [1,5]

For the default input, reshape(-1,128) changes [2,512] to [8,128] and produces [8,5] through the original head. The operation runs but does not preserve one output row per image. Odd-sized pooling and impossible/redundant reshape cases were also checked against PyTorch.

Browser rendering and interaction acceptance are not established by these tests. No model accuracy, checkpoint compatibility or extension capture result is claimed by this standalone lesson.

Browser QA — October 11, 2026

A separate in-app browser pass checked the locally served lesson at 1280 × 720 and 390 × 844. It verified these interactions:

  • The default input displays 512 ≠ 128 at the original classifier.
  • Choosing the 512-feature head produces the calculated output [2,5].
  • Changing the image to 16 × 20 produces 640 ≠ 512 with that fixed head.
  • Adding adaptive pooling produces [2,5] and shows the explicit warning that the architecture and computation change.
  • A 17 × 19 image pools to spatial size 8 × 9.
  • Batch zero shows the validation message; Reset restores the starting lesson.

The 390-pixel-wide page had readable text and no horizontal overflow. A full-page mobile screenshot was saved as tensorviz-shape-lab-mobile-2026-10-11.png. No lesson-origin console errors were observed. These results cover the two listed viewports; 320-pixel rendering and hosted Hugging Face behavior were not established by this local pass.

A source review also confirmed the visible arithmetic-only notice, batch-preserving flatten, explicit adaptive-pooling semantics, unsafe-reshape sample-count warning, and distinction between this lesson and actual tensorViz model capture. The code adds no runtime fetch or tracking, and the footer limits its claim to calculations staying in the reader's browser.