Add HF Space config frontmatter to README
Browse files- README.md +60 -8
- run_experiment.sh +52 -0
README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# On the Mechanism and Dynamics of Modular Addition
|
| 2 |
|
| 3 |
### Fourier Features, Lottery Ticket, and Grokking
|
|
@@ -36,14 +47,55 @@ python hf_app/app.py
|
|
| 36 |
|
| 37 |
### Deploy to Hugging Face Spaces
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
> **Tip:** For GPU-accelerated on-demand training, select a GPU runtime in your Space settings.
|
| 49 |
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Modular Addition Feature Learning
|
| 3 |
+
emoji: 🔢
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "6.5.1"
|
| 8 |
+
app_file: hf_app/app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
# On the Mechanism and Dynamics of Modular Addition
|
| 13 |
|
| 14 |
### Fourier Features, Lottery Ticket, and Grokking
|
|
|
|
| 47 |
|
| 48 |
### Deploy to Hugging Face Spaces
|
| 49 |
|
| 50 |
+
We use the [Hugging Face Python API](https://huggingface.co/docs/huggingface_hub/) to upload to Spaces, since HF now requires [Xet storage](https://huggingface.co/docs/hub/xet) for binary files (PNGs, etc.) which standard `git push` does not handle.
|
| 51 |
+
|
| 52 |
+
**First-time setup:**
|
| 53 |
+
|
| 54 |
+
```bash
|
| 55 |
+
pip install huggingface_hub hf_xet
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
Log in (get a **write** token from https://huggingface.co/settings/tokens):
|
| 59 |
+
|
| 60 |
+
```bash
|
| 61 |
+
huggingface-cli login
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
**Upload to the Space:**
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
from huggingface_hub import HfApi
|
| 68 |
+
api = HfApi()
|
| 69 |
+
api.upload_folder(
|
| 70 |
+
folder_path=".",
|
| 71 |
+
repo_id="y-agent/modular-addition-feature-learning",
|
| 72 |
+
repo_type="space",
|
| 73 |
+
ignore_patterns=[
|
| 74 |
+
"trained_models/*", "saved_models/*", "src/saved_models/*",
|
| 75 |
+
".git/*", ".claude/*", ".DS_Store", "tmp/*",
|
| 76 |
+
"notebooks/*", "figures/*", "__pycache__/*", "src/wandb/*",
|
| 77 |
+
],
|
| 78 |
+
commit_message="Update app",
|
| 79 |
+
)
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Or as a one-liner from the project root:
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
python -c "
|
| 86 |
+
from huggingface_hub import HfApi; HfApi().upload_folder(
|
| 87 |
+
folder_path='.', repo_id='y-agent/modular-addition-feature-learning',
|
| 88 |
+
repo_type='space', ignore_patterns=[
|
| 89 |
+
'trained_models/*','saved_models/*','src/saved_models/*',
|
| 90 |
+
'.git/*','.claude/*','.DS_Store','tmp/*',
|
| 91 |
+
'notebooks/*','figures/*','__pycache__/*','src/wandb/*'],
|
| 92 |
+
commit_message='Update app')
|
| 93 |
+
"
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
**What gets uploaded:** Only the files the app needs — `hf_app/`, `precompute/`, `precomputed_results/`, `src/`, `requirements.txt`, `README.md`. Model checkpoints, notebooks, and figures are excluded.
|
| 97 |
+
|
| 98 |
+
**On-demand training:** Users can generate results for new $p$ values directly from the app's "Generate" button. Streaming logs show real-time training progress. New results are auto-committed back to the Space repo so they persist across restarts.
|
| 99 |
|
| 100 |
> **Tip:** For GPU-accelerated on-demand training, select a GPU runtime in your Space settings.
|
| 101 |
|
run_experiment.sh
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
#SBATCH --job-name=tk_module_addition_feature # Job name
|
| 4 |
+
#SBATCH --partition=gpu
|
| 5 |
+
#SBATCH --gres=gpu:h100:1
|
| 6 |
+
#SBATCH --qos=qos_zhuoran_yang
|
| 7 |
+
#SBATCH --ntasks=1
|
| 8 |
+
#SBATCH --cpus-per-task=16
|
| 9 |
+
#SBATCH --time=48:00:00
|
| 10 |
+
#SBATCH --output=slurm_output/%j.out
|
| 11 |
+
#SBATCH --error=slurm_output/%j.err
|
| 12 |
+
#SBATCH --requeue
|
| 13 |
+
|
| 14 |
+
# Set working directory explicitly
|
| 15 |
+
WORK_DIR=/home/jh3439/modular-addition-feature-learning
|
| 16 |
+
|
| 17 |
+
echo '-------------------------------'
|
| 18 |
+
cd ${WORK_DIR}
|
| 19 |
+
echo "Working directory: $(pwd)"
|
| 20 |
+
echo Running on host $(hostname)
|
| 21 |
+
echo Time is $(date)
|
| 22 |
+
echo '-------------------------------'
|
| 23 |
+
echo -e '\n\n'
|
| 24 |
+
|
| 25 |
+
export PROCS=${SLURM_CPUS_ON_NODE}
|
| 26 |
+
|
| 27 |
+
module load CUDA
|
| 28 |
+
module load cuDNN
|
| 29 |
+
module load miniconda
|
| 30 |
+
|
| 31 |
+
# Initialize conda for bash - try multiple methods
|
| 32 |
+
source $(conda info --base)/etc/profile.d/conda.sh
|
| 33 |
+
conda activate llm_base
|
| 34 |
+
|
| 35 |
+
echo "Python path: $(which python)"
|
| 36 |
+
echo "Python version: $(python --version)"
|
| 37 |
+
echo "Conda environment: $CONDA_DEFAULT_ENV"
|
| 38 |
+
|
| 39 |
+
echo "Starting experiments..."
|
| 40 |
+
echo "============================================================="
|
| 41 |
+
|
| 42 |
+
cd src
|
| 43 |
+
|
| 44 |
+
# Use explicit Python path from llm_base environment
|
| 45 |
+
/gpfs/radev/home/jh3439/.conda/envs/llm_base/bin/python module_nn.py --init_type random --act_type ReLU --optimizer AdamW --init_scale 0.1
|
| 46 |
+
#python module_nn.py --init_type random --act_type ReLU --optimizer SGD --lr 0.1 --init_scale 0.01
|
| 47 |
+
#python module_nn.py --init_type single-freq --act_type Quad --optimizer SGD --lr 0.1 --init_scale 0.02
|
| 48 |
+
#python module_nn.py --init_type single-freq --act_type ReLU --optimizer SGD --lr 0.01 --init_scale 0.002
|
| 49 |
+
#python module_nn.py --init_type random --act_type Quad --optimizer SGD --lr 0.1 --init_scale 0.1
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
#python module_nn.py --init_type random --act_type ReLU --optimizer AdamW --init_scale 0.1 --frac_train 0.75 --weight_decay 2 --lr 1e-4 --num_epochs 50000 --d_mlp 128
|