Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third_party/Megatron-LM"]
path = third_party/Megatron-LM
url = https://github.com/stanford-futuredata/Megatron-LM.git
url = https://github.com/ROCm/Stanford-Megatron-LM
[submodule "third_party/Stanford-Megatron-LM"]
path = third_party/Stanford-Megatron-LM
url = https://github.com/ROCm/Stanford-Megatron-LM
19 changes: 14 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
FROM nvcr.io/nvidia/pytorch:23.09-py3
FROM rocm/pytorch:rocm6.3_ubuntu24.04_py3.12_pytorch_release_2.4.0
WORKDIR /root/

RUN pip install stanford-stk==0.0.6
# Install the application dependencies
RUN pip install regex
RUN pip install nltk
RUN pip install pybind11

RUN pip install flash-attn
RUN git clone --recurse-submodules -j8 https://github.com/ROCm/megablocks && \
cd megablocks && \
./patch_torch.sh && \
python setup.py install

ENV PYTHONPATH="/mount/megablocks/third_party/Megatron-LM:${PYTHONPATH}"
RUN cd megablocks/third_party/Stanford-Megatron-LM && \
git checkout rocm_6_3_patch && \
./apply_patch.sh

WORKDIR /mount/megablocks
CMD ["/bin/bash"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ We provide scripts for pre-training Transformer MoE and dMoE language models und
volume={5},
year={2023}
}
```
```
14 changes: 11 additions & 3 deletions csrc/replicate.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Modifications: Copyright Advanced Micro Devices, Inc. SPDX License: MIT.

#undef CUB_WRAPPED_NAMESPACE
#define CUB_WRAPPED_NAMESPACE megablocks

Expand All @@ -8,6 +10,12 @@
#include <c10/cuda/CUDAStream.h>
#include <torch/extension.h>

#ifndef USE_ROCM
#define _LDG(arg) __ldg(arg)
#else
#define _LDG(arg) *(arg)
#endif

#define CUDA_CALL(code) \
do { \
cudaError_t status = code; \
Expand Down Expand Up @@ -37,11 +45,11 @@ __global__ void __launch_bounds__(kThreadsPerBlock)
// Load the start/end for this bin.
int bin_idx = blockIdx.x;
int start = 0;
if (bin_idx > 0) start = __ldg(bins + bin_idx - 1);
int end = __ldg(bins + bin_idx);
if (bin_idx > 0) start = _LDG(bins + bin_idx - 1);
int end = _LDG(bins + bin_idx);

// Load the value to replicate.
T value = __ldg((T*)x + bin_idx);
T value = _LDG((T*)x + bin_idx);

// Offset to this threadblocks bin and this threads
// offset within the bin.
Expand Down
10 changes: 0 additions & 10 deletions docker.sh

This file was deleted.

15 changes: 10 additions & 5 deletions exp/dmoe/dmoe_125m_8gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ PILE_DATASET="\
1.0 \
/mount/pile_gpt2/29_text_document"

VOCAB_FILE=<Enter location here>
MERGE_FILE=<Enter location here>
DATA_PATH=<Enter location here>
CHECKPOINT_PATH=<Enter location here>

# NOTE: We don't train for enough tokens for the
# split to matter.
DATA_ARGUMENTS="\
--data-path ${PILE_DATASET} \
--vocab-file /mount/gpt2-vocab.json \
--merge-file /mount/gpt2-merges.txt \
--data-path ${DATA_PATH} \
--vocab-file ${VOCAB_FILE} \
--merge-file ${MERGE_FILE} \
--make-vocab-size-divisible-by 1024 \
--split 969,30,1"

Expand All @@ -145,7 +150,7 @@ COMPUTE_ARGUMENTS="\
--DDP-impl local \
--moe-expert-model-parallelism \
--no-async-tensor-model-parallel-allreduce \
--use-flash-attn"
--no-gradient-accumulation-fusion"

CHECKPOINT_ARGUMENTS="\
--save-interval 2000 \
Expand All @@ -157,7 +162,7 @@ EVALUATION_ARGUMENTS="\
--eval-interval 1000"

torchrun ${DISTRIBUTED_ARGUMENTS} \
third_party/Megatron-LM/pretrain_gpt.py \
third_party/Stanford-Megatron-LM/pretrain_gpt.py \
${MOE_ARGUMENTS} \
${MODEL_ARGUMENTS} \
${TRAINING_ARGUMENTS} \
Expand Down
15 changes: 10 additions & 5 deletions exp/dmoe/dmoe_356m_8gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ PILE_DATASET="\
1.0 \
/mount/pile_gpt2/29_text_document"

VOCAB_FILE=<Enter location here>
MERGE_FILE=<Enter location here>
DATA_PATH=<Enter location here>
CHECKPOINT_PATH=<Enter location here>

# NOTE: We don't train for enough tokens for the
# split to matter.
DATA_ARGUMENTS="\
--data-path ${PILE_DATASET} \
--vocab-file /mount/gpt2-vocab.json \
--merge-file /mount/gpt2-merges.txt \
--data-path ${DATA_PATH} \
--vocab-file ${VOCAB_FILE} \
--merge-file ${MERGE_FILE} \
--make-vocab-size-divisible-by 1024 \
--split 969,30,1"

Expand All @@ -145,7 +150,7 @@ COMPUTE_ARGUMENTS="\
--DDP-impl local \
--moe-expert-model-parallelism \
--no-async-tensor-model-parallel-allreduce \
--use-flash-attn"
--no-gradient-accumulation-fusion"

CHECKPOINT_ARGUMENTS="\
--save-interval 2000 \
Expand All @@ -158,7 +163,7 @@ EVALUATION_ARGUMENTS="\


torchrun ${DISTRIBUTED_ARGUMENTS} \
third_party/Megatron-LM/pretrain_gpt.py \
third_party/Stanford-Megatron-LM/pretrain_gpt.py \
${MOE_ARGUMENTS} \
${MODEL_ARGUMENTS} \
${TRAINING_ARGUMENTS} \
Expand Down
15 changes: 10 additions & 5 deletions exp/dmoe/dmoe_46m_8gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ PILE_DATASET="\
1.0 \
/mount/pile_gpt2/29_text_document"

VOCAB_FILE=<Enter location here>
MERGE_FILE=<Enter location here>
DATA_PATH=<Enter location here>
CHECKPOINT_PATH=<Enter location here>

# NOTE: We don't train for enough tokens for the
# split to matter.
DATA_ARGUMENTS="\
--data-path ${PILE_DATASET} \
--vocab-file /mount/gpt2-vocab.json \
--merge-file /mount/gpt2-merges.txt \
--data-path ${DATA_PATH} \
--vocab-file ${VOCAB_FILE} \
--merge-file ${MERGE_FILE} \
--make-vocab-size-divisible-by 1024 \
--split 969,30,1"

Expand All @@ -145,7 +150,7 @@ COMPUTE_ARGUMENTS="\
--DDP-impl local \
--moe-expert-model-parallelism \
--no-async-tensor-model-parallel-allreduce \
--use-flash-attn"
--no-gradient-accumulation-fusion"

CHECKPOINT_ARGUMENTS="\
--save-interval 2000 \
Expand All @@ -157,7 +162,7 @@ EVALUATION_ARGUMENTS="\
--eval-interval 1000"

torchrun ${DISTRIBUTED_ARGUMENTS} \
third_party/Megatron-LM/pretrain_gpt.py \
third_party/Stanford-Megatron-LM/pretrain_gpt.py \
${MOE_ARGUMENTS} \
${MODEL_ARGUMENTS} \
${TRAINING_ARGUMENTS} \
Expand Down
15 changes: 10 additions & 5 deletions exp/dmoe/dmoe_760m_8gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ PILE_DATASET="\
1.0 \
/mount/pile_gpt2/29_text_document"

VOCAB_FILE=<Enter location here>
MERGE_FILE=<Enter location here>
DATA_PATH=<Enter location here>
CHECKPOINT_PATH=<Enter location here>

# NOTE: We don't train for enough tokens for the
# split to matter.
DATA_ARGUMENTS="\
--data-path ${PILE_DATASET} \
--vocab-file /mount/gpt2-vocab.json \
--merge-file /mount/gpt2-merges.txt \
--data-path ${DATA_PATH} \
--vocab-file ${VOCAB_FILE} \
--merge-file ${MERGE_FILE} \
--make-vocab-size-divisible-by 1024 \
--split 969,30,1"

Expand All @@ -145,7 +150,7 @@ COMPUTE_ARGUMENTS="\
--DDP-impl local \
--moe-expert-model-parallelism \
--no-async-tensor-model-parallel-allreduce \
--use-flash-attn"
--no-gradient-accumulation-fusion"

CHECKPOINT_ARGUMENTS="\
--save-interval 2000 \
Expand All @@ -157,7 +162,7 @@ EVALUATION_ARGUMENTS="\
--eval-interval 1000"

torchrun ${DISTRIBUTED_ARGUMENTS} \
third_party/Megatron-LM/pretrain_gpt.py \
third_party/Stanford-Megatron-LM/pretrain_gpt.py \
${MOE_ARGUMENTS} \
${MODEL_ARGUMENTS} \
${TRAINING_ARGUMENTS} \
Expand Down
17 changes: 12 additions & 5 deletions exp/gpt2/gpt2_125m_1gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,25 @@ PILE_DATASET="\
1.0 \
../pile_gpt2/29_text_document"

VOCAB_FILE=<Enter location here>
MERGE_FILE=<Enter location here>
DATA_PATH=<Enter location here>
CHECKPOINT_PATH=<Enter location here>

# NOTE: We don't train for enough tokens for the
# split to matter.
DATA_ARGUMENTS="\
--data-path ${PILE_DATASET} \
--vocab-file ../gpt2-vocab.json \
--merge-file ../gpt2-merges.txt \
--data-path ${DATA_PATH} \
--vocab-file ${VOCAB_FILE} \
--merge-file ${MERGE_FILE} \
--make-vocab-size-divisible-by 1024 \
--split 969,30,1"

COMPUTE_ARGUMENTS="\
--fp16 \
--DDP-impl local"
--DDP-impl local \
--no-async-tensor-model-parallel-allreduce \
--no-gradient-accumulation-fusion"

CHECKPOINT_ARGUMENTS="\
--save-interval 2000 \
Expand All @@ -127,7 +134,7 @@ EVALUATION_ARGUMENTS="\
--eval-interval 1000"

torchrun ${DISTRIBUTED_ARGUMENTS} \
third_party/Megatron-LM/pretrain_gpt.py \
third_party/Stanford-Megatron-LM/pretrain_gpt.py \
${MODEL_ARGUMENTS} \
${TRAINING_ARGUMENTS} \
${DATA_ARGUMENTS} \
Expand Down
20 changes: 13 additions & 7 deletions exp/gpt2/gpt2_125m_8gpu.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# Modifications: Copyright Advanced Micro Devices, Inc. SPDX License: MIT.

EXP_DIR=$1

Expand Down Expand Up @@ -106,35 +107,40 @@ PILE_DATASET="\
1.0 \
/mount/pile_gpt2/29_text_document"

VOCAB_FILE=<Enter location here>
MERGE_FILE=<Enter location here>
DATA_PATH=<Enter location here>
CHECKPOINT_PATH=<Enter location here>

# NOTE: We don't train for enough tokens for the
# split to matter.
DATA_ARGUMENTS="\
--data-path ${PILE_DATASET} \
--vocab-file /mount/gpt2-vocab.json \
--merge-file /mount/gpt2-merges.txt \
--data-path ${DATA_PATH} \
--vocab-file ${VOCAB_FILE} \
--merge-file ${MERGE_FILE} \
--make-vocab-size-divisible-by 1024 \
--split 969,30,1"

COMPUTE_ARGUMENTS="\
--bf16 \
--DDP-impl local \
--no-async-tensor-model-parallel-allreduce \
--use-flash-attn"
--no-gradient-accumulation-fusion"

CHECKPOINT_ARGUMENTS="\
--save-interval 2000 \
--save ./${EXP_DIR}"
--save ${CHECKPOINT_PATH}"

EVALUATION_ARGUMENTS="\
--eval-iters 100 \
--log-interval 100 \
--eval-interval 1000"

torchrun ${DISTRIBUTED_ARGUMENTS} \
third_party/Megatron-LM/pretrain_gpt.py \
third_party/Stanford-Megatron-LM/pretrain_gpt.py \
${MODEL_ARGUMENTS} \
${TRAINING_ARGUMENTS} \
${DATA_ARGUMENTS} \
${COMPUTE_ARGUMENTS} \
${CHECKPOINT_ARGUMENTS} \
${EVALUATION_ARGUMENTS} |& tee ./${EXP_DIR}/train.log
${EVALUATION_ARGUMENTS} |& tee ${CHECKPOINT_PATH}/train.log
17 changes: 12 additions & 5 deletions exp/gpt2/gpt2_1315m_1gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,25 @@ PILE_DATASET="\
1.0 \
../pile_gpt2/29_text_document"

VOCAB_FILE=<Enter location here>
MERGE_FILE=<Enter location here>
DATA_PATH=<Enter location here>
CHECKPOINT_PATH=<Enter location here>

# NOTE: We don't train for enough tokens for the
# split to matter.
DATA_ARGUMENTS="\
--data-path ${PILE_DATASET} \
--vocab-file ../gpt2-vocab.json \
--merge-file ../gpt2-merges.txt \
--data-path ${DATA_PATH} \
--vocab-file ${VOCAB_FILE} \
--merge-file ${MERGE_FILE} \
--make-vocab-size-divisible-by 1024 \
--split 969,30,1"

COMPUTE_ARGUMENTS="\
--fp16 \
--DDP-impl local"
--DDP-impl local \
--no-async-tensor-model-parallel-allreduce \
--no-gradient-accumulation-fusion"

CHECKPOINT_ARGUMENTS="\
--save-interval 2000 \
Expand All @@ -126,7 +133,7 @@ EVALUATION_ARGUMENTS="\
--eval-interval 1000"

torchrun ${DISTRIBUTED_ARGUMENTS} \
third_party/Megatron-LM/pretrain_gpt.py \
third_party/Stanford-Megatron-LM/pretrain_gpt.py \
${MODEL_ARGUMENTS} \
${TRAINING_ARGUMENTS} \
${DATA_ARGUMENTS} \
Expand Down
Loading