Skip to content

CPU backend: export load_ebook_dataset, RawTextDataLoader and TextPreprocessor - #15501

Merged
danielhanchen merged 2 commits into
mainfrom
fix/cpu-backend-dataprep-exports
Oct 27, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/cpu-backend-dataprep-exports

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

On a host without an accelerator, import unsloth hands off to the CPU backend (unsloth/_cpu_init.py, #14717). The GPU backend exports the dataprep helpers from unsloth (_gpu_init.py), but the CPU backend did not. So the documented from unsloth import load_ebook_dataset (#14453) raises ImportError: cannot import name 'load_ebook_dataset' on CPU-only hosts, and so do RawTextDataLoader and TextPreprocessor.

The CPU backend now exports all three. It loads dataprep/raw_text.py and dataprep/ebooks.py by file, the way the MLX backend already does, because dataprep/__init__ also imports synthetic.py, which needs a GPU device type. Neither file has relative imports.

test_cpu_backend_init.py::test_no_accelerator_loads_the_cpu_backend now also checks the three names in its no-accelerator subprocess probe. The GPU-only module list it asserts against is unchanged.

main this PR
test_cpu_backend_init.py (CUDA hidden) 1 failed, 6 passed, 1 skipped 7 passed, 1 skipped

…processor

The GPU backend exports them from unsloth; the CPU backend (#14717) did not,
so 'from unsloth import load_ebook_dataset' raised ImportError on CPU-only
hosts. Loaded by file so dataprep/__init__ (synthetic.py needs a GPU device
type) never runs.
@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 ✅ Completed 2026-10-27T10:34:26.398360Z a1f4b56 Manual request
ℹ️ 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

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 8bdff71725

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

Both lint reds here come from one PR-specific finding: the risky loader baseline. Source lint (job 122028040895) and workflow-trigger lint (test_the_tree_matches_the_baseline, job 122028040885) each report:

1 risky loader call site(s) not in the baseline:
  unsloth/_cpu_init.py:203  [dynamic-import] spec_from_file_location

_load_dataprep only ever loads unsloth/dataprep/{raw_text}.py from the installed package, with a fixed name from this file, so it is trusted. Running python scripts/lint_risky_loaders.py --update and replacing the "REVIEW ME" reason in scripts/risky_loaders_baseline.json with that (package-local file, constant module name) clears both. The ruff format --check and codespell output higher up in the Source lint log is the usual advisory noise and also shows on green runs.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: a1f4b5614b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 3bce1d1 into main Oct 27, 2026
@danielhanchen
danielhanchen deleted the fix/cpu-backend-dataprep-exports branch October 27, 2026 10:58
danielhanchen added a commit that referenced this pull request Oct 27, 2026
…5501 (#15549)

`Source lint` and `workflow-trigger lint`
(`tests/security/test_lint_risky_loaders.py::test_the_tree_matches_the_baseline`)
fail on main since #15501 merged, and so on every PR based after it
(e.g. #15536, job 122152574837):

```
1 risky loader call site(s) not in the baseline:
  unsloth/_cpu_init.py:205  [dynamic-import] spec_from_file_location
```

#15501 added `_load_dataprep` to the CPU backend init, which loads
`unsloth/dataprep/raw_text.py` and `ebooks.py` by file (so it skips
`dataprep/__init__`, which needs a GPU device type). The call is safe,
but the baseline entry was not recorded before it merged.

## Review

- The path is `Path(__file__).resolve().parent / "dataprep" /
f"{name}.py"`, inside the installed package.
- The only callers pass the constants `"raw_text"` and `"ebooks"`, and
`_load_dataprep` is deleted right after, so nothing else can reach it.
- This is the same shape as the existing `unsloth/__init__.py` entry
that loads `dataprep/ebooks.py` by file on MLX.

## Change

One entry from `python scripts/lint_risky_loaders.py --update`, with the
reason filled in. Nothing else in the baseline moves.

## Verification

- `python scripts/lint_risky_loaders.py`: main reports the site above
and exits 1; this branch prints `ok: 111 risky loader call site(s), all
recorded`.
- `tests/security/test_lint_risky_loaders.py`: main 1 failed, 45 passed;
this branch 46 passed.
- The entry is digest-pinned to the call: changing its path argument to
`os.environ["X_DATAPREP"]` reopens the site and the lint exits 1 again.
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.

1 participant