Add marimo MNIST + W&B Registry example#621
Conversation
Introduces the first marimo notebook in this repo. Trains a small PyTorch CNN on MNIST, logs the run with wandb, saves the trained model as an Artifact, and links it to a W&B Registry collection via the cross-org link_artifact API. The notebook is interactive: hyperparameters live in a marimo form and training is gated by an explicit Train button so slider tweaks do not trigger runs. PEP 723 inline script metadata makes it self-installing under `uvx marimo edit --sandbox`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Active voice, present tense, plain English, and consistent brand capitalization across the README and the notebook's prose cells. Code identifiers wrapped in backticks where missing; a sentence fragment in the verify step rewritten as a complete clause. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
Mirrors the existing "Get Colabs" PR-comment flow (which serves .ipynb files via nb_helpers) for marimo .py notebooks, which nb_helpers does not handle. On each PR that touches a .py file, the job detects marimo notebooks by their `marimo.App(` marker and upserts a single comment linking each to molab — marimo's hosted runtime that loads any public notebook on GitHub. Uses pull_request_target with pull-requests:write so the comment also lands on fork PRs, and never checks out or runs PR code (reads file content as text only). Links pin to the head commit SHA because branch names with slashes make the molab blob/<ref>/<path> split ambiguous. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
| Notebook | molab |
|---|---|
examples/marimo/mnist-registry/mnist_registry.py |
Links track the head of jmulhausen/marimo-mnist-registry-example.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a masked mo.ui.text(kind="password") field so users can authenticate by pasting a key instead of running `wandb login` in a shell. The resolved value is kept out of the run config (never logged) and feeds wandb.login(key=...) in the gated training cell; blank falls back to ambient auth (shell login, WANDB_API_KEY, or netrc). Downstream cells read the key via the returned wandb_api_key. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Triage: Socket license alerts on
|
The link step's "common causes" did not name the most common real failure: a view-only org seat (`view-only member cannot write to project`), where the run and artifact succeed but linking is blocked. Lead the remediation with that case and how to resolve it, and note the write-access requirement up front in the prerequisites. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
GitHub resolves multi-segment (slashed) branch names in blob/<ref>/<path> and molab fetches from GitHub, so a branch-based link points at the latest revision and needs no per-commit comment maintenance. Content detection still pins to the head SHA. Skip the comment write when the body is unchanged so no-op pushes don't churn it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The view-only link failure now names the required role (Member) and the
three ways an admin can grant it: the Registry Members UI, the Python SDK
(wandb.Api().registry(...) then add_member()/update_member()), and SCIM
(PATCH /scim/Users/{id} with registryRoles), with a link to the configure
registry access docs. README prerequisite updated to match.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The bare molab GitHub URL renders a static preview. Appending /server opens the notebook in a hosted runtime so reviewers can actually run it — needed here since the notebook depends on torch, which the in-browser /wasm mode cannot run. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a push-triggered workflow that runs `marimo export md` on each notebook under examples/marimo/, writing a peer <notebook>.md, and commits the result back to the branch so the rendered Markdown always tracks the notebook. marimo is pinned for byte-deterministic output (no version-only churn), and three guards prevent commit loops (GITHUB_TOKEN pushes don't re-trigger, *.py-only trigger vs *.md-only commits, and [skip ci]). Includes the initial export of mnist_registry.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collapses 19 cells into 5, breaking only where marimo requires it or where the user actually provides input: - intro (markdown) - setup + form: imports, device detection, and all input widgets in one cell - train button: its own cell (a widget must be defined separately from the cell that reads its value) - run training: one gated cell that configs, authenticates, inits, builds and trains the model, logs, saves, and links the artifact — streaming each milestone with mo.output.append so it isn't a black box - verify + next steps (markdown), rendered once a run exists run_button.value resets to False after its cascade, so editing the form after a run re-runs the training cell but mo.stop halts it immediately — no silent retrain. Regenerates the Markdown peer. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Socket re-scan
|
There was a problem hiding this comment.
Pull request overview
Adds a new examples/marimo/ MNIST notebook demonstrating training a small PyTorch CNN, logging to W&B, and linking a logged model artifact into a W&B Registry collection, plus GitHub Actions automation for exporting marimo notebooks to Markdown and for posting molab “run this notebook” PR links.
Changes:
- Add a self-contained marimo MNIST → W&B Artifact → W&B Registry notebook (+ exported Markdown peer) under
examples/marimo/mnist-registry/. - Add docs and a
requirements.txtmirror for the notebook’s PEP 723 dependency block. - Add GitHub Actions workflows to (a) auto-export marimo notebooks to Markdown on push and (b) comment molab links on PRs.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
examples/marimo/mnist-registry/mnist_registry.py |
New marimo notebook implementing training, W&B logging, artifact creation, and registry linking. |
examples/marimo/mnist-registry/mnist_registry.md |
Exported Markdown version of the notebook for static rendering. |
examples/marimo/mnist-registry/README.md |
Run instructions, prerequisites, and design notes for the example. |
examples/marimo/mnist-registry/requirements.txt |
Pip requirements mirroring the PEP 723 dependency block. |
.github/workflows/marimo_export_md.yml |
Workflow to export examples/marimo/**/*.py notebooks to peer .md files and commit updates. |
.github/workflows/marimo_molab.yml |
Workflow to post/update PR comments with molab links for modified marimo notebooks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove the unused `import os` and drop `os` from the setup cell's returns. - Compute final_acc from the full-precision last-epoch test_acc instead of the display-rounded history entry, so artifact `test_accuracy` keeps full precision. - marimo_molab.yml: use `**/*.py` (canonical glob) instead of `**.py` so the path filter reliably matches notebooks in subdirectories. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reorders the notebook to: intro -> setup+form -> training pipeline -> Train button -> verify. The button still gates the pipeline (so it doesn't run on open), but now reads as the explicit "run the code above" trigger. The training cell's pre-run message explains what it does and points to the button below. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The entity form field read just "W&B entity", which reads as jargon. Label it "username or team" to match the prerequisites wording. Also tighten the registry-link remediation: an entity is a team or username (not an org), so it now reads "set W&B entity to a team in an org where you have Registry write access." Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Personal-username entities were removed for W&B accounts created after 2024-05-21, so a run's entity must be a team. Relabel the entity field accordingly, fix the prerequisite, and wrap wandb.init so an "entity ... not found" failure renders actionable guidance (set the entity to a team) instead of a raw CommError traceback. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pulls the CNN definition into its own cell so it can be shared, then adds a cell that downloads the model from W&B (preferring the registered version, falling back to the run's artifact so it works even when the registry link is blocked), loads the weights into a fresh network, and classifies 10 held-out MNIST test digits — rendering each as an image with predicted vs. true label and an N/10 correct tally. No new dependency (numpy ships with torch; mo.image renders the arrays). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The consume cell reused `correct` and `pred`, which the training cell already defines — marimo forbids defining a name in more than one cell, so the cell refused to run. Rename them to `n_correct` / `prediction` (both cell-local to the consume step). marimo export does not enforce the single-definition rule, only the kernel does, so this slipped through earlier validation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Adds the first marimo notebook to this repo at
examples/marimo/mnist-registry/. The notebook trains a small PyTorch CNN on MNIST, logs the run to W&B, saves the trained weights as a model Artifact, and links the Artifact to a W&B Registry collection through the current cross-orgrun.link_artifact(target_path="wandb-registry-model/<collection>")API.PEP 723 inline script metadata makes the notebook self-installing under
uvx marimo edit mnist_registry.py --sandbox. No new top-level deps for the repo.What the notebook demonstrates
mo.uiwidgets bind to a config dict that feedswandb.config.mo.ui.run_buttonplusmo.stopkeeps slider tweaks from kicking off runs. After a run completes, clicking again starts a new run using the current form values; the previous run finishes cleanly first.wandb.finish()runs at the top of the training cell and at the end of the notebook so re-clicking Train in the same marimo kernel never nests runs.run.link_artifact(artifact=logged, target_path=f"wandb-registry-{registry}/{collection}")with a try/except that surfaces inline remediation guidance when the Registry is not provisioned, rather than crashing.logged.wait()before linking prevents a race wherelink_artifactresolves an uncommitted version.wandb.define_metricusesepochas the x-axis fortrain/*andtest/*series in the W&B UI.Architecture and training loop mirror
examples/pytorch/pytorch-cnn-mnist/main.py. Registry linking mirrorscolabs/wandb_registry/zoo_wandb.ipynb.Files
examples/marimo/mnist-registry/mnist_registry.py— the notebook (~640 lines)examples/marimo/mnist-registry/README.md— prereqs, how to run, design notesexamples/marimo/mnist-registry/requirements.txt— pip mirror of the PEP 723 blockCommits
add marimo MNIST + W&B Registry example— initial draftapply Google Developer Style Guide pass to marimo MNIST example— style cleanup (active voice, present tense, plain English, brand capitalization, code identifiers in backticks)Test plan
python3 -c "import ast; ast.parse(open('examples/marimo/mnist-registry/mnist_registry.py').read())"succeeds (verified locally).uvx marimo edit examples/marimo/mnist-registry/mnist_registry.py --sandboxopens the notebook with all cells rendering and no errors.mnist-cnn-<run-id>appears under the run's Artifacts tab with metadata for test accuracy, parameter count, and hyperparameters.wandb-registry-model/MNIST Classifiers; the version appears in the Model registry UI.wandb.initwarnings about a pre-existing run).mo.calloutwith remediation guidance and does not crash the notebook.🤖 Generated with Claude Code