6.5.11 · D3Research Frontiers & Practice

Worked examples — Contributing to open-source ML

3,783 words17 min readBack to topic

Before any symbol or term appears, we build it from zero. If you have never opened a terminal, you can still follow from line one. Any name in double brackets like Testing ML Systems is a link to another note in this vault — you can safely read this page without clicking any of them; they are there for later.


The scenario matrix

Every open-source contribution you will ever make falls into one of a small number of cells. A cell here just means "a category of situation" — the way a chessboard has squares. If you can handle every cell, nothing can ambush you.

Let me define the two axes of the table before drawing it.

The figure below places every worked example of this page onto that grid, so you can see at a glance which corner each one lives in. Read it like a map: horizontal = how deep into the code you must go (Trivial → Local → Structural, left to right), vertical = what became of your work (Merged bottom, Revised middle, Rejected top). Each pastel tile carries an example label; the top-left tile reads "(empty)" because a trivial change almost never gets outright rejected, which is exactly why doc fixes (Ex 1, bottom-left) are the safest first contribution. The two arrows on the left and bottom edges show the direction each axis increases. In words: doc fixes sit lower-left (easy, welcomed), feature work sits right (structural), and the only rejection tile (Ex 6, the plugin) sits upper-middle.

Figure — Contributing to open-source ML

Here is the same matrix in full detail. Every worked example below is tagged with the cell it fills.

Cell Effort Situation Worked example
A Trivial Fix a typo / clarify docs Ex 1
B Local Fix a crash on a degenerate input (empty / 1-D) Ex 2
C Local Fix a silent wrong-number bug Ex 3
D Structural Add a feature with a compute/memory tradeoff Ex 4
E Structural The zero/edge guard everyone forgets Ex 5
F Any → Rejected Your PR is declined — recover gracefully Ex 6
G Word problem A real user opens a vague issue; turn it into a PR Ex 7
H Exam twist Reviewer asks "prove your change is equivalent" Ex 8

The "degenerate input" row (cell B/E) is the analogue of checking every quadrant in geometry: the case that looks trivial but breaks everything. We give it two full examples because it is where beginners lose PRs. There are eight cells and eight worked examples — one for each — so nothing on the matrix is left unworked.

Recall Why enumerate cells at all?

Question: Why lay out a matrix before writing examples? ::: So no class of situation is left unshown — the reader never meets a scenario we skipped, exactly like covering all four quadrants of an angle.


Language and library convention (read this once)

Every code snippet on this page is Python. When a snippet uses .sum(dim=1), .norm(...), .unsqueeze(...) or .ndim, it is operating on a PyTorch tensor — PyTorch's multi-dimensional array type (see Software Engineering for ML). A plain Python list like [1, 2, 3] is not a tensor; the examples show the moment a list is turned into a tensor and given the extra "batch" dimension the library expects. Where we do pure hand-arithmetic we write it as maths in $…$, not as code.


Vocabulary earned before use

Every term the examples lean on, defined once, plainly.

We also use one piece of maths repeatedly — cosine similarity — so define it now.


Ex 1 — Cell A · Trivial · a docs clarification


Ex 2 — Cell B · Local · degenerate input (1-D crash)

This is the "quadrant II where the naive formula fails" of coding: the input the author never pictured.


Ex 3 — Cell C · Local · a silent wrong-number bug

The nastiest bug: no crash, just quietly wrong output.


Ex 4 — Cell D · Structural · a feature with a tradeoff argument


Ex 5 — Cell E · Structural · the zero / degenerate guard

The "what if the input is zero?" case — the coding twin of dividing by zero.


Ex 6 — Cell F · Rejected · recover gracefully


Ex 7 — Cell G · Word problem · vague issue → PR


Ex 8 — Cell H · Exam twist · "prove it's equivalent"


The whole decision, one diagram

trivial

local

structural

merged

revise

rejected

See an issue

Effort level

Docs fix Ex1

Bug fix Ex2 Ex3

Feature Ex4

Guard zero and 1D Ex5

Submit PR with tests

Outcome

Done

Publish plugin Ex6

Recall Self-check

Which cell is "cosine similarity of a zero vector"? ::: Cell E — the degenerate zero-input guard. Why is the PR quality a product not a sum? ::: Any factor at zero (untested, unclear, unjustified) makes the whole PR unmergeable — multiplication makes one zero fatal. What compute factor does gradient checkpointing cost with ? ::: , to keep of stored activations ( only as ).


Prerequisites & neighbours: Version Control with Git · Testing ML Systems · Code Review Best Practices · Software Engineering for ML · ML Research Paper Implementation · Building ML Portfolios · Technical Writing for ML · Collaborative Machine Learning · parent Contributing to open-source ML.