Skip to content

Commit d44b65f

Browse files
authored
remove requires_permission_to_run (#8552)
1 parent 880d63b commit d44b65f

File tree

8 files changed

+5
-101
lines changed

8 files changed

+5
-101
lines changed

docs/docs/api/optimizers/MIPROv2.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ gsm8k = GSM8K()
4747
optimized_program = teleprompter.compile(
4848
dspy.ChainOfThought("question -> answer"),
4949
trainset=gsm8k.train,
50-
requires_permission_to_run=False,
5150
)
5251

5352
# Save optimize program for future use

docs/docs/cheatsheet.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ optimized_program = teleprompter.compile(
307307
trainset=trainset,
308308
max_bootstrapped_demos=3,
309309
max_labeled_demos=4,
310-
requires_permission_to_run=False,
311310
)
312311

313312
# Save optimize program for future use
@@ -337,7 +336,6 @@ optimized_program = teleprompter.compile(
337336
trainset=trainset,
338337
max_bootstrapped_demos=0,
339338
max_labeled_demos=0,
340-
requires_permission_to_run=False,
341339
)
342340

343341
# Save optimize program for future use

docs/docs/tutorials/entity_extraction/index.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@
567567
" people_extractor,\n",
568568
" trainset=train_set,\n",
569569
" max_bootstrapped_demos=4,\n",
570-
" requires_permission_to_run=False,\n",
571570
" minibatch=False\n",
572571
")"
573572
]

docs/docs/tutorials/games/index.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@
572572
"optimizer = dspy.MIPROv2(metric=metric, auto=\"light\", num_threads=16, prompt_model=gpt4o)\n",
573573
"\n",
574574
"config = dict(max_bootstrapped_demos=1, max_labeled_demos=0, minibatch_size=40)\n",
575-
"optimized_4o = optimizer.compile(agent_4o, trainset=trainset, **config, requires_permission_to_run=False)"
575+
"optimized_4o = optimizer.compile(agent_4o, trainset=trainset, **config)"
576576
]
577577
},
578578
{

docs/docs/tutorials/math/index.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@
414414
"kwargs = dict(num_threads=THREADS, teacher_settings=dict(lm=gpt4o), prompt_model=gpt4o_mini)\n",
415415
"optimizer = dspy.MIPROv2(metric=dataset.metric, auto=\"medium\", **kwargs)\n",
416416
"\n",
417-
"kwargs = dict(requires_permission_to_run=False, max_bootstrapped_demos=4, max_labeled_demos=4)\n",
417+
"kwargs = dict(max_bootstrapped_demos=4, max_labeled_demos=4)\n",
418418
"optimized_module = optimizer.compile(module, trainset=dataset.train, **kwargs)"
419419
]
420420
},

docs/docs/tutorials/multihop_search/index.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@
574574
"models = dict(prompt_model=gpt4o, teacher_settings=dict(lm=gpt4o))\n",
575575
"tp = dspy.MIPROv2(metric=top5_recall, auto=\"medium\", num_threads=16, **models)\n",
576576
"\n",
577-
"kwargs = dict(minibatch_size=40, minibatch_full_eval_steps=4, requires_permission_to_run=False)\n",
577+
"kwargs = dict(minibatch_size=40, minibatch_full_eval_steps=4)\n",
578578
"optimized = tp.compile(Hop(), trainset=trainset, max_bootstrapped_demos=4, max_labeled_demos=4, **kwargs)"
579579
]
580580
},

docs/docs/tutorials/rag/index.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,8 +1143,7 @@
11431143
"tp = dspy.MIPROv2(metric=metric, auto=\"medium\", num_threads=24) # use fewer threads if your rate limit is small\n",
11441144
"\n",
11451145
"optimized_rag = tp.compile(RAG(), trainset=trainset,\n",
1146-
" max_bootstrapped_demos=2, max_labeled_demos=2,\n",
1147-
" requires_permission_to_run=False)"
1146+
" max_bootstrapped_demos=2, max_labeled_demos=2)"
11481147
]
11491148
},
11501149
{

dspy/teleprompt/mipro_optimizer_v2.py

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import logging
22
import random
3-
import sys
4-
import textwrap
5-
import time
63
from collections import defaultdict
74
from typing import TYPE_CHECKING, Any, Callable, Literal
85

@@ -112,7 +109,7 @@ def compile(
112109
view_data_batch_size: int = 10,
113110
tip_aware_proposer: bool = True,
114111
fewshot_aware_proposer: bool = True,
115-
requires_permission_to_run: bool = True,
112+
requires_permission_to_run: bool = True, # deprecated
116113
provide_traceback: bool | None = None,
117114
) -> Any:
118115
effective_max_errors = (
@@ -162,20 +159,6 @@ def compile(
162159
if minibatch and minibatch_size > len(valset):
163160
raise ValueError(f"Minibatch size cannot exceed the size of the valset. Valset size: {len(valset)}.")
164161

165-
# Estimate LM calls and get user confirmation
166-
if requires_permission_to_run:
167-
if not self._get_user_confirmation(
168-
student,
169-
num_trials,
170-
minibatch,
171-
minibatch_size,
172-
minibatch_full_eval_steps,
173-
valset,
174-
program_aware_proposer,
175-
):
176-
logger.info("Compilation aborted by the user.")
177-
return student # Return the original student program
178-
179162
# Initialize program and evaluator
180163
program = student.deepcopy()
181164
evaluate = Evaluate(
@@ -336,80 +319,6 @@ def _estimate_lm_calls(
336319

337320
return prompt_model_line, task_model_line
338321

339-
def _get_user_confirmation(
340-
self,
341-
program: Any,
342-
num_trials: int,
343-
minibatch: bool,
344-
minibatch_size: int,
345-
minibatch_full_eval_steps: int,
346-
valset: list,
347-
program_aware_proposer: bool,
348-
) -> bool:
349-
prompt_model_line, task_model_line = self._estimate_lm_calls(
350-
program,
351-
num_trials,
352-
minibatch,
353-
minibatch_size,
354-
minibatch_full_eval_steps,
355-
valset,
356-
program_aware_proposer,
357-
)
358-
359-
user_message = textwrap.dedent(
360-
f"""\
361-
{YELLOW}{BOLD}Projected Language Model (LM) Calls{ENDC}
362-
363-
Based on the parameters you have set, the maximum number of LM calls is projected as follows:
364-
365-
{prompt_model_line}
366-
{task_model_line}
367-
368-
{YELLOW}{BOLD}Estimated Cost Calculation:{ENDC}
369-
370-
{YELLOW}Total Cost = (Number of calls to task model * (Avg Input Token Length per Call * Task Model Price per Input Token + Avg Output Token Length per Call * Task Model Price per Output Token)
371-
+ (Number of program calls * (Avg Input Token Length per Call * Task Prompt Price per Input Token + Avg Output Token Length per Call * Prompt Model Price per Output Token).{ENDC}
372-
373-
For a preliminary estimate of potential costs, we recommend you perform your own calculations based on the task
374-
and prompt models you intend to use. If the projected costs exceed your budget or expectations, you may consider:
375-
376-
{YELLOW}- Reducing the number of trials (`num_trials`), the size of the valset, or the number of LM calls in your program.{ENDC}
377-
{YELLOW}- Using a cheaper task model to optimize the prompt.{ENDC}
378-
{YELLOW}- Setting `minibatch=True` if you haven't already.{ENDC}\n"""
379-
)
380-
381-
user_confirmation_message = textwrap.dedent(
382-
f"""\
383-
To proceed with the execution of this program, please confirm by typing {BLUE}'y'{ENDC} for yes or {BLUE}'n'{ENDC} for no.
384-
If no input is received within 20 seconds, the program will proceed automatically.
385-
386-
If you would like to bypass this confirmation step in future executions, set the {YELLOW}`requires_permission_to_run`{ENDC} flag to {YELLOW}`False`{ENDC} when calling compile.
387-
388-
{YELLOW}Awaiting your input...{ENDC}
389-
"""
390-
)
391-
392-
print(f"{user_message}\n{user_confirmation_message}\nDo you wish to continue? (y/n): ", end="", flush=True)
393-
394-
# Wait for input with timeout
395-
start_time = time.time()
396-
while time.time() - start_time < 20:
397-
if sys.platform == "win32":
398-
import msvcrt
399-
if msvcrt.kbhit():
400-
user_input = msvcrt.getch().decode("utf-8").strip().lower()
401-
print(user_input) # Echo the input
402-
return user_input == "y"
403-
else:
404-
import select
405-
if select.select([sys.stdin], [], [], 0.1)[0]:
406-
user_input = sys.stdin.readline().strip().lower()
407-
return user_input == "y"
408-
time.sleep(0.1)
409-
410-
print("\nNo input received within 20 seconds. Proceeding with execution...")
411-
return True
412-
413322
def _bootstrap_fewshot_examples(self, program: Any, trainset: list, seed: int, teacher: Any) -> list | None:
414323
logger.info("\n==> STEP 1: BOOTSTRAP FEWSHOT EXAMPLES <==")
415324
if self.max_bootstrapped_demos > 0:

0 commit comments

Comments
 (0)