Skip to content

Commit

Permalink
feat: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehwan committed Jun 21, 2024
1 parent 41b4b67 commit 455f327
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 56 deletions.
1 change: 0 additions & 1 deletion code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

try:
from sympy import *

Expand Down
13 changes: 0 additions & 13 deletions configs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ TOTAL_TOKENS: 2048 # if PRIVATE else 512

DEEP: True

code: """Below is a math problem you are to solve (positive numerical answer):
\"{}\"
To accomplish this, first determine a sympy-based approach for solving the problem by listing each step to take and what functions need to be called in each step. Be clear so even an idiot can follow your instructions, and remember, your final answer should be positive integer, not an algebraic expression!
Write the entire script covering all the steps (use comments and document it well) and print the result. After solving the problem, output the final numerical answer within \\boxed{}.
Approach:"""


cot: """Below is a math problem you are to solve (positive numerical answer!):
\"{}\"Analyze this problem and think step by step to come to a solution with programs. After solving the problem, output the final numerical answer within \\boxed{}.\n\n"""

tool_instruction: '\n\nPlease integrate natural language reasoning with programs to solve the above problem, and put your final numerical answer within \\boxed{}.\nNote that the intermediary calculations may be real numbers, but the final numercal answer would always be an integer.'


temperature: 0.9
top_p: 1.0
Expand Down
2 changes: 2 additions & 0 deletions log.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Loading the config file...
Transformers Version: 4.39.3
torch.bfloat16
85 changes: 44 additions & 41 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import math
import random

from collections import defaultdict
from collections import Counter

Expand Down Expand Up @@ -46,50 +47,49 @@ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor):
return False

if __name__ == "__main__":
import aimo
env = aimo.make_env()
iter_test = env.iter_test()
# # Parse arguments
# arg_parser = argparse.ArgumentParser()
# arg_parser.add_argument("-c", "--config", default="./configs/config.yaml",
# help="the config file to be used to run the experiment")
# arg_parser.add_argument("--verbose", action='store_true', help="Log also to stdout")

# args = arg_parser.parse_args()


LOGGER=True

if LOGGER:
log_fn = 'log.txt'
if os.path.exists(log_fn):
os.remove(log_fn)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Create a file handler
file_handler = logging.FileHandler(log_fn)
file_handler.setLevel(logging.INFO)
# Create a stream handler
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)

# Add the handlers to the logger
logger.addHandler(file_handler)
logger.addHandler(stream_handler)

# Parse arguments
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("-c", "--config", default="./configs/config.yaml",
help="the config file to be used to run the experiment")
arg_parser.add_argument("--verbose", action='store_true', help="Log also to stdout")

args = arg_parser.parse_args()

LOGGER=True
log_fn = 'log.txt'
if os.path.exists(log_fn):
os.remove(log_fn)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Create a file handler
file_handler = logging.FileHandler(log_fn)
file_handler.setLevel(logging.INFO)
# Create a stream handler
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)

# Add the handlers to the logger
logger.addHandler(file_handler)
logger.addHandler(stream_handler)


config_fn = './configs/config.yaml'
# check if the config files exists
if not os.path.exists(args.config):
logging.info("Config file does not exist: {}".format(args.config))
if not os.path.exists(config_fn):
logging.info("Config file does not exist: {}".format(config_fn))
raise SystemExit

# Munchify the dict to access entries with both dot notation and ['name']
logging.info(f'Loading the config file...')
config = yaml.load(open(args.config, "r", encoding='utf-8'), yaml.FullLoader, )
config = yaml.load(open(config_fn, "r", encoding='utf-8'), yaml.FullLoader)
config = munchify(config)


import aimo
env = aimo.make_env()
iter_test = env.iter_test()


import transformers
logging.info(f"Transformers Version: {transformers.__version__}")
Expand All @@ -113,18 +113,14 @@ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor):

torch.cuda.empty_cache()
gc.collect()





n_repetitions = config.n_repetitions # Original notebook had 22 but times out :(
TOTAL_TOKENS = config.TOTAL_TOKENS # if PRIVATE else 512

if PRIVATE:
TIME_LIMIT = 31500
else:
TIME_LIMIT = 31500 # ORIGIN 1
TIME_LIMIT = 1 # ORIGIN 1



Expand Down Expand Up @@ -217,13 +213,19 @@ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor):
logging.info(model.dtype, model.hf_device_map)


code = config.code
code = """Below is a math problem you are to solve (positive numerical answer):
\"{}\"
To accomplish this, first determine a sympy-based approach for solving the problem by listing each step to take and what functions need to be called in each step. Be clear so even an idiot can follow your instructions, and remember, your final answer should be positive integer, not an algebraic expression!
Write the entire script covering all the steps (use comments and document it well) and print the result. After solving the problem, output the final numerical answer within \\boxed{}.
Approach:"""

cot = config.cot

cot = """Below is a math problem you are to solve (positive numerical answer!):
\"{}\"Analyze this problem and think step by step to come to a solution with programs. After solving the problem, output the final numerical answer within \\boxed{}.\n\n"""
promplt_options = [code,cot]

tool_instruction = config.tool_instruction
tool_instruction = '\n\nPlease integrate natural language reasoning with programs to solve the above problem, and put your final numerical answer within \\boxed{}.\nNote that the intermediary calculations may be real numbers, but the final numercal answer would always be an integer.'


temperature = config.temperature
Expand All @@ -240,6 +242,7 @@ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor):
question_type_counts = {}
starting_counts = (2,3)


# LEWIS: I had to invert the loop order because the new API forbids repeated calls on the same problem
for i, (test, sample_submission) in tqdm(enumerate(iter_test)):
logging.info(f"Solving problem {i} ...")
Expand Down
2 changes: 1 addition & 1 deletion test.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"row_id", ""id","problem","answer"
"row_id", "id","problem","answer"
1, "229ee8","Let $k, l > 0$ be parameters. The parabola $y = kx^2 - 2kx + l$ intersects the line $y = 4$ at two points $A$ and $B$. These points are distance 6 apart. What is the sum of the squares of the distances from $A$ and $B$ to the origin?",52
2, "246d26","Each of the three-digits numbers $111$ to $999$ is coloured blue or yellow in such a way that the sum of any two (not necessarily different) yellow numbers is equal to a blue number. What is the maximum possible number of yellow numbers there can be?",250
3, "2fc4ad","Let the `sparkle' operation on positive integer $n$ consist of calculating the sum of the digits of $n$ and taking its factorial, e.g. the sparkle of 13 is $4! = 24$. A robot starts with a positive integer on a blackboard, then after each second for the rest of eternity, replaces the number on the board with its sparkle. For some `special' numbers, if they're the first number, then eventually every number that appears will be less than 6. How many such special numbers are there with at most 36 digits?",702
Expand Down

0 comments on commit 455f327

Please sign in to comment.