Skip to content

Fix code example in MLFlow section of deployment docs #8229

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 3 commits into from
May 20, 2025

Conversation

jmho
Copy link
Contributor

@jmho jmho commented May 16, 2025

The current example code in the MLFlow section of the deployment doc:

import dspy
import mlflow

mlflow.set_tracking_uri("http://127.0.0.1:5000/")
mlflow.set_experiment("deploy_dspy_program")

lm = dspy.LM("openai/gpt-4o-mini")
dspy.settings.configure(lm=lm)
dspy_program = dspy.ChainOfThought("question -> answer")

with mlflow.start_run():
    mlflow.dspy.log_model(
        dspy_program,
        "dspy_program",
        input_example={"messages": [{"role": "user", "content": "What is LLM agent?"}]},
        task="llm/v1/chat",
    )

Does not work given dspy>=2.6.23 and mlflow>=2.22.0. This has been referenced in both #8134 and mlflow/mlflow#15546 where the resolution in the latter was that MLFlow expects custom modules for mlflow.dspy.log_model(...) and not the primitive modules which is currently in the example.

This PR changes the MLFlow example in the deploy docs to match the working MLFlow docstring example found here for the mlflow.dspy.log_model(...) function.

Copy link
Collaborator

@chenmoneygithub chenmoneygithub left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I was able to deploy with the existing code 3 days ago. May I have your exact DSPy and MLflow version?

@jmho
Copy link
Contributor Author

jmho commented May 16, 2025

Hey @chenmoneygithub thanks for the help!

I created a reproduction repo here that has all of my deps, the code I ran in script, and the same code in notebook form. For reference I am, running dspy==2.6.23 and mlflow==2.22.0 and python=3.11.

I run mlflow ui in the activated venv and then run either the jupyter notebook cell or the script using uv run main.py and get:

TypeError('ChainOfThought.forward() takes 1 positional argument but 2 were given')Traceback (most recent call last):
  File "/Users/jmho/Desktop/Personal-Documents/projects/dspy-reproduction-repo/.venv/lib/python3.11/site-packages/mlflow/utils/_capture_modules.py", line 166, in load_model_and_predict
    model.predict(input_example, params=params)
  File "/Users/jmho/Desktop/Personal-Documents/projects/dspy-reproduction-repo/.venv/lib/python3.11/site-packages/mlflow/dspy/wrapper.py", line 89, in predict
    outputs = self.model(converted_inputs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jmho/Desktop/Personal-Documents/projects/dspy-reproduction-repo/.venv/lib/python3.11/site-packages/dspy/utils/callback.py", line 326, in sync_wrapper
    return fn(instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jmho/Desktop/Personal-Documents/projects/dspy-reproduction-repo/.venv/lib/python3.11/site-packages/dspy/primitives/program.py", line 32, in __call__
    return self.forward(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ChainOfThought.forward() takes 1 positional argument but 2 were given

Copy link
Collaborator

@chenmoneygithub chenmoneygithub left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!

@chenmoneygithub chenmoneygithub merged commit 195ae05 into stanfordnlp:main May 20, 2025
5 checks passed
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