-
Notifications
You must be signed in to change notification settings - Fork 10
/
slurm_example.sub
118 lines (106 loc) · 4.42 KB
/
slurm_example.sub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
#SBATCH --exclusive
#SBATCH --mem=0
#SBATCH --overcommit
#SBATCH --parsable
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# This Slurm script demonstrates how to use the LDDL preprocessor, load balancer
# and data loader and scale them to multi-nodes on Slurm clusters for (mock)
# BERT Phase 2 pretraining with static masking and sequence binning enabled.
#
set -eux
#
# The following configurations might need to be customized based on the setup
# of the Slurm cluster you are using.
#
# The URL of the container image built via `bash docker/build.sh`.
# For example, if you build the container image by
# `bash docker/build.sh ngc_pyt 21.11-py3 lddl:latest push`,
# then the URL would be "lddl:latest":
readonly docker_image=${DOCKER_IMAGE:-"lddl:latest"}
# Create a directory to store data.
mkdir -p data/
# Assume the Wikipedia dump is already downloaded and moved to the following
# location in the NFS of your Slurm cluster.
#
# Please refer to examples/local_example.sh on how to use the LDDL downloader
# to download the Wikipedia dump.
readonly wikipedia_path=data/wikipedia
# Download the vocab file from NVIDIA Deep Learning Examples (but you can
# certainly get it from other sources as well).
readonly vocab_source_url=https://raw.githubusercontent.com/NVIDIA/DeepLearningExamples/master/PyTorch/LanguageModeling/BERT/vocab/vocab
mkdir -p data/vocab/
readonly vocab_path=data/vocab/bert-en-uncased.txt
wget ${vocab_source_url} -O ${vocab_path}
# Run the LDDL preprocessor for BERT Phase 2 pretraining with static masking and
# sequence binning enabled (where the bin size is 64).
readonly mounts=$(realpath data/):/workspace/lddl/data
readonly workdir=/workspace/lddl
readonly num_shards=4096
readonly bin_size=64
readonly tasks_per_node=128
readonly pretrain_input_path=data/bert/pretrain/phase2/bin_size_${bin_size}/
srun \
-l \
--mpi=pmix \
--container-image="${docker_image}" \
--container-mounts="${mounts}" \
--container-workdir=${workdir} \
--ntasks-per-node=${tasks_per_node} \
--export=ALL,LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so \
preprocess_bert_pretrain \
--schedule mpi \
--vocab-file ${vocab_path} \
--wikipedia ${wikipedia_path}/source/ \
--sink ${pretrain_input_path} \
--target-seq-length 512 \
--num-blocks ${num_shards} \
--bin-size ${bin_size} \
--masking
# Run the LDDL load balancer to balance the parquet shards generated by the LDDL
# preprocessor.
srun \
-l \
--mpi=pmix \
--container-image="${docker_image}" \
--container-mounts="${mounts}" \
--container-workdir=${workdir} \
--ntasks-per-node=${tasks_per_node} \
balance_dask_output \
--indir ${pretrain_input_path} \
--num-shards ${num_shards}
# Run a mock PyTorch training script that loads the input from the balanced
# parquet shards using the LDDL data loader.
# Once these training processes is up and running (as you can see from the
# stdout printing), it simply emulates training and you can kill it at any time.
readonly gpus_per_node=8
srun \
-l \
--container-image="${docker_image}" \
--container-mounts="${mounts}" \
--container-workdir=${workdir} \
--ntasks-per-node=${gpus_per_node} \
python benchmarks/torch_train.py \
--path ${pretrain_input_path} \
--vocab-file ${vocab_path}