while getopts ":p:v:m:f:t:k:" opt; do case ${opt} in p ) path_to_weights=$OPTARG ;; v ) vocab_size=$OPTARG ;; m ) model_name=$OPTARG ;; f ) vocab_file=$OPTARG ;; t ) model_type=$OPTARG ;; k ) kv_channels=$OPTARG ;; \? ) echo "Invalid option: $OPTARG" 1>&2 exit 1 ;; : ) echo "Invalid option: $OPTARG requires an argument" 1>&2 exit 1 ;; esac done shift $((OPTIND -1)) KV_CHANNELS_ARGS="" if [ "$kv_channels" != "" ]; then KV_CHANNELS_ARGS="--kv_channels $kv_channels" fi # path_to_weights is where the latest_checkpointed_iteration.txt file is located # script creates a folder with respective iteration in unsharded_dir, so no need to specify iteration python tools/checkpoint_util.py \ --target_tensor_parallel_size 1 \ --target_pipeline_parallel_size 1 \ --load_dir $path_to_weights \ --save_dir "${path_to_weights}/unsharded" \ --model_type $model_type \ --true_vocab_size $vocab_size \ --bf16 \ $KV_CHANNELS_ARGS python weights_conversion/megatron_to_hf.py \ --input_dir "${path_to_weights}/unsharded" \ --output_dir "${path_to_weights}/hf/${model_name}" \ --vocab_file "${vocab_file}" \ --model $model_type # remove intermediate step rm -r "${path_to_weights}/unsharded"