Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Stabilize real LM tests with deterministic temperature (#9218)

Omar Khattab9d579f22d063
diff --git a/tests/primitives/test_base_module.py b/tests/primitives/test_base_module.py
index a8960cfda..fb538f906 100644
--- a/tests/primitives/test_base_module.py
+++ b/tests/primitives/test_base_module.py
@@ -247,7 +247,7 @@ def test_load_with_version_mismatch(tmp_path):
@pytest.mark.llm_call
def test_single_module_call_with_usage_tracker(lm_for_test):
- dspy.configure(lm=dspy.LM(lm_for_test, cache=False), track_usage=True)
+ dspy.configure(lm=dspy.LM(lm_for_test, cache=False, temperature=0.0), track_usage=True)
predict = dspy.ChainOfThought("question -> answer")
output = predict(question="What is the capital of France?")
@@ -259,7 +259,7 @@ def test_single_module_call_with_usage_tracker(lm_for_test):
assert lm_usage[lm_for_test]["total_tokens"] > 0
# Test no usage being tracked when cache is enabled
- dspy.configure(lm=dspy.LM(lm_for_test, cache=True), track_usage=True)
+ dspy.configure(lm=dspy.LM(lm_for_test, cache=True, temperature=0.0), track_usage=True)
for _ in range(2):
output = predict(question="What is the capital of France?")
@@ -268,7 +268,7 @@ def test_single_module_call_with_usage_tracker(lm_for_test):
@pytest.mark.llm_call
def test_multi_module_call_with_usage_tracker(lm_for_test):
- dspy.configure(lm=dspy.LM(lm_for_test, cache=False), track_usage=True)
+ dspy.configure(lm=dspy.LM(lm_for_test, cache=False, temperature=0.0), track_usage=True)
class MyProgram(dspy.Module):
def __init__(self):
diff --git a/tests/utils/test_usage_tracker.py b/tests/utils/test_usage_tracker.py
index f3ae61273..af303ba12 100644
--- a/tests/utils/test_usage_tracker.py
+++ b/tests/utils/test_usage_tracker.py
@@ -138,7 +138,7 @@ def test_track_usage_with_multiple_models():
def test_track_usage_context_manager(lm_for_test):
- lm = dspy.LM(lm_for_test, cache=False)
+ lm = dspy.LM(lm_for_test, cache=False, temperature=0.0)
dspy.configure(lm=lm)
predict = dspy.ChainOfThought("question -> answer")