Skip to content

Skip unsupported stop parameter for reasoning models #1211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 18, 2025

Conversation

albertvillanova
Copy link
Member

@albertvillanova albertvillanova commented Apr 17, 2025

Skip unsupported stop parameter for reasoning models: o3 and o4-mini

Fix #1210.

@albertvillanova
Copy link
Member Author

The CI error is unrelated:

@@ -307,7 +307,9 @@ def _prepare_completion_kwargs(

# Handle specific parameters
if stop_sequences is not None:
completion_kwargs["stop"] = stop_sequences
# Not supported with reasoning models openai/o3 and openai/o4-mini
if self.model_id.split("/")[-1] not in ["o3", "o4-mini"]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked the API, indeed these models don't seem to have any argument for stop sequences, really strange IMO not to propose this.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah... thanks guys!

Copy link
Contributor

Choose a reason for hiding this comment

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

@albertvillanova @aymeric-roucher

actually I think the fix above is not working if people specify model versions a la o4-mini-2025-04-16

Suggested change
if self.model_id.split("/")[-1] not in ["o3", "o4-mini"]:
# Handle specific parameters
if stop_sequences is not None:
# Not supported with reasoning models openai/o3 and openai/o4-mini
if ("o3" in self.model_id.split("/")[-1] and "o3-mini" not in self.model_id.split("/")[-1]) or "o4-mini" in self.model_id.split("/")[-1]:
completion_kwargs.pop("stop", None)
else:
completion_kwargs["stop"] = stop_sequences

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. For reference: https://platform.openai.com/docs/api-reference/chat/create#chat-create-stop

stop: string / array / null, Optional, Defaults to null

Not supported with latest reasoning models o3 and o4-mini.

Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.

Copy link
Collaborator

@aymeric-roucher aymeric-roucher left a comment

Choose a reason for hiding this comment

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

Thank you!

@@ -307,7 +307,9 @@ def _prepare_completion_kwargs(

# Handle specific parameters
if stop_sequences is not None:
completion_kwargs["stop"] = stop_sequences
# Not supported with reasoning models openai/o3 and openai/o4-mini
if self.model_id.split("/")[-1] not in ["o3", "o4-mini"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

@albertvillanova @aymeric-roucher

actually I think the fix above is not working if people specify model versions a la o4-mini-2025-04-16

Suggested change
if self.model_id.split("/")[-1] not in ["o3", "o4-mini"]:
# Handle specific parameters
if stop_sequences is not None:
# Not supported with reasoning models openai/o3 and openai/o4-mini
if ("o3" in self.model_id.split("/")[-1] and "o3-mini" not in self.model_id.split("/")[-1]) or "o4-mini" in self.model_id.split("/")[-1]:
completion_kwargs.pop("stop", None)
else:
completion_kwargs["stop"] = stop_sequences

@albertvillanova
Copy link
Member Author

Good catch, @benediktstroebl! We should handle model snapshots (versions) as well.

@albertvillanova albertvillanova merged commit 3f6b7da into huggingface:main Apr 18, 2025
3 checks passed
@albertvillanova albertvillanova deleted the fix-1210 branch April 18, 2025 07:45
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.

[BUG] o4-mini and o3 don't support stop_sequences parameter
3 participants