|
1 | 1 | import logging |
2 | 2 | import random |
3 | | -import sys |
4 | | -import textwrap |
5 | | -import time |
6 | 3 | from collections import defaultdict |
7 | 4 | from typing import TYPE_CHECKING, Any, Callable, Literal |
8 | 5 |
|
@@ -112,7 +109,7 @@ def compile( |
112 | 109 | view_data_batch_size: int = 10, |
113 | 110 | tip_aware_proposer: bool = True, |
114 | 111 | fewshot_aware_proposer: bool = True, |
115 | | - requires_permission_to_run: bool = True, |
| 112 | + requires_permission_to_run: bool = True, # deprecated |
116 | 113 | provide_traceback: bool | None = None, |
117 | 114 | ) -> Any: |
118 | 115 | effective_max_errors = ( |
@@ -162,20 +159,6 @@ def compile( |
162 | 159 | if minibatch and minibatch_size > len(valset): |
163 | 160 | raise ValueError(f"Minibatch size cannot exceed the size of the valset. Valset size: {len(valset)}.") |
164 | 161 |
|
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 | | - |
179 | 162 | # Initialize program and evaluator |
180 | 163 | program = student.deepcopy() |
181 | 164 | evaluate = Evaluate( |
@@ -336,80 +319,6 @@ def _estimate_lm_calls( |
336 | 319 |
|
337 | 320 | return prompt_model_line, task_model_line |
338 | 321 |
|
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 | | - |
413 | 322 | def _bootstrap_fewshot_examples(self, program: Any, trainset: list, seed: int, teacher: Any) -> list | None: |
414 | 323 | logger.info("\n==> STEP 1: BOOTSTRAP FEWSHOT EXAMPLES <==") |
415 | 324 | if self.max_bootstrapped_demos > 0: |
|
0 commit comments