Skip to content

Trim comments in the Studio frontend and Tauri shell - #12966

Merged
danielhanchen merged 98 commits into
mainfrom
trim-comments-studio-frontend
Oct 26, 2026
Merged

danielhanchen merged 98 commits into
mainfrom
trim-comments-studio-frontend

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Comment trim across the Studio frontend (studio/frontend) and the Tauri desktop shell (studio/src-tauri). No code changes.

scope files comment lines before after
studio/frontend + studio/src-tauri 2112 65273 23027 (-65%)

Counts include docstrings and are measured against current main.

Comment share of non-blank lines goes from 10.1% to 3.7%. Removed: JSX {/* section */} labels, comments that restate the next line, history notes and long explanations that the code or names already carry. Kept: the reasons behind non-obvious state handling, race and ordering notes, platform quirks (WebView2, macOS, Linux), security notes in the Tauri commands, and every comment a frontend or Python contract test reads.

Rust files were checked with doc comments stripped so /// and //! edits are covered too.

How it was checked

  • comment_tools.py check --strict-ext on every changed file against main: the code token stream (AST for Python, lexer/tree-sitter for TS/TSX/JS/shell/PowerShell/YAML/Rust) is identical, so only comments and blank lines changed. Docstrings and string literals are untouched.
  • Comments that code or tests read as text were kept word for word: source-reading tests (read_text, readFileSync, regex and fixed-window matches), inspect.getsource + replace targets, lint markers (lint-allow:, # allow-slot-clamp:, # novermin, noqa, type: ignore, eslint/biome-ignore, @ts-), shellcheck/zizmor directives, #region/#requires, PowerShell help blocks, and the comment blocks that tests require to stay identical between install.sh/studio/setup.sh and install.ps1/studio/setup.ps1.
  • Comments that explain a non-obvious invariant, an ordering constraint, a security decision, an upstream workaround or a magic number were kept or shortened to one line. Narration, history, section banners and restatements of the code were removed.
  • Every changed region was reviewed a second time for comments that became wrong, misplaced or half-finished after condensing, and those were fixed.
  • Repo lints: lint_exec_literals, lint_av_shapes (0 new errors), lint_risky_loaders, lint_no_parallel_clamp, lint_no_duplicate_ts_imports, lint_workflow_triggers, lint_backend_python_floor all pass; scripts/run_ruff_format.py is a fixed point; scripts/sync_shared_ps1_helpers.py --check reports no drift.
  • Tests, main vs main plus all four of these PRs, same machine: the pytest suites (tests/, studio/backend/tests/, unsloth_cli/tests/), the full frontend node --test suite and all 133 tests/**/*.ps1 / tests/sh/*.sh scripts. No test fails with these changes that passes on main (the few one-off differences either pass on both trees or fail on both when rerun alone).

Related

One of four comment-trim PRs split by area so each diff stays reviewable: #12966 (Studio frontend and Tauri), #12967 (Studio backend), #12968 (unsloth, unsloth_cli, tests), #12969 (installers, scripts, CI). They touch disjoint files (apart from one entry each in scripts/av_shapes_baseline.json for #12967 and #12968); the test runs above were on all four applied together.

Update: merged with main, second pass

  • Merged current main. Where hunks conflicted, the merge took main's side, so the branch still differs from main only in comments (comment_tools.py check --strict-ext against the new merge base passes).
  • Tests that landed on main after the first pass read some of the removed comments as anchors, so those comments are back: chat-adapter.ts (// Answered once per thread), prompt-storage-dialog.tsx (/** A sidebar row as one markdown document.), use-chat-model-runtime.ts (/**\n * Reconcile the UI after the SERVER unloaded) and diffusion-train-panel.tsx (// On first activation). The first one failed chat-export-system-prompt.test.ts; the other three made indexOf return -1, so their tests kept passing on a slice that ran to the end of the file.
  • Rechecked against main on the same machine during this pass (affected tests rerun after the last fixes): the full tests/ + unsloth_cli/tests/ pytest run, studio/backend/tests and hub/tests, the full frontend node --test suite, all tests/sh/*.sh and the standalone tests/**/*.ps1 scripts. The remaining differences from main are pytest-timeout expiries and wall-clock assertions under heavy parallel load; every other difference was rerun alone and matches main. lint_av_shapes, lint_exec_literals and lint_risky_loaders pass.

Comment accuracy audit

  • Every comment this PR rewrote (rather than deleted) was compared against the text it replaced, one before/after pair at a time, looking for a dropped not, a reversed condition, a wrong identifier, a torn sentence or a pointer to a comment that no longer exists. Each proposed correction got a second, independent check against the original before it was applied.
  • The corrections that passed are in the "Correct shortened comments that lost or changed meaning" commit. Corrections whose before/after pairing was ambiguous, or that would have touched a line with code on it, were left out.
  • The commit is comment-only (comment_tools.py check --strict-ext), no marker a test or regex reads went missing, and the full Python, backend and frontend suites match main apart from wall-clock assertions under parallel load that pass when rerun alone.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
🔒 Security Review 🔄 Running since 2026-10-07T15:41:50.794659Z dbd9166 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 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-07T15:41:57.867923Z dbd9166 PR opened
🔒 Security Review ⚠️ Failed 2026-10-07T15:41:53.936501Z dbd9166 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 added a commit that referenced this pull request Oct 26, 2026
Comment trim across `unsloth/`, `unsloth_cli/` and `tests/`. No code
changes.

| scope | files | comment lines before | after |
|---|---|---|---|
| unsloth, unsloth_cli, tests (+ av_shapes_baseline.json) | 1377 |
111274 | 46085 (-59%) |

Counts include docstrings and are measured against current `main`.

Removed: section banners, history notes, comments that restate the code
and long multi-paragraph explanations condensed to one line. Kept:
transformers / TRL / PEFT / vLLM version workarounds, dtype and upcast
ordering, Triton kernel layout, overflow and autotune notes,
import-order constraints in `unsloth/__init__.py` and `import_fixes.py`,
and anything `rl.py` / `rl_replacements.py` / unsloth_zoo patch through
`inspect.getsource` (those patches only target code and string literals,
which are unchanged).

## How it was checked

- `comment_tools.py check --strict-ext` on every changed file against
`main`: the code token stream (AST for Python, lexer/tree-sitter for
TS/TSX/JS/shell/PowerShell/YAML/Rust) is identical, so only comments and
blank lines changed. String literals are untouched; docstring edits are
allowed by `--allow-docstring-edits` and covered below.
- Comments that code or tests read as text were kept word for word:
source-reading tests (`read_text`, `readFileSync`, regex and
fixed-window matches), `inspect.getsource` + replace targets, lint
markers (`lint-allow:`, `# allow-slot-clamp:`, `# novermin`, `noqa`,
`type: ignore`, `eslint`/`biome-ignore`, `@ts-`), shellcheck/zizmor
directives, `#region`/`#requires`, PowerShell help blocks, and the
comment blocks that tests require to stay identical between
`install.sh`/`studio/setup.sh` and `install.ps1`/`studio/setup.ps1`.
- Comments that explain a non-obvious invariant, an ordering constraint,
a security decision, an upstream workaround or a magic number were kept
or shortened to one line. Narration, history, section banners and
restatements of the code were removed.
- Every changed region was reviewed a second time for comments that
became wrong, misplaced or half-finished after condensing, and those
were fixed.
- Repo lints: `lint_exec_literals`, `lint_av_shapes` (0 new errors),
`lint_risky_loaders`, `lint_no_parallel_clamp`,
`lint_no_duplicate_ts_imports`, `lint_workflow_triggers`,
`lint_backend_python_floor` all pass; `scripts/run_ruff_format.py` is a
fixed point; `scripts/sync_shared_ps1_helpers.py --check` reports no
drift.
- Tests, `main` vs `main` plus all four of these PRs, same machine: the
pytest suites (`tests/`, `studio/backend/tests/`, `unsloth_cli/tests/`),
the full frontend `node --test` suite and all 133 `tests/**/*.ps1` /
`tests/sh/*.sh` scripts. No test fails with these changes that passes on
`main` (the few one-off differences either pass on both trees or fail on
both when rerun alone).

## Related

One of four comment-trim PRs split by area so each diff stays
reviewable: #12966 (Studio frontend and Tauri), #12967 (Studio backend),
#12968 (unsloth, unsloth_cli, tests), #12969 (installers, scripts, CI).
They touch disjoint files (apart from one entry each in
`scripts/av_shapes_baseline.json` for #12967 and #12968); the test runs
above were on all four applied together.

## Update: merged with main, second pass

- Merged current `main`. Where hunks conflicted, the merge took `main`'s
side, so the branch still differs from `main` only in comments
(`comment_tools.py check --strict-ext` against the new merge base
passes).
- Tests that landed on `main` after the first pass read some of the
removed comments as anchors, so those comments are back: comments in
`tests/kaggle/studio_gpu/run_studio_gpu.py`,
`tests/studio/studiobench/__main__.py`,
`tests/studio/playwright_chat_ui.py` and
`tests/studio/playwright_mac_tab_capabilities.py` that four tests read
by text.
- Second pass on docstrings in `tests/` and `unsloth_cli/tests/`:
multi-line test docstrings collapsed to one line (about 4.7k). Library
docstrings in `unsloth/` are unchanged. One
`scripts/av_shapes_baseline.json` entry recorded a docstring that no
longer names the flagged construct, so it is dropped (`lint_av_shapes`
reports a baseline entry that allows more than the code has as stale).
- Every one-line rewrite was compared against the text it replaced,
looking for a dropped `not`, a reversed condition, a wrong identifier or
a torn sentence. About 240 were corrected.
- Rechecked against `main` on the same machine during this pass
(affected tests rerun after the last fixes): the full `tests/` +
`unsloth_cli/tests/` pytest run, `studio/backend/tests` and `hub/tests`,
the full frontend `node --test` suite, all `tests/sh/*.sh` and the
standalone `tests/**/*.ps1` scripts. The remaining differences from
`main` are pytest-timeout expiries and wall-clock assertions under heavy
parallel load; every other difference was rerun alone and matches
`main`. `lint_av_shapes`, `lint_exec_literals` and `lint_risky_loaders`
pass.
- #12967 and #12968 each drop a different entry from
`scripts/av_shapes_baseline.json`; the two hunks do not overlap.

## Comment accuracy audit

- Every comment this PR rewrote (rather than deleted) was compared
against the text it replaced, one before/after pair at a time, looking
for a dropped `not`, a reversed condition, a wrong identifier, a torn
sentence or a pointer to a comment that no longer exists. Each proposed
correction got a second, independent check against the original before
it was applied.
- The corrections that passed are in the "Correct shortened comments
that lost or changed meaning" commit. Corrections whose before/after
pairing was ambiguous, or that would have touched a line with code on
it, were left out.
- The commit is comment-only (`comment_tools.py check --strict-ext`), no
marker a test or regex reads went missing, and the full Python, backend
and frontend suites match `main` apart from wall-clock assertions under
parallel load that pass when rerun alone.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 26, 2026
Comment trim across the Studio backend (`studio/backend`), including its
tests. No code changes.

| scope | files | comment lines before | after |
|---|---|---|---|
| studio/backend (+ av_shapes_baseline.json) | 1883 | 185225 | 72964
(-61%) |

Counts include docstrings and are measured against current `main`.

Removed: section banners, narration of the next statement, history and
issue-number notes, and long paragraphs condensed to the one line that
matters. Kept: sandbox and path-safety reasoning, process and GPU
lifecycle ordering, llama.cpp / sd.cpp / vLLM version quirks, the
origins of magic numbers, and every comment that a test or
`inspect.getsource` patch matches.

`scripts/av_shapes_baseline.json` drops one entry: the two `tools.py`
comments it recorded no longer exist, so the entry was stale.

## How it was checked

- `comment_tools.py check --strict-ext` on every changed file against
`main`: the code token stream (AST for Python, lexer/tree-sitter for
TS/TSX/JS/shell/PowerShell/YAML/Rust) is identical, so only comments and
blank lines changed. String literals are untouched; docstring edits are
allowed by `--allow-docstring-edits` and covered below.
- Comments that code or tests read as text were kept word for word:
source-reading tests (`read_text`, `readFileSync`, regex and
fixed-window matches), `inspect.getsource` + replace targets, lint
markers (`lint-allow:`, `# allow-slot-clamp:`, `# novermin`, `noqa`,
`type: ignore`, `eslint`/`biome-ignore`, `@ts-`), shellcheck/zizmor
directives, `#region`/`#requires`, PowerShell help blocks, and the
comment blocks that tests require to stay identical between
`install.sh`/`studio/setup.sh` and `install.ps1`/`studio/setup.ps1`.
- Comments that explain a non-obvious invariant, an ordering constraint,
a security decision, an upstream workaround or a magic number were kept
or shortened to one line. Narration, history, section banners and
restatements of the code were removed.
- Every changed region was reviewed a second time for comments that
became wrong, misplaced or half-finished after condensing, and those
were fixed.
- Repo lints: `lint_exec_literals`, `lint_av_shapes` (0 new errors),
`lint_risky_loaders`, `lint_no_parallel_clamp`,
`lint_no_duplicate_ts_imports`, `lint_workflow_triggers`,
`lint_backend_python_floor` all pass; `scripts/run_ruff_format.py` is a
fixed point; `scripts/sync_shared_ps1_helpers.py --check` reports no
drift.
- Tests, `main` vs `main` plus all four of these PRs, same machine: the
pytest suites (`tests/`, `studio/backend/tests/`, `unsloth_cli/tests/`),
the full frontend `node --test` suite and all 133 `tests/**/*.ps1` /
`tests/sh/*.sh` scripts. No test fails with these changes that passes on
`main` (the few one-off differences either pass on both trees or fail on
both when rerun alone).

## Related

One of four comment-trim PRs split by area so each diff stays
reviewable: #12966 (Studio frontend and Tauri), #12967 (Studio backend),
#12968 (unsloth, unsloth_cli, tests), #12969 (installers, scripts, CI).
They touch disjoint files (apart from one entry each in
`scripts/av_shapes_baseline.json` for #12967 and #12968); the test runs
above were on all four applied together.

## Update: merged with main, second pass

- Merged current `main`. Where hunks conflicted, the merge took `main`'s
side, so the branch still differs from `main` only in comments
(`comment_tools.py check --strict-ext` against the new merge base
passes).
- Tests that landed on `main` after the first pass read some of the
removed comments as anchors, so those comments are back: the `#
========== AUDIO MODELS: custom preprocessing ==========` banner in
`trainer.py`, the `1g. ROCm OOM guard` and `2b. Training VRAM budget`
banners in `worker.py`, a `[CALL_ID]` comment in `tool_healing.py`, and
the `_guard_peft_torchao_dispatcher` docstring, which
`test_diffusion_peft_torchao_guard.py` compares by AST against its copy
in `unsloth/import_fixes.py`.
- Second pass on docstrings: multi-line docstrings of backend functions
and tests collapsed to one line, or deleted where they only restated the
name (about 8k docstrings). Left alone: route handlers and every other
decorated function, classes (pydantic models feed the OpenAPI schema),
module docstrings outside tests, `llama_compat.py` (it registers routes
without decorators), and any file that reads `__doc__`.
- Every one-line rewrite was compared against the text it replaced,
looking for a dropped `not`, a reversed condition, a wrong identifier or
a torn sentence. About 240 were corrected.
- Rechecked against `main` on the same machine during this pass
(affected tests rerun after the last fixes): the full `tests/` +
`unsloth_cli/tests/` pytest run, `studio/backend/tests` and `hub/tests`,
the full frontend `node --test` suite, all `tests/sh/*.sh` and the
standalone `tests/**/*.ps1` scripts. The remaining differences from
`main` are pytest-timeout expiries and wall-clock assertions under heavy
parallel load; every other difference was rerun alone and matches
`main`. `lint_av_shapes`, `lint_exec_literals` and `lint_risky_loaders`
pass.
- #12967 and #12968 each drop a different entry from
`scripts/av_shapes_baseline.json`; the two hunks do not overlap.

## Comment accuracy audit

- Every comment this PR rewrote (rather than deleted) was compared
against the text it replaced, one before/after pair at a time, looking
for a dropped `not`, a reversed condition, a wrong identifier, a torn
sentence or a pointer to a comment that no longer exists. Each proposed
correction got a second, independent check against the original before
it was applied.
- The corrections that passed are in the "Correct shortened comments
that lost or changed meaning" commit. Corrections whose before/after
pairing was ambiguous, or that would have touched a line with code on
it, were left out.
- The commit is comment-only (`comment_tools.py check --strict-ext`), no
marker a test or regex reads went missing, and the full Python, backend
and frontend suites match `main` apart from wall-clock assertions under
parallel load that pass when rerun alone.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 26, 2026
Comment trim across the installer helpers and repo tooling: the
`studio/install_*` helpers, `scripts/`, `.github/`, `docker/` and
`pyproject.toml`. No code changes.

The installer entry scripts (`install.sh`, `install.ps1`,
`studio/setup.sh`, `studio/setup.ps1`, `scripts/uninstall.sh`,
`scripts/uninstall.ps1`) moved to #15333 and are identical to `main`
here.

| scope | files | comment lines before | after |
|---|---|---|---|
| installers, scripts, CI, docker | 228 | 38524 | 18625 (-52%) |

Counts include docstrings and are measured against current `main`.

Installer-specific care:
- The comment blocks and PowerShell functions that tests require to be
identical between `install.sh` and `studio/setup.sh`, and between
`install.ps1` and `studio/setup.ps1`, are still identical (all 87 shared
PowerShell functions compared through the PowerShell AST, and
`sync_shared_ps1_helpers.py --check` is clean).
- Comments that `tests/sh` scripts use as `sed`/`awk` anchors are kept
word for word.
- `lint_av_shapes` hashes whole lines, so trailing comments on installer
lines were left alone and no reworded comment introduces scanner
keywords.
- The pyproject comment above the `windows` extra still names
`unsloth[cu130-torch2100]` and `unsloth[cu128-torch2100]`, which
`test_windows_xformers_wheel_match.py` requires.
- Workflow YAML only lost comments; `lint_workflow_triggers` passes and
`uses:` lines are untouched.

## How it was checked

- `comment_tools.py check --strict-ext` on every changed file against
`main`: the code token stream (AST for Python, lexer/tree-sitter for
TS/TSX/JS/shell/PowerShell/YAML/Rust) is identical, so only comments and
blank lines changed. Docstrings and string literals are untouched.
- Comments that code or tests read as text were kept word for word:
source-reading tests (`read_text`, `readFileSync`, regex and
fixed-window matches), `inspect.getsource` + replace targets, lint
markers (`lint-allow:`, `# allow-slot-clamp:`, `# novermin`, `noqa`,
`type: ignore`, `eslint`/`biome-ignore`, `@ts-`), shellcheck/zizmor
directives, `#region`/`#requires`, PowerShell help blocks, and the
comment blocks that tests require to stay identical between
`install.sh`/`studio/setup.sh` and `install.ps1`/`studio/setup.ps1`.
- Comments that explain a non-obvious invariant, an ordering constraint,
a security decision, an upstream workaround or a magic number were kept
or shortened to one line. Narration, history, section banners and
restatements of the code were removed.
- Every changed region was reviewed a second time for comments that
became wrong, misplaced or half-finished after condensing, and those
were fixed.
- Repo lints: `lint_exec_literals`, `lint_av_shapes` (0 new errors),
`lint_risky_loaders`, `lint_no_parallel_clamp`,
`lint_no_duplicate_ts_imports`, `lint_workflow_triggers`,
`lint_backend_python_floor` all pass; `scripts/run_ruff_format.py` is a
fixed point; `scripts/sync_shared_ps1_helpers.py --check` reports no
drift.
- Tests, `main` vs `main` plus all four of these PRs, same machine: the
pytest suites (`tests/`, `studio/backend/tests/`, `unsloth_cli/tests/`),
the full frontend `node --test` suite and all 133 `tests/**/*.ps1` /
`tests/sh/*.sh` scripts. No test fails with these changes that passes on
`main` (the few one-off differences either pass on both trees or fail on
both when rerun alone).

## Related

One of four comment-trim PRs split by area so each diff stays
reviewable: #12966 (Studio frontend and Tauri), #12967 (Studio backend),
#12968 (unsloth, unsloth_cli, tests), #12969 (installers, scripts, CI).
They touch disjoint files (apart from one entry each in
`scripts/av_shapes_baseline.json` for #12967 and #12968); the test runs
above were on all four applied together.

## Update: merged with main, second pass

- Merged current `main`. Where hunks conflicted, the merge took `main`'s
side, so the branch still differs from `main` only in comments
(`comment_tools.py check --strict-ext` against the new merge base
passes).
- `install.ps1` keeps the comment opening `# A redirected stdout is not
a console` above the VT early return:
`test_windows_setup_output_encoding.py` (Windows, PowerShell 5.1 only)
slices the probe on that line.
- Rechecked against `main` on the same machine during this pass
(affected tests rerun after the last fixes): the full `tests/` +
`unsloth_cli/tests/` pytest run, `studio/backend/tests` and `hub/tests`,
the full frontend `node --test` suite, all `tests/sh/*.sh` and the
standalone `tests/**/*.ps1` scripts. The remaining differences from
`main` are pytest-timeout expiries and wall-clock assertions under heavy
parallel load; every other difference was rerun alone and matches
`main`. `lint_av_shapes`, `lint_exec_literals` and `lint_risky_loaders`
pass.

## Comment accuracy audit

- Every comment this PR rewrote (rather than deleted) was compared
against the text it replaced, one before/after pair at a time, looking
for a dropped `not`, a reversed condition, a wrong identifier, a torn
sentence or a pointer to a comment that no longer exists. Each proposed
correction got a second, independent check against the original before
it was applied.
- The corrections that passed are in the "Correct shortened comments
that lost or changed meaning" commit. Corrections whose before/after
pairing was ambiguous, or that would have touched a line with code on
it, were left out.
- The commit is comment-only (`comment_tools.py check --strict-ext`), no
marker a test or regex reads went missing, and the full Python, backend
and frontend suites match `main` apart from wall-clock assertions under
parallel load that pass when rerun alone.

## Update: installer entry scripts split out

- `install.sh`, `install.ps1`, `studio/setup.sh`, `studio/setup.ps1`,
`scripts/uninstall.sh` and `scripts/uninstall.ps1` now match `main` in
this PR; their trim lives in #15333. The installer-specific notes above
about those files apply to #15333.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@danielhanchen
danielhanchen merged commit 9e44983 into main Oct 26, 2026
@danielhanchen
danielhanchen deleted the trim-comments-studio-frontend branch October 26, 2026 10:05
danielhanchen added a commit to unslothai/unsloth-zoo that referenced this pull request Oct 30, 2026
Condenses comments and docstrings across `tests/`, following the same
rules as the package PR and the Unsloth cleanup
(unslothai/unsloth#12966, #12967, #12968, #12969, #15594). This touches
tests only and does not depend on the package PR (#2192).

No code changes. Every changed file has an identical code token stream
and an identical AST once docstrings are removed.

## What changed

648 files, +7,732 / -22,089 lines. Item counts below are from the
rewrite pass; a few hundred were later restored (conflicts with main,
scanner evidence spans).

- 2,002 multi-line comment blocks condensed to one line, or a few
wrapped lines when there are several facts to keep.
- 3,148 test function and class docstrings condensed.
- 525 module docstrings condensed. A static reader analysis proved
nothing reads these.
- 21 single-line comments deleted. These only restated the next line or
were commented-out code.
- 4,103 informative single-line comments kept as they were.

The condensed text keeps:
- what each test pins and why;
- the bug or upstream behaviour it guards (with issue numbers);
- version bounds, shapes and dtypes;
- env vars;
- must / never rules.

## Left untouched

- **Never edited:**
  - section delimiters;
  - license headers;
  - tool directives (`noqa`, `type: ignore`, `pragma`, `fmt`, ...).
- **Excluded:** `tests/mlx_simulation/**`.
- **Text that tests read back:** comments and docstrings containing text
that a test or the unsloth repo reads, such as slices taken after `# LM
Head`, `# packing rejected/unused` and `# labels-aware path`. Docstrings
read through `__doc__` are also left alone.

## Verification

- **Code unchanged:** `comment_tools.py check --strict-ext
--allow-docstring-edits` passes 651/651.
`scripts/verify_comment_only_diff.py` passes on every changed file.
- **Comment structure:**
  - Delimiter and directive comment sequences are identical.
  - No comment moved to a different code position.
  - No rewritten block borders another comment.
- **Package scanner:** the zoo sdist ships `tests/`, and Unsloth's
Security Audit baselines findings there by evidence hash. Unsloth's
`check_py_file` finds the same keys at main and at this head in every
changed file; edits inside evidence spans were restored to make this
hold.
- **Lints:** `lint_exec_literals.py`, `lint_dynamic_exec.py`,
`lint_risky_loaders.py` and `lint_workflow_triggers.py` pass with
baselines untouched, and `python -W error -m compileall` passes.
- **Module docstrings:** a reader analysis over this repo and unsloth
confirms that every changed module docstring has no reader.
- **Tests (GPUs blocked), on main as of #2253:** the full `tests/` suite
ran on main and on this branch with #2192 merged in, and both collect
the same 21,224 tests. Every test that failed on only one side under
xdist passes identically on both sides when its file runs alone. After
main moved to #2255, the tests that main changed pass the same on both
sides. Files that conflicted with main (`test_cpu_backend.py`,
`test_gc_collect_early_stop_loops.py`, `test_mlx_attention_metal.py`)
take main's version unchanged. Staging CI is green: Lint, Tests, Wheel,
Security audit and studio-export-fix. MLX on Apple Silicon: the pinned
leg is green. The latest leg fails the same three cases on main, so that
failure predates this PR.
- **Review:** each rewrite was checked for meaning lost or claims added.
Removals in tests that read their own source were checked for readers.
Anything a reviewer flagged without a confirmed correction was restored
to the original text.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-zoo-staging-2 that referenced this pull request Oct 30, 2026
Condenses comments and docstrings across `unsloth_zoo/`,
`unsloth_zoo_downloads/` and `scripts/`, following the same rules as the
Unsloth cleanup (unslothai/unsloth#12966, #12967, #12968, #12969,
#15594). The tests get the same treatment in unslothai#2193.

No code changes. Every changed file has an identical code token stream
and an identical AST once docstrings are removed.

## What changed

152 files, +5,261 / -13,205 lines. Item counts below are from the
rewrite pass; a few dozen were later restored (conflicts with main,
newly read text, scanner evidence spans).

- 2,086 multi-line comment blocks condensed to one line, or a few
wrapped lines when there are several facts to keep.
- 1,143 function and class docstrings condensed.
- 57 module docstrings condensed. A static reader analysis (below)
proved nothing reads these.
- 96 single-line comments deleted. These only restated the next line (`#
Check if the folder exists`, `# Go through all layers!`) or were
commented-out code.
- 3,249 informative single-line comments kept as they were.

The condensed text keeps every fact a reader needs:
- the reason for a workaround;
- version bounds (transformers / TRL / torch / triton / vLLM);
- shapes and dtypes;
- env vars and flags;
- issue numbers;
- fail-open and best-effort behaviour;
- must / never rules;
- ordering rules and security reasons.

## Left untouched

- **Never edited:**
  - section delimiters;
  - license and attribution headers;
- tool directives (`noqa`, `type: ignore`, `pragma`, `fmt`, `nosec`,
...);
  - `# All Unsloth Zoo code licensed under LGPLv3` markers.
- **Excluded files:**
  - `_vendored/**`, `vllm_lora_request.py` and `stubs/**`;
- `converter_scan.py` and `scripts/scan_packages.py` (mirrored
scanners).
- **Text that something reads**, found by a static inventory over this
repo and the unsloth repo:
- any comment or docstring containing a string literal or regex that a
test, a source patcher or unsloth searches for in source;
- comments inside functions whose source is copied into generated code
(`inspect.getsource` targets, for example `grpo_compute_loss` and
`_get_vllm_state_dict`);
  - comments inside `exec` / `compile` spans and in registry tables;
  - docstrings read through `__doc__`, `getdoc` or `functools.wraps`.

3,079 candidate comments and docstrings were frozen this way. The
inventory is rerun every time main moves. Comments it newly flags are
restored to main's text, and files that conflict with main take main's
version unchanged. So far that is `gradient_checkpointing.py`,
`routing_replay.py`, `dataset_utils.py`, `mlx/generate.py`,
`mlx/inference.py` and `mlx/speculative.py`.

## Verification

- **Code unchanged:** `comment_tools.py check --strict-ext
--allow-docstring-edits` passes 158/158. The repo's own
`scripts/verify_comment_only_diff.py` passes on every changed file.
- **Comment structure:**
- Delimiter and directive comment sequences are identical in every
changed file.
  - No comment moved to a different code position (token-anchor check).
- No rewritten comment block borders another comment, so there are no
half-rewritten sentences.
- **Package scanner:** Unsloth's Security Audit baselines zoo findings
by evidence hash, and that hash can cover comment lines inside a long
matched span. Unsloth's own `scripts/scan_packages.py` `check_py_file`
was run on every changed file at main and at this head. It finds the
same keys (package, file, check, evidence hash) on both, so the next zoo
release cannot reopen a baselined finding. Edits inside evidence spans
were restored to make this hold.
- **Lints:** `lint_exec_literals.py`, `lint_dynamic_exec.py` and
`lint_risky_loaders.py` (self-test and full scan) pass with their
baselines untouched. So do `lint_workflow_triggers.py` and
`enforce_kwargs_spacing.py`, and `python -W error -m compileall` passes.
- **Module docstrings:** a reader analysis over this repo and unsloth
confirms that every changed module docstring has no reader. It checks
`__doc__`, `getdoc`, `help`, `getsource` and file reads that match the
module.
- **Generated code:** Unsloth's compiled cache was generated on CPU from
main and from this branch, with fixed hashing and separate cache dirs.
It covers the RL trainers (GRPO, DPO, KTO, ORPO, CPO, RLOO, GKD, ...)
and 20 model types through `unsloth_compile_transformers`. All 42
generated files match token for token. 41 are byte-identical;
`moe_utils.py` differs only in comments because it is a copy of the
package file.
- **Tests (GPUs blocked), on main with unslothai#2193 merged:**
- Zoo suite: the full `tests/` suite ran on main and on this branch, and
both collect the same 21,244 tests. Every test that failed on only one
side under xdist passes identically on both sides when its file runs
alone (`test_recompile_limit_fallback`,
`test_routing_replay_compile_pending`, `test_sparse_attention_flex`: 118
passed, 39 skipped, twice each). Earlier rounds on older mains gave the
same result.
- Unsloth: the 229 unsloth test files that read zoo source ran with zoo
main and with this branch first on `PYTHONPATH`, with a session check
that each arm imports its own `unsloth_zoo`. Both collect the same
10,842 tests. The two gloo DDP tests in `test_fused_preference_loss.py`
hang under xdist on main too, so they ran separately (2 passed on each
side). The only failures unique to the branch are 2
`test_extended_module_imports` cases. They fail because another test in
the same worker leaves a stub `unsloth_zoo.device_type` in
`sys.modules`; on another run main hit the same thing. Run alone, they
pass on both sides.
- Generated code: the compiled cache (42 files) is still token-identical
to main.
- Staging CI is green: Lint, Tests (repo CPU tests, MLX Linux CPU, Core
drift, 3.10-3.13 collect), Wheel, Security audit and studio-export-fix.
- MLX on Apple Silicon (dispatched, since that job is opt-in on PRs):
the pinned leg is green. The latest leg fails the same three
`test_vlm_stream_row_left_alone_decodes_bitwise_without_the_single_row_shortcut`
cases on main, so that failure predates this PR.
- Unsloth Core against this branch: `consolidated-tests-ci.yml` was
dispatched on an unsloth staging repo with `unsloth_zoo_ref` set to this
head, and again with zoo main. The job results match: all six Core and
Core zoo legs (HF 4.57.6 / default / latest) pass on both. `llama.cpp
build + smoke` fails on both, unrelated to this change.
- **Review:** each rewrite was checked for meaning lost or claims added.
Removals in files that read or patch source were checked against both
repos for readers. Proposed corrections went through a second check;
anything a reviewer flagged without a confirmed correction was restored
to the original text.

## Not covered here

GPU-only code paths are covered only by the token and AST identity above
and by the CPU-side checks. Comments in regions that GPU code reads by
text stay verbatim.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants