Download README.md from tensorviz-org/pytorch-shape-lab: direct link, hf CLI and curl.
- Browser
- Download file 4.08 kB
-
https://huggingface.co/spaces/tensorviz-org/pytorch-shape-lab/resolve/main/README.md
- Command line
-
hf download hf://spaces/tensorviz-org/pytorch-shape-lab/README.md
-
curl -L -o README.md https://huggingface.co/spaces/tensorviz-org/pytorch-shape-lab/resolve/main/README.md
title: PyTorch Shape Lab
emoji: 🧮
colorFrom: green
colorTo: gray
sdk: static
app_file: index.html
pinned: false
license: mit
short_description: Follow a CNN's shapes without losing the batch dimension.
thumbnail: >-
https://raw.githubusercontent.com/tensorviz-org/tensorviz-examples/6e5cdcfc8ec3ab39c0bb1264bf534210ae5c1981/assets/tensorviz-logo-white.png
tags:
- pytorch
- education
- tensor-shapes
PyTorch shape lab
A small interactive lesson by tensorViz. Change the batch and image size,
follow a fixed convolution/pooling stack, and find a mismatch at Linear.
Compare a correctly sized fixed head with an explicit architecture change using
adaptive average pooling. See how reshape(-1, 128) can silently change the
number of samples.
This is shape arithmetic, not model execution. The browser runs no Python, inference, training or tensorViz backend. Compatible shapes do not establish prediction quality or numerical equivalence. The lesson code has no tracking, third-party script, iframe, runtime fetch or account requirement. External resources load only when the reader follows a link. This describes the lesson code, not the hosting platform's ordinary request handling or platform analytics.
The original executable example is available with its checks and explanation. The static arithmetic was independently checked against actual CPU PyTorch operations; see validation.
Run locally
No package installation or build is needed. Serve this folder using an existing Python installation:
python3 -m http.server 4177 --bind 127.0.0.1
Open http://127.0.0.1:4177. ES modules need an HTTP server; opening index.html
as a local file: URL is not the supported preview path.
Lesson boundaries
- The fixed feature stack is
Conv2d(3, 8, kernel_size=3, padding=1),ReLU,MaxPool2d(2), thenFlatten(start_dim=1). - Inputs are NCHW with three channels. This teaching UI accepts batch 1–64 and integer height/width 2–256. These UI bounds are not a general PyTorch limit.
- Pooling uses the default stride of two, padding zero and
ceil_mode=False. Odd spatial dimensions round down. - The original head expects 128 features. A 16 × 16 image yields 512. A fixed 512-feature head fits that example, but not every other input size.
- The optional adaptive pool reduces each of the eight spatial channels to one value and uses an eight-feature head. That changes computation and parameters; it is not an interchangeable pretrained checkpoint repair.
- The unsafe reshape demonstration uses the original feature map before any adaptive pool and the original 128-feature head.
For real model exploration, tensorViz's recorded browser examples are an optional next step. Capturing your own PyTorch model requires the separate tensorViz extension and your model environment. This repository contains only the lesson, not extension implementation.
Validate changes
Use existing Node.js and a Python environment with PyTorch installed. Nothing in the checks downloads dependencies or enables telemetry.
node --test shape-math.test.mjs
python verify_pytorch.py
verify_pytorch.py also invokes Node.js to compare the JavaScript results with
PyTorch. Visual and accessibility acceptance remain separate from these checks.
The intended layout and review cases are in design notes.
License and attribution
Original lesson code and documentation are MIT licensed, including the small test model derived from the public tensorViz example linked above. PyTorch is a separate dependency under its own license. The supplied tensorViz logo identifies the project; this license does not grant trademark rights. The extension and its dependencies retain their own licenses.