Skip to content

Commit 26bfd24

Browse files
authored
Fix rollout_id warning for default LM temperature (#9316)
1 parent 8d93124 commit 26bfd24

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎dspy/clients/lm.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(
111111
self._warn_zero_temp_rollout(self.kwargs.get("temperature"), self.kwargs.get("rollout_id"))
112112

113113
def _warn_zero_temp_rollout(self, temperature: float | None, rollout_id):
114-
if not self._warned_zero_temp_rollout and rollout_id is not None and (temperature is None or temperature == 0):
114+
if not self._warned_zero_temp_rollout and rollout_id is not None and temperature == 0:
115115
warnings.warn(
116116
"rollout_id has no effect when temperature=0; set temperature>0 to bypass the cache.",
117117
stacklevel=3,

‎tests/clients/test_lm.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def fake_completion(*, cache, num_retries, retry_strategy, **request):
190190

191191
monkeypatch.setattr(litellm, "completion", fake_completion)
192192

193-
lm = dspy.LM(model="openai/dspy-test-model", model_type="chat")
193+
lm = dspy.LM(model="openai/dspy-test-model", model_type="chat", temperature=0)
194194
with pytest.warns(UserWarning, match="rollout_id has no effect"):
195195
lm("Query", rollout_id=1)
196196
with warnings.catch_warnings(record=True) as record:
@@ -199,6 +199,23 @@ def fake_completion(*, cache, num_retries, retry_strategy, **request):
199199
assert len(record) == 0
200200

201201

202+
def test_rollout_id_with_default_temperature_does_not_warn(monkeypatch):
203+
def fake_completion(*, cache, num_retries, retry_strategy, **request):
204+
return ModelResponse(
205+
choices=[Choices(message=Message(role="assistant", content="Hi!"))],
206+
usage={"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2},
207+
model="openai/gpt-5-nano",
208+
)
209+
210+
monkeypatch.setattr(litellm, "completion", fake_completion)
211+
212+
with warnings.catch_warnings(record=True) as record:
213+
warnings.simplefilter("always")
214+
lm = dspy.LM(model="openai/gpt-5-nano", model_type="chat", rollout_id=1)
215+
lm("Query")
216+
assert len(record) == 0
217+
218+
202219
def test_text_lms_can_be_queried(litellm_test_server):
203220
api_base, _ = litellm_test_server
204221
expected_response = ["Hi!"]

0 commit comments

Comments
 (0)