Skip to content

Implement CoT no-op for reasoning models #8375

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

FireMasterK
Copy link

  • Add an optional parameter to allow specifying whether a model is a reasoning model or not. If not specified, we to determine it using litellm.supports_reasoning.
  • I had to upgrade to upgrade the LiteLLM library to have access to the function, as it wasn't present in the version used earlier.

Additional context: https://x.com/DSPyOSS/status/1931886536221724848

@okhat
Copy link
Collaborator

okhat commented Jun 14, 2025

This is AMAZING. Thank you @FireMasterK !!

I think we'll need to think (no pun intended) about reasoning models like Qwen3 that expose their reasoning in the string... What does LiteLLM do for that. I guess it says False?

Also I guess we should still return a reasoning field, but set it to something that indicates that the reasoning is not available.

@FireMasterK FireMasterK force-pushed the reasoning-models-cot branch from c8b1c4e to b4e570b Compare June 15, 2025 03:09
@FireMasterK
Copy link
Author

I think we'll need to think (no pun intended) about reasoning models like Qwen3 that expose their reasoning in the string... What does LiteLLM do for that. I guess it says False?

I don't think they support telling whether a model displays its CoT or not, which is unfortunate.

It also seems like LiteLLM doesn't have enough mappings for reasoning models (eg. Qwen3 models are not there), which means we can't solely rely on LiteLLM telling if a model supports reasoning or not.
Source: https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json

Also I guess we should still return a reasoning field, but set it to something that indicates that the reasoning is not available.

Yes, but some model providers providers summarize the CoT, what should we do about these? I have added the parsing of reasoning_content from non-streaming responses. I'm not sure what should be done for reasoning content. Should I create a new class like dspy.streaming.ReasoningStreamListener?

@FireMasterK FireMasterK force-pushed the reasoning-models-cot branch from b4e570b to 2181050 Compare June 15, 2025 03:17
@@ -27,15 +28,42 @@ def __init__(
"""
super().__init__()
signature = ensure_signature(signature)
self.predict_reasoning = dspy.Predict(signature, **config)
Copy link
Author

Choose a reason for hiding this comment

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

Adding this field causes a few tests to fail, any idea on how I could fix these:

FAILED tests/teleprompt/test_copro_optimizer.py::test_signature_optimizer_optimization_process - dspy.utils.exceptions.AdapterParseError: LM response cannot be serialized to a JSON object.
FAILED tests/teleprompt/test_copro_optimizer.py::test_signature_optimizer_statistics_tracking - dspy.utils.exceptions.AdapterParseError: LM response cannot be serialized to a JSON object.
FAILED tests/teleprompt/test_copro_optimizer.py::test_optimization_and_output_verification - dspy.utils.exceptions.AdapterParseError: LM response cannot be serialized to a JSON object.
FAILED tests/teleprompt/test_copro_optimizer.py::test_statistics_tracking_during_optimization - dspy.utils.exceptions.AdapterParseError: LM response cannot be serialized to a JSON object.

@FireMasterK FireMasterK force-pushed the reasoning-models-cot branch from 2181050 to a6fd573 Compare June 18, 2025 09:57
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.

2 participants