Skip to content

Commit 5b49772

Browse files
add caveat callout
1 parent 1977785 commit 5b49772

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

docs/docs/tutorials/deployment/index.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,14 @@ Let's spin up the MLflow tracking server, where we will store our DSPy program.
146146
```
147147

148148
Then we can define the DSPy program and log it to the MLflow server. "log" is an overloaded term in MLflow, basically it means
149-
we store the program information along with environment requirements in the MLflow server. This is done via the `mlflow.dspy.log_model()` function which takes a custom `dspy.Module` object along with a model signature that defines the expected schema for model inputs and outputs.
149+
we store the program information along with environment requirements in the MLflow server. This is done via the `mlflow.dspy.log_model()`
150+
function, please see the code below:
150151

151-
See the code below:
152+
> [!NOTE]
153+
> As of MLflow 2.22.0, there is a caveat that you must wrap your DSPy program in a custom DSPy Module class when deploying with MLflow.
154+
> This is because MLflow requires positional arguments while DSPy pre-built modules disallow positional arguments, e.g., `dspy.Predict`
155+
> or `dspy.ChainOfThought`. To work around this, create a wrapper class that inherits from `dspy.Module` and implement your program's
156+
> logic in the `forward()` method, as shown in the example below.
152157
153158
```python
154159
import dspy
@@ -160,15 +165,15 @@ mlflow.set_experiment("deploy_dspy_program")
160165
lm = dspy.LM("openai/gpt-4o-mini")
161166
dspy.settings.configure(lm=lm)
162167

163-
class CoT(dspy.Module):
168+
class MyProgram(dspy.Module):
164169
def __init__(self):
165170
super().__init__()
166-
self.prog = dspy.ChainOfThought("question -> answer")
171+
self.cot = dspy.ChainOfThought("question -> answer")
167172

168173
def forward(self, question):
169-
return self.prog(question=question)
174+
return self.cot(question=question)
170175

171-
dspy_program = CoT()
176+
dspy_program = MyProgram()
172177

173178
with mlflow.start_run():
174179
mlflow.dspy.log_model(

0 commit comments

Comments
 (0)