Skip to content

Conversation

@LysandreJik
Copy link
Member

@LysandreJik LysandreJik commented Nov 27, 2025

Better guard the CLI commands, so that transformers add-new-model-like works without the serving dependencies (bug) and so that transformers chat does not import torch unnecessarily (improvement)

The transformers run (previously transformers-cli run) is an artefact of the past, was not documented nor tested,
and isn't part of any public documentation. Removing it for now and writing about it in the migration guide.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@LysandreJik LysandreJik marked this pull request as ready for review November 27, 2025 09:33
Comment on lines +96 to +103
try:
is_available, torch_version = _is_package_available("torch", return_version=True)
parsed_version = version.parse(torch_version)
if is_available and parsed_version < version.parse("2.2.0"):
logger.warning_once(f"Disabling PyTorch because PyTorch >= 2.2 is required but found {torch_version}")
return is_available and version.parse(torch_version) >= version.parse("2.2.0")
except packaging.version.InvalidVersion:
return False
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to revert this; I ran into an edge-case when uninstalling torch where it would still show up with is_available yet would have 'N/A' as a version.

This is a bit out of scope of that PR so happy to revert it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just saw that, isn't that caused by the lru_cache maybe?

app.command(name="chat", cls=ChatCommand)(Chat)
app.command()(download)
app.command()(env)
app.command()(run)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? If yes, can the run.py be entirely removed since it's not used anymore?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if removed, would be good to mention it in PR description + migration guide.

Apart from that the PR looks good to me (haven't run it locally though)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks @Wauplin

Copy link
Contributor

@molbap molbap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems faster and fixes transformers add-new-model-like on fresh envs, thanks!


def stream_response(streamer, _request_id):
# Temporary hack for GPTOS 2: filter out the CoT tokens. Full solution here implies defining new output
# Temporary hack for GPT-OSS 2: filter out the CoT tokens. Full solution here implies defining new output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Temporary hack for GPT-OSS 2: filter out the CoT tokens. Full solution here implies defining new output
# Temporary hack for GPT-OSS: filter out the CoT tokens. Full solution here implies defining new output

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fix 2 out of 3 for the GPT OSS family of models :)

Comment on lines +96 to +103
try:
is_available, torch_version = _is_package_available("torch", return_version=True)
parsed_version = version.parse(torch_version)
if is_available and parsed_version < version.parse("2.2.0"):
logger.warning_once(f"Disabling PyTorch because PyTorch >= 2.2 is required but found {torch_version}")
return is_available and version.parse(torch_version) >= version.parse("2.2.0")
except packaging.version.InvalidVersion:
return False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just saw that, isn't that caused by the lru_cache maybe?

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@LysandreJik LysandreJik enabled auto-merge (rebase) November 27, 2025 09:59
@LysandreJik LysandreJik merged commit 08a4049 into main Nov 27, 2025
24 checks passed
@LysandreJik LysandreJik deleted the cli-import-guards-main branch November 27, 2025 10:02
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.

5 participants