Ray's blog

On Where We Are

AGUI- a guide to how to install google’s Alphageometry and experiment with UI

(Image from Google)

First, massive thanks to each and every individual that contributed to the content linked below:

https://github.com/google-deepmind/alphageometry

https://github.com/tpgh24/ag4masses

https://github.com/pyenv/pyenv

https://github.com/docker

Alright, now lets get into how you actually set up Alphageometry, I will be going through two method, both of which has (unofficial) UI support.

Method 1: Native Install on Linux

I just want to first say that even though google did not say much about it, their code has proven to be Linux-exclusive, thanks to their very specific pip requirements. I tested this on Windows WSL running Ubuntu 23.2, but theoretically this should work on Ubuntu 19.4+.

they already have a run.sh file in their GitHub repo, but it never works as intended, so I shall go over how to install this state-of-the-art (according to google) geometry solver here.

IMPORTANT NOTE: execute all the commands listed below with the root user, type sudo su to log in as root if you are a sudo user.

  1. Clone their GitHub repo (and correct a minor mistake)
apt update;
apt install git -y;
git clone https://github.com/google-deepmind/alphageometry.git;
cd alphageometry;
sed -i '30s/matplotlib.use(.*)/matplotlib.use("Agg")/' numerical.py

2. Install python 3.10.9 or 3.10.8

If you happen to have one of these python versions properly installed, you can skip this step. If not, you should use a tool like pyenv or conda to install one of these versions because it is important for the dependencies. I shall be showing how to use pyenv to do it because it is easier to demonstrate

Install it with (assuming you use bash as your shell)

apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev -y
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc
pyenv install 3.10.8
pyenv local 3.10.8

OR, execute these commands in a one-liner fashion

apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev -y;git clone https://github.com/pyenv/pyenv.git ~/.pyenv;echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc;echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc;echo 'eval "$(pyenv init -)"' >> ~/.bashrc;source ~/.bashrc;pyenv install 3.10.8;pyenv local 3.10.8;

3. Build the virtual environment (this is mandatory, not optional) and install pip dependencies

apt install python3-tk -y
python -m venv .
source ./bin/activate
pip install --require-hashes --use-deprecated=legacy-resolver -r requirements.txt

# what's below installs meliad
MELIAD_PATH=meliad_lib/meliad
mkdir -p $MELIAD_PATH
git clone https://github.com/google-research/meliad $MELIAD_PATH
export PYTHONPATH=$PYTHONPATH:$MELIAD_PATH

Again: one-liner:

apt install python3-tk -y;python -m venv .;source ./bin/activate; pip install --require-hashes --use-deprecated=legacy-resolver -r requirements.txt ;MELIAD_PATH=meliad_lib/meliad;mkdir -p $MELIAD_PATH;git clone https://github.com/google-research/meliad  $MELIAD_PATH;export PYTHONPATH=$PYTHONPATH:$MELIAD_PATH;

4. Download the checkpoint

bash download.sh

if for whatever reason this does not work for you, please navigate to https://huggingface.co/Wauplin/alphageometry/tree/main

and download checkpoint_10999999, geometry.757.model, and geometry.757.vocab. Then, create a folder at the root of your alphageometry folder named ag_ckpt_vocab. Place the three downloaded files in the ag_ckpt_vocab folder.

5. Write a run script

I strongly suggest creating a bash file for running this application for ease of future usage.

nano solve.sh
source ./bin/activate
DATA=ag_ckpt_vocab
MELIAD_PATH=meliad_lib/meliad
export PYTHONPATH=$PYTHONPATH:$MELIAD_PATH

DDAR_ARGS=(
  --defs_file=$(pwd)/defs.txt \
  --rules_file=$(pwd)/rules.txt \
);

BATCH_SIZE=2
BEAM_SIZE=2
DEPTH=2

SEARCH_ARGS=(
  --beam_size=$BEAM_SIZE
  --search_depth=$DEPTH
)

LM_ARGS=(
  --ckpt_path=$DATA \
  --vocab_path=$DATA/geometry.757.model \
  --gin_search_paths=$MELIAD_PATH/transformer/configs \
  --gin_file=base_htrans.gin \
  --gin_file=size/medium_150M.gin \
  --gin_file=options/positions_t5.gin \
  --gin_file=options/lr_cosine_decay.gin \
  --gin_file=options/seq_1024_nocache.gin \
  --gin_file=geometry_150M_generate.gin \
  --gin_param=DecoderOnlyLanguageModelGenerate.output_token_losses=True \
  --gin_param=TransformerTaskConfig.batch_size=$BATCH_SIZE \
  --gin_param=TransformerTaskConfig.sequence_length=128 \
  --gin_param=Trainer.restore_state_variables=False
);

echo $PYTHONPATH

python -m alphageometry \
--alsologtostderr \
--problems_file=$(pwd)/$1 \
--problem_name=$2 \
--mode=alphageometry \
"${DDAR_ARGS[@]}" \
"${SEARCH_ARGS[@]}" \
"${LM_ARGS[@]}"

Hit cltr+X, then Y, then Enter to save.

6. Run alphageometry

With the newly created script, we can do

bash solve.sh <your problem file> <your problem name>

Example:

bash solve.sh imo_ag_30.txt translated_imo_2002_p2b

Enjoy!

  • UI deployment (OPTIONAL)

Method 2: Dockerizing alphageometry

this is a easier method or deployment, but it will surely be less efficient because the nature of docker virtualization, but it is much easier to install, and it works on anything that runs docker.

  1. Install docker.

For windows or mac:

install their desktop software

https://www.docker.com/products/docker-desktop

For Ubuntu :

apt update; apt install docker.io -y;

2, One command setup:

docker run -d  --name AGUI -p 5000:5000 rayrayhi/alphageometry_ui:v1.0   bash -c "cd /AGUI ; /root/.pyenv/shims/python  /AGUI/process_post.py"

3, interact through the UI at

http://localhost:5000/

and ………… yes, I am the person who came up with the stupid idea to write the UI and do the dockerization, blame me if my UI crashes 🫠🫠🫠.

anyway, hope you enjoy this, playing with alphageometry, the UI and docker image is still not fully complete. I might update this post if I make update to them, feel free to send me feedback regarding anything within my capability to fix. I can be reached through GitHub issues, or at [email protected]

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *