File size: 1,452 Bytes
a93e458
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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"