ModelScope 模型下载

1、安装依赖

pip install modelscope -i https://mirrors.aliyun.com/pypi/simple/

2、创建一个python脚本

# -*- coding: utf-8 -*-
# @Time : 2024/6/24 上午10:01
# @Author : yangwenjie
# @Email : 邮箱
# @File : modelscope_spdownload.py.py
# @Project : study
from argparse import ArgumentParser

from modelscope.hub.snapshot_download import snapshot_download
import time
from concurrent.futures import ThreadPoolExecutor


def download_snapshot(*, model_id,cache_dir):
    print('Downloading snapshot {}'.format(model_id))
    snapshot_download(f'{model_id}', cache_dir=cache_dir)


def main(model_ids,cache_dir,max_workers=4):
    with ThreadPoolExecutor(max_workers=max_workers) as executor:
        # model_ids = ['qwen/Qwen-7B', 'qwen/Qwen-7B-Chat', 'qwen/Qwen-7B-Chat-Int4']
        model_ids = [model_ids]
        start = time.time()
        for model_id in model_ids:
            executor.submit(download_snapshot, model_id=model_id,cache_dir=cache_dir)
        end = time.time()
        print('Total elapsed time: {}'.format(end - start))


if __name__ == '__main__':
    # python script.py --model_ids  iic/nlp_bert_entity-embedding_chinese-base
    # python script.py --max_workers 8  --cache_dir ./   --model_ids  iic/nlp_bert_entity-embedding_chinese-base
    parser = ArgumentParser(description='模型下载')
    parser.add_argument('--max_workers', type=int, default=4, )
    parser.add_argument('--cache_dir', type=str, default="./")
    parser.add_argument('--model_ids', type=str, default="iic/nlp_bert_entity-embedding_chinese-base", )
    args = parser.parse_args()
    main(args.model_ids,args.cache_dir,args.max_workers)

 3、执行脚本

python script.py --model_ids  iic/nlp_bert_entity-embedding_chinese-base

 

posted @ 2024-06-24 10:40  小白啊小白,Fighting  阅读(303)  评论(0编辑  收藏  举报