Add a simple --version flag#5516
Merged
Merged
Conversation
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements a version flag for the Unsloth CLI, utilizing importlib.metadata to retrieve the package version. The review feedback suggests optimizing the version retrieval by moving it into the callback function to prevent unnecessary execution on every import and adjusting the formatting of the Typer option to match the project's established coding standards.
Contributor
Author
|
If you do not like the @app.callback()
def main(
version: bool = typer.Option(
None,
"--version",
"-V",
callback = show_version,
is_eager = True,
help = "Show version and exit.",
),
):
"""Command-line interface for Unsloth training, inference, and export."""Did you know? This still works then: python3 cli.py --help
Usage: cli.py [OPTIONS] COMMAND [ARGS]...
Command-line interface for Unsloth training, inference, and export. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Add a
--versionflag to the CLI tool, which will try to use the built-in package_version and exit (exit-code zero).Fixes: #5515
See also: https://typer.tiangolo.com/tutorial/options/version/#first-version-of-version
Example:
Help output:
python3 cli.py --help Usage: cli.py [OPTIONS] COMMAND [ARGS]... Command-line interface for Unsloth training, inference, and export. ╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --version -V Show version and exit. │ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │ │ --help -h Show this message and exit. │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ train Launch training using the existing Unsloth training backend. │ │ inference Run a single inference using the specified model. │ │ export Export a checkpoint to various formats (merged, GGUF, LoRA adapter). │ │ list-checkpoints List checkpoints detected in the outputs directory. │ │ run Alias for `unsloth studio run`. │ │ studio Unsloth Studio commands. │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯