Skip to content

Commit 4cdfb78

Browse files
committed
initial commit
1 parent d28c5c6 commit 4cdfb78

File tree

9 files changed

+83
-14
lines changed

9 files changed

+83
-14
lines changed

apps/mast/README.md renamed to .meta/mast/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Forge MAST Environment Setup
22

33
A simple setup script to automatically configure your environment for running Forge with MAST jobs.
4+
This only applies to Meta internal users.
45

56
## Quick Start
67

@@ -9,7 +10,7 @@ A simple setup script to automatically configure your environment for running Fo
910
### 1. Run the Setup Script
1011

1112
The `env_setup.sh` script will automatically:
12-
- ✅ Activate the required conda environment (`forge-8448524`)
13+
- ✅ Activate and configure the required conda environment
1314
- ✅ Clone/update the Forge repository
1415
- ✅ Install Forge package dependencies
1516
- ✅ Mount the required oilfs workspace to `/mnt/wsfuse`
@@ -20,14 +21,14 @@ The `env_setup.sh` script will automatically:
2021
chmod +x env_setup.sh
2122

2223
# Run the setup
23-
./apps/mast/env_setup.sh
24+
./.meta/mast/env_setup.sh
2425

2526
```
2627

2728
### 2. Submit MAST job
2829

2930
```
30-
pip install --force-reinstall --no-deps . && python -m apps.mast.main --config apps/mast/qwen3_1_7b_mast.yaml
31+
pip install --force-reinstall --no-deps . && python -m .meta.mast.main --config .meta/mast/qwen3_1_7b_mast.yaml
3132
```
3233

3334
⚠️ Important Note: `pip install --force-reinstall --no-deps .` is required every time you make a change to the local codebase. This ensures your latest changes are installed before job submission.
File renamed without changes.

apps/mast/env_setup.sh renamed to .meta/mast/env_setup.sh

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# setup_forge_env.sh - Setup conda environment and install forge with mounting
1010
set -e # Exit on any error
1111

12+
# Configuration
13+
CONDA_ENV_NAME="forge:stable"
14+
1215
# Colors for output
1316
RED='\033[0;31m'
1417
GREEN='\033[0;32m'
@@ -45,6 +48,7 @@ mount_workspace() {
4548
log_info "Creating mount directory: $mount_dir"
4649
sudo mkdir -p "$mount_dir" || {
4750
log_error "Failed to create mount directory (may need sudo privileges)"
51+
log_error "You could alternatively try to unmount with `sudo umount /mnt/wsfuse`"
4852
return 1
4953
}
5054
fi
@@ -130,10 +134,10 @@ if [ ! -f "$CONDA_SCRIPT_PATH" ]; then
130134
fi
131135

132136
log_info "Sourcing conda script: $CONDA_SCRIPT_PATH"
133-
source "$CONDA_SCRIPT_PATH" activate forge:e146614
137+
source "$CONDA_SCRIPT_PATH" activate "$CONDA_ENV_NAME"
134138

135139
if [ $? -ne 0 ]; then
136-
log_error "Failed to activate conda environment forge-e146614"
140+
log_error "Failed to activate conda environment $CONDA_ENV_NAME"
137141
exit 1
138142
fi
139143

@@ -191,8 +195,72 @@ fi
191195

192196
log_info "Current directory: $(pwd)"
193197

194-
# Step 5: Install forge package
195-
log_info "Step 5: Installing forge package..."
198+
# Step 5: Install torchtitan
199+
log_info "Step 5: Installing torchtitan..."
200+
201+
# Source versions.sh to get the pinned commit
202+
VERSIONS_FILE="$FORGE_REPO_DIR/assets/versions.sh"
203+
if [ -f "$VERSIONS_FILE" ]; then
204+
log_info "Sourcing version information from: $VERSIONS_FILE"
205+
source "$VERSIONS_FILE"
206+
207+
if [ -n "$TORCHTITAN_COMMIT" ]; then
208+
log_info "Installing torchtitan from commit: $TORCHTITAN_COMMIT"
209+
pip uninstall -y torchtitan
210+
pip install "git+https://github.com/pytorch/torchtitan.git@$TORCHTITAN_COMMIT"
211+
212+
if [ $? -eq 0 ]; then
213+
log_info "Torchtitan installed successfully"
214+
else
215+
log_error "Failed to install torchtitan"
216+
exit 1
217+
fi
218+
else
219+
log_error "TORCHTITAN_COMMIT not found in versions.sh"
220+
exit 1
221+
fi
222+
else
223+
log_error "versions.sh not found at: $VERSIONS_FILE"
224+
log_error "Cannot proceed without version information"
225+
exit 1
226+
fi
227+
228+
# Step 5.5: Apply monarch torch import hack
229+
log_info "Step 5.5: Applying monarch torch import hack..."
230+
231+
MONARCH_INIT="$CONDA_PREFIX/lib/python3.10/site-packages/monarch/__init__.py"
232+
if [ -f "$MONARCH_INIT" ]; then
233+
# Check if we already applied the hack
234+
if grep -q "^import torch # Injected by forge setup" "$MONARCH_INIT"; then
235+
log_info "Monarch torch import hack already applied, skipping"
236+
else
237+
log_info "Injecting 'import torch' into monarch/__init__.py"
238+
239+
# Create a backup
240+
cp "$MONARCH_INIT" "$MONARCH_INIT.bak"
241+
242+
# Use sed to inject 'import torch' before the "# Import before monarch" comment
243+
# We add it right after "from typing import TYPE_CHECKING" and before the comment
244+
sed -i '/^from typing import TYPE_CHECKING$/a\
245+
\
246+
# Torch must be imported before monarch (injected by forge setup)\
247+
import torch # Injected by forge setup' "$MONARCH_INIT"
248+
249+
if [ $? -eq 0 ]; then
250+
log_info "Successfully injected torch import into monarch/__init__.py"
251+
else
252+
log_error "Failed to inject torch import, restoring backup"
253+
mv "$MONARCH_INIT.bak" "$MONARCH_INIT"
254+
exit 1
255+
fi
256+
fi
257+
else
258+
log_warn "monarch/__init__.py not found at: $MONARCH_INIT"
259+
log_warn "Skipping monarch torch import hack (monarch may not be installed yet)"
260+
fi
261+
262+
# Step 6: Install forge package
263+
log_info "Step 6: Installing forge package..."
196264
pip install --no-deps --force-reinstall .
197265
if [ $? -ne 0 ]; then
198266
log_error "Failed to install forge package"
@@ -234,5 +302,5 @@ log_info "Mounted workspace available at: /mnt/wsfuse"
234302
echo ""
235303
log_info "Installation completed successfully!"
236304
echo ""
237-
log_info "Re-activate the conda environment to make the changes take effect:"
238-
log_info "conda deactivate && conda activate forge-e146614"
305+
log_info "Test that this is working locally with:"
306+
log_info "python -m apps.grpo.main --config=apps/grpo/qwen3_1_7b.yaml"
File renamed without changes.

apps/mast/qwen3_14b_mast.yaml renamed to .meta/mast/qwen3_14b_mast.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Grouped Relative Policy Optimization (GRPO)
2-
# >>> python -m apps.grpo.main --config apps/grpo/qwen3_1_7b.yaml
2+
# >>> python -m .meta.mast.main --config .meta/mast/qwen3_14b_mast.yaml
33

44
# Global configuration
55
group_size: 8

apps/mast/qwen3_1_7b_mast.yaml renamed to .meta/mast/qwen3_1_7b_mast.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Grouped Relative Policy Optimization (GRPO)
2-
# >>> python -m apps.grpo.main --config apps/grpo/qwen3_1_7b.yaml
2+
# >>> python -m .meta.mast.main --config .meta/mast/qwen3_1_7b_mast.yaml
33

44
# Global configuration
55
group_size: 8

apps/mast/qwen3_32b_mast.yaml renamed to .meta/mast/qwen3_32b_mast.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Grouped Relative Policy Optimization (GRPO)
2-
# >>> python -m apps.mast.main --config apps/mast/qwen3_1_7b_mast.yaml
2+
# >>> python -m .meta.mast.main --config .meta/mast/qwen3_32b_mast.yaml
33

44
# Global configuration
55
group_size: 8

apps/mast/qwen3_4b_mast.yaml renamed to .meta/mast/qwen3_4b_mast.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Grouped Relative Policy Optimization (GRPO)
2-
# >>> python -m apps.grpo.main --config apps/grpo/qwen3_1_7b.yaml
2+
# >>> python -m .meta.mast.main --config .meta/mast/qwen3_4b_mast.yaml
33

44
# Global configuration
55
group_size: 8

apps/mast/qwen3_8b_mast.yaml renamed to .meta/mast/qwen3_8b_mast.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Grouped Relative Policy Optimization (GRPO)
2-
# >>> python -m apps.grpo.main --config apps/grpo/qwen3_1_7b.yaml
2+
# >>> python -m .meta.mast.main --config .meta/mast/qwen3_8b_mast.yaml
33

44
# Global configuration
55
group_size: 8

0 commit comments

Comments
 (0)