Commit graph

1 commit

Author SHA1 Message Date
Daniel Han
8601821e37
Report unsloth's own version on the MLX path (#8395)
* Report unsloth's own version on the MLX path

The MLX branch of unsloth/__init__.py set __version__ from unsloth_zoo, a
different package pinned with >= rather than ==, so unsloth.__version__ on
Apple Silicon reported a number that was neither the installed core nor the
latest zoo. It also disagreed with pip show unsloth, unsloth --version and
Studio's own version on the same machine.

Move the literal into unsloth/_version.py, a leaf module with no imports, and
have every consumer read it from there. The MLX path can import it without
reaching unsloth.models._utils, which pulls in torch, transformers, trl, peft
and the Triton kernels and would defeat that branch's torch-free boot.

pyproject keeps deriving the distribution version from it, and setuptools still
resolves it with a static AST parse, so building a wheel never imports torch.
models/_utils.py re-exports the name, so existing consumers are unchanged.
Studio's get_unsloth_version fallback scans for a __version__ = line and now
points at the file that still has one, else a source checkout reports dev.

The GPU path already reported the core's own version and is unaffected.

Fixes #8171

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Keep the version fallback working on a half-updated tree

get_unsloth_version falls back to scanning the source when distribution metadata
is missing, which is the source-checkout case. The scan matches a __version__ =
line prefix, and moving the literal left models/_utils.py holding only a
re-export, which that prefix does not match. Pointing the scan at _version.py
alone is correct for a current tree but reports dev on any tree where the two
files disagree, which a partial unsloth studio update can produce.

Try both files in order, so either one alone still yields a real version.

The test that pinned this was matching main.py's source with a regex, which
broke on the very refactor it was meant to guard. Replace it with one that runs
the real function against the real tree with metadata forced absent, and add the
half-updated layouts. Verified against real installs: wheel, sdist, editable and
source checkout all report 2026.8.12, and neither-file-current still reports dev
rather than a wrong number.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Tighten the comments on the version change

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-08-11 01:10:03 -07:00