BoltzmannEntropy
commited on
Commit
•
a1d1593
1
Parent(s):
eda5971
LT
Browse files- Q_app_llm_pairs_gen.py +1 -1
- Q_quantum_utils.py +27 -11
- quantum_problems.duckdb.wal +0 -0
Q_app_llm_pairs_gen.py
CHANGED
@@ -138,7 +138,7 @@ with gr.Blocks() as app:
|
|
138 |
|
139 |
solutions_model_selector = gr.Dropdown(
|
140 |
choices=solutions_model_options,
|
141 |
-
value=solutions_model_options[
|
142 |
label="Select Solution Model"
|
143 |
)
|
144 |
|
|
|
138 |
|
139 |
solutions_model_selector = gr.Dropdown(
|
140 |
choices=solutions_model_options,
|
141 |
+
value=solutions_model_options[1],
|
142 |
label="Select Solution Model"
|
143 |
)
|
144 |
|
Q_quantum_utils.py
CHANGED
@@ -426,7 +426,7 @@ def generate_dynamic_prompt(selected_domains):
|
|
426 |
raise ValueError("No domains selected. Please select at least one domain.")
|
427 |
# Select a single domain randomly
|
428 |
selected_domain = random.choice(selected_domains)
|
429 |
-
|
430 |
# Retrieve the description and template
|
431 |
domain_details = quantum_problem_domains[selected_domain]
|
432 |
domain_description = domain_details["description"]
|
@@ -485,30 +485,37 @@ def generate_problem(pair_id, model_name, selected_domains):
|
|
485 |
conn.close()
|
486 |
|
487 |
# print(response)
|
488 |
-
return response
|
489 |
except Exception as e:
|
490 |
print(f"Error generating problem {pair_id}: {e}")
|
491 |
-
return None
|
492 |
|
493 |
-
# Generate multiple problems with progress
|
494 |
def generate_multiple_problems(num_pairs, selected_domains):
|
495 |
if not selected_domains:
|
496 |
return "Please select at least one domain type."
|
497 |
-
|
498 |
conn = duckdb.connect(database=DB_FILE)
|
499 |
current_count = conn.execute("SELECT COUNT(*) FROM problems").fetchone()[0]
|
500 |
conn.close()
|
501 |
|
|
|
|
|
|
|
|
|
|
|
|
|
502 |
responses = []
|
503 |
-
with tqdm(total=num_pairs, desc=
|
504 |
for i in range(num_pairs):
|
505 |
-
response = generate_problem(current_count + i + 1, selected_model, selected_domains)
|
506 |
if response:
|
507 |
responses.append(response)
|
|
|
508 |
pbar.update(1)
|
509 |
-
|
510 |
return "\n\n".join(responses)
|
511 |
|
|
|
512 |
def generate_solutions_pqt(solution_model_name):
|
513 |
df = load_parquet()
|
514 |
unsolved_problems = df[df["solution"].isna()]
|
@@ -548,7 +555,6 @@ def generate_solutions_pqt(solution_model_name):
|
|
548 |
pbar.update(1)
|
549 |
return "Solutions generated successfully!"
|
550 |
|
551 |
-
# Function to generate solutions for unsolved problems
|
552 |
def generate_solutions(solution_model_name):
|
553 |
conn = duckdb.connect(database=DB_FILE)
|
554 |
problems = conn.execute("SELECT uuid, problem FROM problems WHERE solution IS NULL").fetchall()
|
@@ -556,7 +562,12 @@ def generate_solutions(solution_model_name):
|
|
556 |
if not problems:
|
557 |
return "No unsolved problems found in the database."
|
558 |
|
559 |
-
|
|
|
|
|
|
|
|
|
|
|
560 |
for problem_id, problem_text in problems:
|
561 |
try:
|
562 |
solution_prompt = RESPONSE_SOLUTION_LLM_USR_PROMPT.format(problem=problem_text)
|
@@ -581,17 +592,22 @@ def generate_solutions(solution_model_name):
|
|
581 |
]
|
582 |
solution = solution_tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
583 |
|
|
|
584 |
conn.execute("""
|
585 |
UPDATE problems
|
586 |
SET solution = ?, solution_model_name = ?
|
587 |
WHERE uuid = ?
|
588 |
-
""", (solution,
|
|
|
|
|
|
|
589 |
except Exception as e:
|
590 |
print(f"Error generating solution for problem {problem_id}: {e}")
|
591 |
pbar.update(1)
|
592 |
conn.close()
|
593 |
return "Solutions generated successfully!"
|
594 |
|
|
|
595 |
# Load problems from DuckDB
|
596 |
def load_problems_from_duckdb():
|
597 |
"""Load all problems and solutions from the DuckDB database."""
|
|
|
426 |
raise ValueError("No domains selected. Please select at least one domain.")
|
427 |
# Select a single domain randomly
|
428 |
selected_domain = random.choice(selected_domains)
|
429 |
+
|
430 |
# Retrieve the description and template
|
431 |
domain_details = quantum_problem_domains[selected_domain]
|
432 |
domain_description = domain_details["description"]
|
|
|
485 |
conn.close()
|
486 |
|
487 |
# print(response)
|
488 |
+
return response, selected_domain
|
489 |
except Exception as e:
|
490 |
print(f"Error generating problem {pair_id}: {e}")
|
491 |
+
return None, None
|
492 |
|
|
|
493 |
def generate_multiple_problems(num_pairs, selected_domains):
|
494 |
if not selected_domains:
|
495 |
return "Please select at least one domain type."
|
496 |
+
|
497 |
conn = duckdb.connect(database=DB_FILE)
|
498 |
current_count = conn.execute("SELECT COUNT(*) FROM problems").fetchone()[0]
|
499 |
conn.close()
|
500 |
|
501 |
+
# Prepare a descriptive header for TQDM
|
502 |
+
model_name = selected_model.split("/")[-1]
|
503 |
+
domain_list = ", ".join(selected_domains[:3]) # Include up to 3 domains for brevity
|
504 |
+
|
505 |
+
tqdm_desc = f"Generating Instructions - Model: {model_name} | Total: {num_pairs}"
|
506 |
+
|
507 |
responses = []
|
508 |
+
with tqdm(total=num_pairs, desc=tqdm_desc, unit="problem") as pbar:
|
509 |
for i in range(num_pairs):
|
510 |
+
response, selected_domain = generate_problem(current_count + i + 1, selected_model, selected_domains)
|
511 |
if response:
|
512 |
responses.append(response)
|
513 |
+
pbar.set_postfix_str(f"Last Domain: {selected_domain}") # Updates progress bar with last domain
|
514 |
pbar.update(1)
|
515 |
+
|
516 |
return "\n\n".join(responses)
|
517 |
|
518 |
+
|
519 |
def generate_solutions_pqt(solution_model_name):
|
520 |
df = load_parquet()
|
521 |
unsolved_problems = df[df["solution"].isna()]
|
|
|
555 |
pbar.update(1)
|
556 |
return "Solutions generated successfully!"
|
557 |
|
|
|
558 |
def generate_solutions(solution_model_name):
|
559 |
conn = duckdb.connect(database=DB_FILE)
|
560 |
problems = conn.execute("SELECT uuid, problem FROM problems WHERE solution IS NULL").fetchall()
|
|
|
562 |
if not problems:
|
563 |
return "No unsolved problems found in the database."
|
564 |
|
565 |
+
# Prepare a descriptive header for TQDM
|
566 |
+
model_name = solution_model_name.split("/")[-1]
|
567 |
+
total_problems = len(problems)
|
568 |
+
tqdm_desc = f"Solution Model: {model_name} | Total Problems: {total_problems}"
|
569 |
+
|
570 |
+
with tqdm(total=total_problems, desc=tqdm_desc, unit="solution") as pbar:
|
571 |
for problem_id, problem_text in problems:
|
572 |
try:
|
573 |
solution_prompt = RESPONSE_SOLUTION_LLM_USR_PROMPT.format(problem=problem_text)
|
|
|
592 |
]
|
593 |
solution = solution_tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
594 |
|
595 |
+
# Update the database with the generated solution
|
596 |
conn.execute("""
|
597 |
UPDATE problems
|
598 |
SET solution = ?, solution_model_name = ?
|
599 |
WHERE uuid = ?
|
600 |
+
""", (solution, model_name, problem_id))
|
601 |
+
|
602 |
+
# Update progress bar with the last processed problem ID
|
603 |
+
pbar.set_postfix_str(f"Last Problem UUID: {problem_id}")
|
604 |
except Exception as e:
|
605 |
print(f"Error generating solution for problem {problem_id}: {e}")
|
606 |
pbar.update(1)
|
607 |
conn.close()
|
608 |
return "Solutions generated successfully!"
|
609 |
|
610 |
+
|
611 |
# Load problems from DuckDB
|
612 |
def load_problems_from_duckdb():
|
613 |
"""Load all problems and solutions from the DuckDB database."""
|
quantum_problems.duckdb.wal
DELETED
Binary file (4.42 kB)
|
|