-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Adithyare/sft ultra v3 feb2026 #3272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fa016fd
rebased main
arendu e039525
identity template and tool role mask
ae4717d
revert assert
44c5c24
Skip empty sequences and chunks in MTP tensor roll
rkarimimahab 8ed4905
add option for SFTTokenizer to build_tokenizers
arendu 30f1f32
resolve conflicts between args.sft and args.hybrid_context_parallel
arendu 72a2740
do not check for and add any EOD
arendu f82168a
removed dup identity template
arendu 68514e8
added from #2363
arendu d10fa92
use core sft_tokenizer
arendu edd864c
fmt
arendu 7bd7bfd
Merge remote-tracking branch 'github-upstream/main' into adithyare/sf…
arendu f71ad30
commit from main
arendu f3c6356
checkout main
arendu ee5e581
feat: update scripts for perf. optimizations such as HybridEP, Numact…
seonjinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| #! /bin/bash | ||
| # Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Megatron is not Apache licensed and we don't put the license in each file. |
||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| print_usage() { | ||
| cat << EOF | ||
| ${0} [options] [--] COMMAND [ARG...] | ||
|
|
||
| Control binding policy for each task. Assumes one rank will be launched for each GPU. | ||
|
|
||
| Options: | ||
| --cpu=MODE | ||
| * exclusive -- bind each rank to an exclusive set of cores near its GPU | ||
| * exclusive,nosmt -- bind each rank to an exclusive set of cores near its GPU, without hyperthreading | ||
| * node -- bind each rank to all cores in the NUMA node nearest its GPU [default] | ||
| * *.sh -- bind each rank using the bash associative array bind_cpu_cores or bind_cpu_nodes from a file | ||
| * off -- don't bind | ||
| --mem=MODE | ||
| * node -- bind each rank to the nearest NUMA node [default] | ||
| * *.sh -- bind each rank using the bash associative array bind_mem from a file | ||
| * off -- don't bind | ||
| --ib=MODE | ||
| * single -- bind each rank to a single IB device near its GPU | ||
| * off -- don't bind [default] | ||
| EOF | ||
| } | ||
|
|
||
| ################################################################################ | ||
| # Argument parsing | ||
| ################################################################################ | ||
|
|
||
| cpu_mode='node' | ||
| mem_mode='node' | ||
| ib_mode='off' | ||
| while [[ "$#" -gt "0" ]]; do | ||
| case "$1" in | ||
| -h|--help) print_usage ; exit 0 ;; | ||
| --cpu=*) cpu_mode="${1/*=/}"; shift ;; | ||
| --cpu) cpu_mode="$2"; shift 2 ;; | ||
| --mem=*) mem_mode="${1/*=/}"; shift ;; | ||
| --mem) mem_mode="$2"; shift 2 ;; | ||
| --ib=*) ib_mode="${1/*=/}"; shift ;; | ||
| --ib) ib_mode="$2"; shift 2 ;; | ||
| --) shift; break ;; | ||
| *) break ;; | ||
| esac | ||
| done | ||
| if [[ $# -lt 1 ]]; then | ||
| echo 'ERROR: no command given' 2>&1 | ||
| print_usage | ||
| exit 1 | ||
| fi | ||
|
|
||
| ################################################################################ | ||
| # Get system params | ||
| ################################################################################ | ||
|
|
||
| # LOCAL_RANK is set with an enroot hook for Pytorch containers | ||
| # SLURM_LOCALID is set by Slurm | ||
| # OMPI_COMM_WORLD_LOCAL_RANK is set by mpirun | ||
| readonly local_rank="${LOCAL_RANK:=${SLURM_LOCALID:=${OMPI_COMM_WORLD_LOCAL_RANK:-}}}" | ||
| if [[ ! "${local_rank}" ]]; then | ||
| echo 'ERROR: cannot read LOCAL_RANK from env' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| num_gpus=$(nvidia-smi -i 0 --query-gpu=count --format=csv,noheader,nounits) | ||
| if [[ "${local_rank}" -ge "${num_gpus}" ]]; then | ||
| echo "ERROR: local rank is ${local_rank}, but there are only ${num_gpus} gpus available" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| get_lscpu_value() { | ||
| awk -F: "(\$1 == \"${1}\"){gsub(/ /, \"\", \$2); print \$2; found=1} END{exit found!=1}" | ||
| } | ||
| lscpu_out=$(lscpu) | ||
| num_sockets=$(get_lscpu_value 'Socket(s)' <<< "${lscpu_out}") | ||
| num_nodes=$(lscpu --parse | grep -v '^#' | cut -f4 -d, | sort --unique | wc --lines) | ||
| cores_per_socket=$(get_lscpu_value 'Core(s) per socket' <<< "${lscpu_out}") | ||
|
|
||
| echo "num_gpus=${num_gpus} num_sockets = ${num_sockets} num_nodes=${num_nodes} cores_per_socket=${cores_per_socket}" | ||
|
|
||
| readonly cores_per_node=$(( (num_sockets * cores_per_socket) / num_nodes )) | ||
| if [[ "${num_gpus}" -gt "1" ]] && [[ "${num_gpus}" -ge "${num_nodes}" ]]; then | ||
| readonly gpus_per_node=$(( num_gpus / num_nodes )) | ||
| else | ||
| readonly gpus_per_node=1 | ||
| num_nodes="${num_gpus}" | ||
| fi | ||
| readonly cores_per_gpu=$(( cores_per_node / gpus_per_node )) | ||
| readonly local_node=$(( local_rank / gpus_per_node )) | ||
|
|
||
|
|
||
| declare -a ibdevs=() | ||
| if ibstat_out="$(ibv_devinfo --list | tail -n+2 | cut -f2 | grep -v '^$')"; then | ||
| mapfile -t ibdevs <<< "${ibstat_out}" | ||
| fi | ||
| readonly num_ibdevs="${#ibdevs[@]}" | ||
|
|
||
| ################################################################################ | ||
| # Setup for exec | ||
| ################################################################################ | ||
|
|
||
| declare -a numactl_args=() | ||
|
|
||
| case "${cpu_mode}" in | ||
| exclusive) | ||
| numactl_args+=( "$(printf -- "--physcpubind=%u-%u,%u-%u" \ | ||
| $(( local_rank * cores_per_gpu )) \ | ||
| $(( (local_rank + 1) * cores_per_gpu - 1 )) \ | ||
| $(( local_rank * cores_per_gpu + (cores_per_gpu * gpus_per_node * num_nodes) )) \ | ||
| $(( (local_rank + 1) * cores_per_gpu + (cores_per_gpu * gpus_per_node * num_nodes) - 1 )) \ | ||
| )" ) | ||
| ;; | ||
| exclusive,nosmt) | ||
| numactl_args+=( "$(printf -- "--physcpubind=%u-%u" \ | ||
| $(( local_rank * cores_per_gpu )) \ | ||
| $(( (local_rank + 1) * cores_per_gpu - 1 )) \ | ||
| )" ) | ||
| ;; | ||
| node) | ||
| numactl_args+=( "--cpunodebind=${local_node}" ) | ||
| ;; | ||
| *.sh) | ||
| # shellcheck source=/dev/null | ||
| source "${cpu_mode}" | ||
| if [[ "${bind_cpu_cores:-}" ]]; then | ||
| numactl_args+=( "--physcpubind=${bind_cpu_cores[${local_rank}]}" ) | ||
| elif [[ "${bind_cpu_nodes:-}" ]]; then | ||
| numactl_args+=( "--cpunodebind=${bind_cpu_nodes[${local_rank}]}" ) | ||
| else | ||
| echo "ERROR: invalid CPU affinity file ${cpu_mode}." >&2 | ||
| exit 1 | ||
| fi | ||
| ;; | ||
| off|'') | ||
| ;; | ||
| *) | ||
| echo "ERROR: invalid cpu mode '${cpu_mode}'" 2>&1 | ||
| print_usage | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| case "${mem_mode}" in | ||
| node) | ||
| numactl_args+=( "--membind=${local_node}" ) | ||
| ;; | ||
| *.sh) | ||
| # shellcheck source=/dev/null | ||
| source "${mem_mode}" | ||
| if [[ ! "${bind_mem:-}" ]]; then | ||
| echo "ERROR: invalid memory affinity file ${mem_mode}." >&2 | ||
| exit 1 | ||
| fi | ||
| numactl_args+=( "--membind=${bind_mem[${local_rank}]}" ) | ||
| ;; | ||
| off|'') | ||
| ;; | ||
| *) | ||
| echo "ERROR: invalid mem mode '${mem_mode}'" 2>&1 | ||
| print_usage | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| case "${ib_mode}" in | ||
| single) | ||
| if [[ "${num_ibdevs}" -eq 0 ]]; then | ||
| echo "WARNING: used '$0 --ib=single', but there are 0 IB devices available; skipping IB binding." 2>&1 | ||
| elif (( num_ibdevs > num_gpus)) || (( num_gpus % num_ibdevs != 0 )) ; then | ||
| echo "ERROR: can't evenly map ${num_gpus} gpus to ${num_ibdevs} ibdevs" 2>&1 | ||
| echo "set MELLANOX_VISIBLE_DEVICES correctly or use --ib=off" 2>&1 | ||
| exit 1 | ||
| else | ||
| readonly ibdev="${ibdevs[$(( local_rank * num_ibdevs / num_gpus ))]}" | ||
| export OMPI_MCA_btl_openib_if_include="${OMPI_MCA_btl_openib_if_include-$ibdev}" | ||
| export UCX_NET_DEVICES="${UCX_NET_DEVICES-$ibdev:1}" | ||
| fi | ||
| ;; | ||
| off|'') | ||
| ;; | ||
| *) | ||
| echo "ERROR: invalid ib mode '${ib_mode}'" 2>&1 | ||
| print_usage | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| ################################################################################ | ||
| # Exec | ||
| ################################################################################ | ||
|
|
||
| if [[ "${#numactl_args[@]}" -gt 0 ]] ; then | ||
| [[ "${DEBUG:-0}" = "1" ]] && set -x | ||
| exec numactl "${numactl_args[@]}" -- "${@}" | ||
| else | ||
| exec "${@}" | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will this ever run with the case on line 66 present?