1.7 KiB
Raw Blame History

魔搭环境配置

核心信息

  • 高带宽机器推荐命令行下载,支持断电断续和高速下载

环境安装

pip install modelscope

模型下载

命令行下载(推荐)

modelscope download --model="Qwen/Qwen2.5-0.5B-Instruct" --local_dir ./model-dir

SDK 下载

from modelscope import snapshot_download model_dir = snapshot_download("Qwen/Qwen2.5-0.5B-Instruct")

Git LFS 下载

git lfs install
git clone https://www.modelscope.cn/Qwen/Qwen2.5-0.5B-Instruct.git

模型加载

AutoModel

ModelScope 支持原生 pipeline 推理同时也兼容了由TransformersDiffusers等提供的AutoModel和Pipeline的加载

pip install transformers
from modelscope import AutoModelForCausalLM, AutoTokenizer 

model_name = "Qwen/Qwen2.5-0.5B-Instruct"

model = AutoModelForCausalLM.from_pretrained( 
	model_name, 
	torch_dtype="auto", 
	device_map="auto" 
) 
tokenizer = AutoTokenizer.from_pretrained(model_name)

使用 ModelScope pipeline 加载模型

from modelscope.pipelines import pipeline 
word_segmentation = pipeline('word-segmentation',model='damo/nlp_structbert_word-segmentation_chinese-base')

模型推理

from modelscope.pipelines import pipeline from modelscope.utils.constant import Tasks inference_pipeline = pipeline( task=Tasks.auto_speech_recognition, model='iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch', model_revision="v2.0.4") rec_result = inference_pipeline('https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_vad_punc_example.wav') print(rec_result)