67 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 魔搭环境配置
## 核心信息
- 高带宽机器推荐命令行下载,支持断电断续和高速下载
## 环境安装
```bash
pip install modelscope
```
## 模型下载
### 命令行下载(推荐)
```bash
modelscope download --model="Qwen/Qwen2.5-0.5B-Instruct" --local_dir ./model-dir
```
### SDK 下载
```python
from modelscope import snapshot_download model_dir = snapshot_download("Qwen/Qwen2.5-0.5B-Instruct")
```
### Git LFS 下载
```bash
git lfs install
git clone https://www.modelscope.cn/Qwen/Qwen2.5-0.5B-Instruct.git
```
## 模型加载
### AutoModel
ModelScope 支持原生 pipeline 推理同时也兼容了由TransformersDiffusers等提供的AutoModel和Pipeline的加载
```bash
pip install transformers
```
```python
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 加载模型
```python
from modelscope.pipelines import pipeline
word_segmentation = pipeline('word-segmentation',model='damo/nlp_structbert_word-segmentation_chinese-base')
```
## 模型推理
```python
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)
```