Skip to content

Commit a2b3a9e

Browse files
committed
hydrate cache
1 parent 42d83de commit a2b3a9e

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

.meta/mast/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,48 @@ The launch script will automatically:
4444
- Launch the MAST job with the specified config
4545

4646
You can run it from anywhere, and it will figure out the correct paths.
47+
48+
49+
## Managing HuggingFace Models in MAST
50+
51+
### The Problem: No Internet Access
52+
53+
MAST compute nodes cannot access the internet, which means they cannot download models directly from HuggingFace. To work around this, we store all HuggingFace models and cache data on OilFS at `/mnt/wsfuse/teamforge/hf`, which is accessible from MAST.
54+
55+
### Solution: Two-Step Process
56+
57+
You need to perform both steps below to ensure models work correctly in MAST:
58+
59+
#### 1. Download Model Weights to OilFS
60+
61+
First, download the model weights directly to the OilFS path. This should be done from a machine with internet access (like your devserver):
62+
63+
```bash
64+
# Set HF_HOME to the OilFS path
65+
export HF_HOME=/mnt/wsfuse/teamforge/hf
66+
67+
# Download the model (replace with your desired model)
68+
huggingface-cli download Qwen/Qwen3-8B --local-dir /mnt/wsfuse/teamforge/hf_artifacts/qwen3_8b
69+
```
70+
71+
#### 2. Hydrate the HuggingFace Cache
72+
73+
After downloading the weights, you need to hydrate the HuggingFace cache so that the transformers library can find the model metadata:
74+
75+
```bash
76+
# Set HF_HOME to the OilFS path
77+
export HF_HOME=/mnt/wsfuse/teamforge/hf
78+
79+
# Hydrate the cache for the model
80+
python .meta/mast/hydrate_cache.py --model-id Qwen/Qwen3-8B
81+
```
82+
83+
This ensures that when MAST runs with `HF_HUB_OFFLINE=1`, the transformers library can locate all necessary files from the cache.
84+
85+
### Directory Structure
86+
87+
Both cache and model files are stored under:
88+
- **Cache**: `/mnt/wsfuse/teamforge/hf` (set via `HF_HOME`)
89+
- **Model weights**: `/mnt/wsfuse/teamforge/hf/<model_name>`
90+
91+
Make sure your MAST config files point to the correct paths in `hf_artifacts`.

.meta/mast/hydrate_cache.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
"""This is convenience script meant for hydrating the HuggingFace cache.
8+
9+
This is meant for downloading the model weights and tokenizer to the cache, i.e. for
10+
OilFS.
11+
12+
Example:
13+
14+
python .meta/mast/hydrate_cache.py --model-id Qwen/Qwen3-32B
15+
16+
"""
17+
import argparse
18+
import os
19+
import sys
20+
21+
from transformers import AutoModelForCausalLM, AutoTokenizer
22+
23+
24+
def main():
25+
parser = argparse.ArgumentParser(
26+
description="Hydrate HuggingFace cache for a specific model"
27+
)
28+
parser.add_argument(
29+
"--model-id",
30+
type=str,
31+
required=True,
32+
help="HuggingFace model ID (e.g., Qwen/Qwen3-8B)",
33+
)
34+
args = parser.parse_args()
35+
36+
# Ensure HF_HOME is set
37+
hf_home = os.environ.get("HF_HOME")
38+
if not hf_home:
39+
print(
40+
"ERROR: HF_HOME environment variable must be set. "
41+
"You will likely want to run export HF_HOME=/mnt/wsfuse/teamforge/hf."
42+
)
43+
sys.exit(1)
44+
45+
print(f"Using HF_HOME: {hf_home}")
46+
print(f"Downloading {args.model_id}...")
47+
48+
# This will pull tokenizer + config + all weight shards
49+
tokenizer = AutoTokenizer.from_pretrained(args.model_id, trust_remote_code=True)
50+
model = AutoModelForCausalLM.from_pretrained(args.model_id, trust_remote_code=True)
51+
52+
print("Download complete. Cache hydrated.")
53+
54+
55+
if __name__ == "__main__":
56+
main()

src/forge/controller/launcher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ def build_appdef(self) -> specs.AppDef:
296296
"HF_HUB_OFFLINE": "1",
297297
"MONARCH_HOST_MESH_V1_REMOVE_ME_BEFORE_RELEASE": "1",
298298
"TORCHSTORE_RDMA_ENABLED": "1",
299-
# "HF_HOME": "/mnt/wsfuse/teamforge/hf",
299+
"HF_HOME": "/mnt/wsfuse/teamforge/hf",
300+
"TRANSFORMERS_OFFLINE": "1",
300301
},
301302
}
302303

0 commit comments

Comments
 (0)