Skip to content
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

[WIP] feat: add reasoning flag in dspy.LM #7994

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lxdlam
Copy link
Contributor

@lxdlam lxdlam commented Mar 21, 2025

Summary

  • Add a reasoning_model parameter in dspy.LM to indicate if the LM is a reasoning model.
  • Add checks that if the lm is set with reasoning_model == True, we use plain predictor instead of the CoT prompted predictor.

Explanation

This PR addresses how reasoning models, a new category of models capable of effective self-CoT, are changing the ecosystem. Many best practice guides recommend removing CoT prompts to reduce token usage, and even recommend avoiding them in OpenAI's documentation.

Since the ChainOfThought module is a core component of dspy, completely refactoring all clients would cause significant breaking changes. Instead, I've implemented two separate predictors with routing based on the lm type.

This PR should be considered primarily as a proposal. Given how rapidly the ecosystem is evolving, self-CoT models may soon become the standard, potentially making the CoT module obsolete. I recognize that the current solution isn't ideal, but it offers a path forward.

@lxdlam lxdlam changed the title feat: add reasoning flag in dspy.LM [WIP] feat: add reasoning flag in dspy.LM Mar 21, 2025
@lxdlam lxdlam marked this pull request as draft March 24, 2025 11:17
@shiosai
Copy link

shiosai commented Mar 24, 2025

Apparently LiteLLM has already (some) support to detect the reasoning part so it would be probably better if it could just be used?: #7793

@lxdlam
Copy link
Contributor Author

lxdlam commented Mar 25, 2025

Apparently LiteLLM has already (some) support to detect the reasoning part so it would be probably better if it could just be used?: #7793

Good point. We can utilize it but the parameter should be retained since there are native client libraries or sometimes we're not on the track of the latest LiteLLM.

@shiosai
Copy link

shiosai commented Mar 25, 2025

Good point. We can utilize it but the parameter should be retained since there are native client libraries or sometimes we're not on the track of the latest LiteLLM.

True. I guess it might be not possible (in an easy way) for DSPy to know in advance whether a certain model will have reasoning or not. In any case, if the model has a reasoning part it would be good to not throw it away even when using "plain" predictor. Im curious if there's a general design decision by the DSPy maintainers.

@lxdlam
Copy link
Contributor Author

lxdlam commented Mar 26, 2025

Good point. We can utilize it but the parameter should be retained since there are native client libraries or sometimes we're not on the track of the latest LiteLLM.

True. I guess it might be not possible (in an easy way) for DSPy to know in advance whether a certain model will have reasoning or not. In any case, if the model has a reasoning part it would be good to not throw it away even when using "plain" predictor. Im curious if there's a general design decision by the DSPy maintainers.

I think it's not an issue only suffered by DSPy since the CoT part for current reasoning models is all different: in different response fields, in different naming, even obfuscated or omitted.

Given no standard way to process these fields, manually marking the model as a reasoning model seems the most practical solution by now.

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