Skip to content

Commit

Permalink
[Cleanup] Split run_llama_train.sh and run_memory_estimation.sh
Browse files Browse the repository at this point in the history
Make each script simpler to read

ghstack-source-id: ba3aa65feb6e304736c73daf5bc8ab5fb254f196
Pull Request resolved: pytorch#455
  • Loading branch information
wconstab committed Jul 15, 2024
1 parent ac72078 commit 4b6cdc1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
17 changes: 3 additions & 14 deletions run_llama_train.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ set -ex
# e.g.
# LOG_RANK=0,1 NGPU=4 ./run_llama_train.sh
NGPU=${NGPU:-"8"}
NNODES=${NNODES:-"1"}
TRAINER_DIR=${TRAINER_DIR:-/home/$USER/local/torchtitan}
LOG_RANK=${LOG_RANK:-0}
CONFIG_FILE=${CONFIG_FILE:-"./train_configs/debug_model.toml"}
Expand All @@ -21,16 +20,6 @@ if [ $# -ne 0 ]; then
overrides="$*"
fi

# Check if --estimate.memory=True is in the arguments
if echo "$overrides" | grep -q -- "--memory_estimation.enabled"; then
# Calculate WORLD_SIZE as the product of NGPU and NNODES
# Export WORLD_SIZE and LOCAL_RANK
export WORLD_SIZE=$((NGPU * NNODES))
export LOCAL_RANK=0
python estimation.py --job.config_file ${CONFIG_FILE} $overrides
else
# Call train.py if not in estimation mode
torchrun --nproc_per_node=${NGPU} --rdzv_backend c10d --rdzv_endpoint="localhost:0" \
--local-ranks-filter ${LOG_RANK} --role rank --tee 3 \
train.py --job.config_file ${CONFIG_FILE} $overrides
fi
torchrun --nproc_per_node=${NGPU} --rdzv_backend c10d --rdzv_endpoint="localhost:0" \
--local-ranks-filter ${LOG_RANK} --role rank --tee 3 \
train.py --job.config_file ${CONFIG_FILE} $overrides
27 changes: 27 additions & 0 deletions run_memory_estimation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.

# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

set -ex

# use envs as local overrides for convenience
# e.g.
# NGPU=4 ./run_memory_estimation.sh
NGPU=${NGPU:-"8"}
NNODES=${NNODES:-"1"}
TRAINER_DIR=${TRAINER_DIR:-/home/$USER/local/torchtitan}
CONFIG_FILE=${CONFIG_FILE:-"./train_configs/debug_model.toml"}

overrides=""
if [ $# -ne 0 ]; then
overrides="$*"
fi

# Calculate WORLD_SIZE as the product of NGPU and NNODES
# Export WORLD_SIZE and LOCAL_RANK
export WORLD_SIZE=$((NGPU * NNODES))
export LOCAL_RANK=0
python estimation.py --job.config_file ${CONFIG_FILE} --memory_estimation.enabled $overrides

0 comments on commit 4b6cdc1

Please sign in to comment.