Skip to content

Condense module docstrings, keeping the guarantees they state - #15594

Merged
danielhanchen merged 1 commit into
mainfrom
trim-module-docstrings-v2
Oct 28, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
trim-module-docstrings-v2

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

The earlier comment-trim PRs skipped every module (top-of-file) docstring outside tests. This condenses 556 of them across studio/backend, unsloth, unsloth_cli, scripts and the top-level studio/*.py helpers, from 5,673 lines to 959. Nothing else changes.

before after
module docstring lines in the 556 files 5,673 959

Each docstring keeps what the module is for plus the rules other code relies on: fail-open or best-effort behaviour, import-time safety ("stdlib only, safe to import early"), compatibility promises, route lists, security reasons, ordering rules. For example studio/backend/routes/llama.py now reads llama.cpp prebuilt update routes: GET /api/llama/update-status, GET /api/llama/update-changelog, POST /api/llama/update; fail open; old top-level fields keep shape so older clients work; whisper and audio.cpp chain as phases.

Help text and anything that reads a docstring is left alone

A module docstring was only touched when an AST pass over every Python file in the repo (nothing imported) found no way for it to be read:

  • the module itself never names __doc__ (description=__doc__, print(__doc__), globals(), sys.modules[__name__]);
  • no file reads <module>.__doc__ through its imports, and no file that imports the module reads .__doc__ on a base that cannot be resolved;
  • no file passes the module (or an unresolved name, in a file importing it) to inspect.getdoc, inspect.getcomments, pydoc or help(), or the whole module to inspect.getsource;
  • no file reads __doc__ through getattr/vars while naming the module;
  • no 20+ character fragment of the docstring appears verbatim in another file that names or imports the module (a source-reading test or tool anchoring on it).

80 modules failed one of these and are unchanged, including every scripts/ file whose argparse help is description=__doc__, studio/install_python_stack.py, and modules that tests read whole with inspect.getsource (core/inference/diffusion.py, llama_cpp.py, video.py, ...).

How it was checked

  • Only module docstrings changed: for every changed file the module AST, with the docstring text blanked, is identical to main (every other statement, docstring and string literal is byte-identical), and the file is on the safe list. comment_tools.py check --strict-ext --allow-docstring-edits passes on all 556 files.
  • Help output, byte for byte against main: unsloth --help and all 40 subcommand help pages, plus python <file> --help for all 65 scripts with an argparse/click/typer parser and a __main__ block. Two scripts cannot print help in this environment on either side (kv_cache_multiturn_benchmark.py needs a GPU to import, kernel_install.py must run as a module); python -m utils.kernel_install --help is identical on both, and the benchmark's parser has no description.
  • Tests, main vs this branch on the same commit: every backend test file that reads source text, docstrings or line numbers (905 files: read_text, open(, getsource, linecache, lineno, __doc__, get_docstring, ast.parse, tokenize), the full root and unsloth_cli suites, and every frontend test that reads a .py file. Failing IDs match main; the few one-off differences pass 3/3 alone on both sides.
  • Wording: each rewrite was reviewed against its original for a lost rule, a reversed condition or an invented claim, and each proposed correction was independently checked against the original before it was applied.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-27T19:18:18.438486Z
We couldn’t complete this review. Comment @codex review to try again.
4e41e04 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen
danielhanchen merged commit cb678f5 into main Oct 28, 2026
@danielhanchen
danielhanchen deleted the trim-module-docstrings-v2 branch October 28, 2026 06:15
danielhanchen added a commit that referenced this pull request Nov 9, 2026
…auri (#16109)

Condenses the multi-line comments, docstrings and JSDoc / block comments
that landed in the Studio frontend (`studio/frontend`) and the Tauri
shell (`studio/src-tauri`) after the last cleanup (#12966, #12967,
#12968, #12969, #15333, #15594). Same rules as before: every fact a
reader needs stays (the reason for a workaround, version bounds, shapes
and dtypes, env vars and flags, issue numbers, must / never rules,
ordering and security reasons); narration, step-by-step restatement and
history go. Informative one-line comments are not touched.

No code changes: every changed file has an identical code token stream
(and, for Python, an identical AST once docstrings are removed).

109 files, +343 / -582 lines.

## Scope

Only sections of 2+ lines whose lines were mostly written after the last
cleanup merged. A rewrite is applied only when it saves at least one
line, so tight comments are left as they are.

Left untouched:
- section delimiters, license / SPDX headers, tool directives (`noqa`,
`type: ignore`, `eslint-disable`, `@ts-expect-error`, `biome-ignore`,
`shellcheck`, `#region`, ...), PowerShell comment-based help, JSX `{/*
*/}` comments
- Python docstrings that can be read at runtime (decorated routes /
tools / commands, pydantic models, classes outside tests, anything in a
file that reads `__doc__`; module docstrings only where a reader
analysis over the whole repo found no reader)
- scripts that read their own text back (`$0` / `BASH_SOURCE` /
`$PSCommandPath` / `__file__`)
- any comment containing a string literal that a test or source-reading
script searches for, in a file that reader names (including escaped
multi-line literals)
- any comment inside a span that a frontend test regex matches in the
source it reads
- the line `scripts/lint_av_shapes.py` keys its baseline on
- helpers that exist in more than one file (the shared `install.ps1` /
`studio/setup.ps1` functions, a few Python helpers): every copy keeps
the same comments, since tests compare the copies as text

## Verification

- `comment_tools.py check --strict-ext --allow-docstring-edits` passes
on every changed file (code tokens identical, all languages).
- Delimiter and tool-directive comment sequences are identical in every
changed file.
- `scripts/lint_*.py` (av_shapes, exec_literals, risky_loaders,
workflow_triggers, no_parallel_clamp, no_duplicate_ts_imports,
duplicate_definitions, backend_python_floor) and `ruff check` give the
same result on main and on this branch.
- CLI help: every `--help` surface (41 `unsloth` CLI commands, 40
scripts with a parser) is byte-identical to main.
- Tests (no GPU), main vs all five round-2 branches together, compared
by failing test ID: Studio backend tests that read source text (69,853
tests), root and `unsloth_cli` tests that read source text (41,578
tests), and every frontend node test (14,542 tests). No test fails only
on the branch once ordering effects are rerun alone; the real readers
this and staging CI turned up (a sidebar layout regex, the av_shapes
baseline line, and the test that compares the `install.ps1` /
`studio/setup.ps1` helpers) are handled by keeping those comments
verbatim. Functions that were identical across files on main
(PowerShell, shell, Python) are still identical on the branches.
- PowerShell and shell tests that name `install.ps1`, `studio/setup.ps1`
or the changed shell test (64 files, run with `pwsh` / `bash`): all pass
on main and on the branches.
- Each rewrite was reviewed for meaning lost or claims added, removals
in files that other files read were checked for readers, and proposed
corrections went through a second check; anything flagged without a
confirmed correction keeps its original text.
danielhanchen added a commit that referenced this pull request Nov 9, 2026
…nd CI (#16112)

Condenses the multi-line comments, docstrings and JSDoc / block comments
that landed in the installer helpers, scripts and CI (`studio/*.py`,
`studio/scripts`, `scripts/`, `.github`, `docker`) after the last
cleanup (#12966, #12967, #12968, #12969, #15333, #15594). Same rules as
before: every fact a reader needs stays (the reason for a workaround,
version bounds, shapes and dtypes, env vars and flags, issue numbers,
must / never rules, ordering and security reasons); narration,
step-by-step restatement and history go. Informative one-line comments
are not touched.

No code changes: every changed file has an identical code token stream
(and, for Python, an identical AST once docstrings are removed).

50 files, +669 / -1,747 lines.

## Scope

Only sections of 2+ lines whose lines were mostly written after the last
cleanup merged. A rewrite is applied only when it saves at least one
line, so tight comments are left as they are.

Left untouched:
- section delimiters, license / SPDX headers, tool directives (`noqa`,
`type: ignore`, `eslint-disable`, `@ts-expect-error`, `biome-ignore`,
`shellcheck`, `#region`, ...), PowerShell comment-based help, JSX `{/*
*/}` comments
- Python docstrings that can be read at runtime (decorated routes /
tools / commands, pydantic models, classes outside tests, anything in a
file that reads `__doc__`; module docstrings only where a reader
analysis over the whole repo found no reader)
- scripts that read their own text back (`$0` / `BASH_SOURCE` /
`$PSCommandPath` / `__file__`)
- any comment containing a string literal that a test or source-reading
script searches for, in a file that reader names (including escaped
multi-line literals)
- any comment inside a span that a frontend test regex matches in the
source it reads
- the line `scripts/lint_av_shapes.py` keys its baseline on
- helpers that exist in more than one file (the shared `install.ps1` /
`studio/setup.ps1` functions, a few Python helpers): every copy keeps
the same comments, since tests compare the copies as text

## Verification

- `comment_tools.py check --strict-ext --allow-docstring-edits` passes
on every changed file (code tokens identical, all languages).
- Delimiter and tool-directive comment sequences are identical in every
changed file.
- `scripts/lint_*.py` (av_shapes, exec_literals, risky_loaders,
workflow_triggers, no_parallel_clamp, no_duplicate_ts_imports,
duplicate_definitions, backend_python_floor) and `ruff check` give the
same result on main and on this branch.
- CLI help: every `--help` surface (41 `unsloth` CLI commands, 40
scripts with a parser) is byte-identical to main.
- Tests (no GPU), main vs all five round-2 branches together, compared
by failing test ID: Studio backend tests that read source text (69,853
tests), root and `unsloth_cli` tests that read source text (41,578
tests), and every frontend node test (14,542 tests). No test fails only
on the branch once ordering effects are rerun alone; the real readers
this and staging CI turned up (a sidebar layout regex, the av_shapes
baseline line, and the test that compares the `install.ps1` /
`studio/setup.ps1` helpers) are handled by keeping those comments
verbatim. Functions that were identical across files on main
(PowerShell, shell, Python) are still identical on the branches.
- PowerShell and shell tests that name `install.ps1`, `studio/setup.ps1`
or the changed shell test (64 files, run with `pwsh` / `bash`): all pass
on main and on the branches.
- Each rewrite was reviewed for meaning lost or claims added, removals
in files that other files read were checked for readers, and proposed
corrections went through a second check; anything flagged without a
confirmed correction keeps its original text.
danielhanchen added a commit that referenced this pull request Nov 9, 2026
Condenses the multi-line comments, docstrings and JSDoc / block comments
that landed in the Studio backend (`studio/backend`) after the last
cleanup (#12966, #12967, #12968, #12969, #15333, #15594). Same rules as
before: every fact a reader needs stays (the reason for a workaround,
version bounds, shapes and dtypes, env vars and flags, issue numbers,
must / never rules, ordering and security reasons); narration,
step-by-step restatement and history go. Informative one-line comments
are not touched.

No code changes: every changed file has an identical code token stream
(and, for Python, an identical AST once docstrings are removed).

922 files, +5,663 / -11,400 lines.

## Scope

Only sections of 2+ lines whose lines were mostly written after the last
cleanup merged. A rewrite is applied only when it saves at least one
line, so tight comments are left as they are.

Left untouched:
- section delimiters, license / SPDX headers, tool directives (`noqa`,
`type: ignore`, `eslint-disable`, `@ts-expect-error`, `biome-ignore`,
`shellcheck`, `#region`, ...), PowerShell comment-based help, JSX `{/*
*/}` comments
- Python docstrings that can be read at runtime (decorated routes /
tools / commands, pydantic models, classes outside tests, anything in a
file that reads `__doc__`; module docstrings only where a reader
analysis over the whole repo found no reader)
- scripts that read their own text back (`$0` / `BASH_SOURCE` /
`$PSCommandPath` / `__file__`)
- any comment containing a string literal that a test or source-reading
script searches for, in a file that reader names (including escaped
multi-line literals)
- any comment inside a span that a frontend test regex matches in the
source it reads
- the line `scripts/lint_av_shapes.py` keys its baseline on
- helpers that exist in more than one file (the shared `install.ps1` /
`studio/setup.ps1` functions, a few Python helpers): every copy keeps
the same comments, since tests compare the copies as text

## Verification

- `comment_tools.py check --strict-ext --allow-docstring-edits` passes
on every changed file (code tokens identical, all languages).
- Delimiter and tool-directive comment sequences are identical in every
changed file.
- `scripts/lint_*.py` (av_shapes, exec_literals, risky_loaders,
workflow_triggers, no_parallel_clamp, no_duplicate_ts_imports,
duplicate_definitions, backend_python_floor) and `ruff check` give the
same result on main and on this branch.
- CLI help: every `--help` surface (41 `unsloth` CLI commands, 40
scripts with a parser) is byte-identical to main.
- Tests (no GPU), main vs all five round-2 branches together, compared
by failing test ID: Studio backend tests that read source text (69,853
tests), root and `unsloth_cli` tests that read source text (41,578
tests), and every frontend node test (14,542 tests). No test fails only
on the branch once ordering effects are rerun alone; the real readers
this and staging CI turned up (a sidebar layout regex, the av_shapes
baseline line, and the test that compares the `install.ps1` /
`studio/setup.ps1` helpers) are handled by keeping those comments
verbatim. Functions that were identical across files on main
(PowerShell, shell, Python) are still identical on the branches.
- PowerShell and shell tests that name `install.ps1`, `studio/setup.ps1`
or the changed shell test (64 files, run with `pwsh` / `bash`): all pass
on main and on the branches.
- Each rewrite was reviewed for meaning lost or claims added, removals
in files that other files read were checked for readers, and proposed
corrections went through a second check; anything flagged without a
confirmed correction keeps its original text.
danielhanchen added a commit that referenced this pull request Nov 9, 2026
…16111)

Condenses the multi-line comments, docstrings and JSDoc / block comments
that landed in the core package (`unsloth/`), the CLI (`unsloth_cli/`)
and `tests/` after the last cleanup (#12966, #12967, #12968, #12969,
#15333, #15594). Same rules as before: every fact a reader needs stays
(the reason for a workaround, version bounds, shapes and dtypes, env
vars and flags, issue numbers, must / never rules, ordering and security
reasons); narration, step-by-step restatement and history go.
Informative one-line comments are not touched.

No code changes: every changed file has an identical code token stream
(and, for Python, an identical AST once docstrings are removed).

437 files, +2,397 / -4,483 lines.

## Scope

Only sections of 2+ lines whose lines were mostly written after the last
cleanup merged. A rewrite is applied only when it saves at least one
line, so tight comments are left as they are.

Left untouched:
- section delimiters, license / SPDX headers, tool directives (`noqa`,
`type: ignore`, `eslint-disable`, `@ts-expect-error`, `biome-ignore`,
`shellcheck`, `#region`, ...), PowerShell comment-based help, JSX `{/*
*/}` comments
- Python docstrings that can be read at runtime (decorated routes /
tools / commands, pydantic models, classes outside tests, anything in a
file that reads `__doc__`; module docstrings only where a reader
analysis over the whole repo found no reader)
- scripts that read their own text back (`$0` / `BASH_SOURCE` /
`$PSCommandPath` / `__file__`)
- any comment containing a string literal that a test or source-reading
script searches for, in a file that reader names (including escaped
multi-line literals)
- any comment inside a span that a frontend test regex matches in the
source it reads
- the line `scripts/lint_av_shapes.py` keys its baseline on
- the derivation, diagram and tuning-table comments in `unsloth/kernels`
(the cross entropy loss math, num_warps tables, fitted fused-vs-dense
thresholds, GEMV config notes)
- helpers that exist in more than one file (the shared `install.ps1` /
`studio/setup.ps1` functions, a few Python helpers): every copy keeps
the same comments, since tests compare the copies as text

## Verification

- `comment_tools.py check --strict-ext --allow-docstring-edits` passes
on every changed file (code tokens identical, all languages).
- Delimiter and tool-directive comment sequences are identical in every
changed file.
- `scripts/lint_*.py` (av_shapes, exec_literals, risky_loaders,
workflow_triggers, no_parallel_clamp, no_duplicate_ts_imports,
duplicate_definitions, backend_python_floor) and `ruff check` give the
same result on main and on this branch.
- CLI help: every `--help` surface (41 `unsloth` CLI commands, 40
scripts with a parser) is byte-identical to main.
- Tests (no GPU), main vs all five round-2 branches together, compared
by failing test ID: Studio backend tests that read source text (69,853
tests), root and `unsloth_cli` tests that read source text (41,578
tests), and every frontend node test (14,542 tests). No test fails only
on the branch once ordering effects are rerun alone; the real readers
this and staging CI turned up (a sidebar layout regex, the av_shapes
baseline line, and the test that compares the `install.ps1` /
`studio/setup.ps1` helpers) are handled by keeping those comments
verbatim. Functions that were identical across files on main
(PowerShell, shell, Python) are still identical on the branches.
- PowerShell and shell tests that name `install.ps1`, `studio/setup.ps1`
or the changed shell test (64 files, run with `pwsh` / `bash`): all pass
on main and on the branches.
- Each rewrite was reviewed for meaning lost or claims added, removals
in files that other files read were checked for readers, and proposed
corrections went through a second check; anything flagged without a
confirmed correction keeps its original text.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant