Skip to content

Commit 3bb0ffe

Browse files
authored
Merge branch 'mindspore-lab:master' into master
2 parents 51e0811 + 36ba09f commit 3bb0ffe

353 files changed

Lines changed: 117251 additions & 2542 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ image.save("sd3.png")
5656
| :--- | :--- | :---: | :---: | :---: | :-- |
5757
| Image-to-Video | [hunyuanvideo-i2v](https://github.com/mindspore-lab/mindone/blob/master/examples/hunyuanvideo-i2v) 🔥🔥 || ✖️ | ✖️ | Tencent |
5858
| Text/Image-to-Video | [wan2.1](https://github.com/mindspore-lab/mindone/blob/master/examples/wan2_1) 🔥🔥🔥 || ✖️ | ✖️ | Alibaba |
59+
| Text/Image/Speech-to-Video | [wan2.2](https://github.com/mindspore-lab/mindone/blob/master/examples/wan2_2) 🔥🔥🔥 || ✖️ | ✖️ | Alibaba |
5960
| Text-to-Image | [cogview4](https://github.com/mindspore-lab/mindone/blob/master/examples/cogview) 🔥🔥🔥 || ✖️ | ✖️ | Zhipuai |
6061
| Text-to-Video | [step_video_t2v](https://github.com/mindspore-lab/mindone/blob/master/examples/step_video_t2v) 🔥🔥 || ✖️ | ✖️ | StepFun |
6162
| Image-Text-to-Text | [qwen2_vl](https://github.com/mindspore-lab/mindone/blob/master/examples/qwen2_vl) 🔥🔥🔥|| ✖️ | ✖️ | Alibaba |

docs/diffusers/api/pipelines/wan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<!-- Copyright 2024 The HuggingFace Team. All rights reserved.
22
#
3+
# This code is adapted from https://github.com/huggingface/diffusers
4+
# with modifications to run diffusers on mindspore.
5+
#
36
# Licensed under the Apache License, Version 2.0 (the "License");
47
# you may not use this file except in compliance with the License.
58
# You may obtain a copy of the License at
@@ -190,6 +193,8 @@ pipe = WanPipeline.from_pretrained("Wan-AI/Wan2.1-T2V-1.3B-Diffusers", transform
190193

191194
::: mindone.diffusers.WanImageToVideoPipeline
192195

196+
::: mindone.diffusers.WanVACEPipeline
197+
193198
::: mindone.diffusers.WanVideoToVideoPipeline
194199

195200
::: mindone.diffusers.pipelines.wan.pipeline_output.WanPipelineOutput
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import time
2+
3+
from transformers import AutoProcessor
4+
5+
import mindspore as ms
6+
7+
from mindone.transformers import AutoModelForImageTextToText
8+
9+
MODEL_HUB = "stepfun-ai/GOT-OCR-2.0-hf"
10+
IMAGE = "demo.png"
11+
12+
start = time.time()
13+
processor = AutoProcessor.from_pretrained(MODEL_HUB)
14+
print(f"Loaded processor in {time.time()-start:.4f}s")
15+
16+
start = time.time()
17+
model = AutoModelForImageTextToText.from_pretrained(
18+
MODEL_HUB,
19+
mindspore_dtype=ms.bfloat16,
20+
attn_implementation="eager",
21+
)
22+
print(f"Loaded model in {time.time()-start:.4f}s")
23+
24+
np_inputs = processor(IMAGE, return_tensors="np")
25+
inputs = {}
26+
for k, v in np_inputs.items():
27+
t = ms.Tensor(v)
28+
t = t.astype(ms.int32) if t.dtype == ms.int64 else t.astype(model.dtype)
29+
inputs[k] = t
30+
31+
start = time.time()
32+
generated_ids = model.generate(
33+
**inputs,
34+
do_sample=False,
35+
max_new_tokens=200,
36+
eos_token_id=processor.tokenizer.convert_tokens_to_ids("<|im_end|>"),
37+
pad_token_id=processor.tokenizer.pad_token_id,
38+
)
39+
print(f"Inference in {time.time()-start:.4f}s")
40+
41+
prompt_len = np_inputs["input_ids"].shape[1]
42+
out_ids = generated_ids[0].asnumpy()[prompt_len:]
43+
text = processor.decode(out_ids, skip_special_tokens=True)
44+
print(text)

examples/transformers/qwen2_5_omni/README.md

Lines changed: 77 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ The abstract from the [Qwen2.5-Omni Technical Report](https://arxiv.org/abs/2503
1313
## Requirements:
1414
|mindspore | ascend driver | firmware | cann tookit/kernel|
1515
|--- | --- | --- | --- |
16-
|2.5.0 | 24.1RC3 | 7.3.0.1.231 | 8.0.RC3.beta1|
16+
|2.6.0 | 24.1.RC3 | 7.5.T11.0 | 8.1.RC1|
17+
|2.7.0 | 24.1.RC3 | 7.5.T11.0 | 8.1.RC1|
1718

1819
### Installation
1920
```
@@ -23,15 +24,15 @@ pip install -r requirements.txt
2324
```
2425
### Model Checkpoints
2526

26-
`Qwen2.5-Omni-7B` chekpoint can be found on the [Huggingface Hub](https://huggingface.co/collections/Qwen/qwen25-omni-67de1e5f0f9464dc6314b36e).
27+
`Qwen2.5-Omni-7B`, `Qwen2.5-Omni-3B` checkpoints can be found on the [Huggingface Hub](https://huggingface.co/collections/Qwen/qwen25-omni-67de1e5f0f9464dc6314b36e).
2728

2829
The speakers checkpoint need to be converted before use:
2930
```python
3031
python mindone\transformers\models\qwen2_5_omni\convert_spk_dict_pt2np.py \
3132
--spk_path "Qwen/Qwen2.5-Omni-7B/spk_dict.pt" \
32-
--zip_spk_path"Qwen/Qwen2.5-Omni-7B/spk_dict.zip"
33+
--zip_spk_path "Qwen/Qwen2.5-Omni-7B/spk_dict.zip"
3334
```
34-
### Usage Examples
35+
### Inference Usage Examples
3536

3637

3738
Here are some usage chat examples and scripts with `mindone.transformers`:
@@ -41,13 +42,11 @@ Here are some usage chat examples and scripts with `mindone.transformers`:
4142
|[Universal Audio Understanding](universal_audio_understanding.py)| Speech recongnition, speech-to-text translation and audio analysis. |
4243
|[Voice Chatting](voice_chatting.py) | Chatting with Qwen2.5-Omni by voice input and output. |
4344
|[Video Information Extracting](video_information_extracting.py) | Obtaining information from the video stream. |
44-
[Multi Round Omni Chatting](multi_round_omni_chatting.py) |Conducted multiple rounds of audio and video dialogues with Qwen2.5-Omni to provide the most comprehensive ability demonstration.|
45-
46-
<!-- OOM:
45+
|[Multi Round Omni Chatting](multi_round_omni_chatting.py) |Conducted multiple rounds of audio and video dialogues with Qwen2.5-Omni to provide the most comprehensive ability demonstration.|
4746
|[Screen Recording Interaction](screen_recording_interaction.py) | Get the information and content you want to know by asking questions in real time on the recording screen. |
4847
|[Omni Chatting for Music](omni_chatting_for_music.py) | Chat with Qwen2.5-Omni about music content in a audio and video stream.|
4948
| [Omni Chatting for Math](omni_chatting_for_math.py) |Chat with Qwen2.5-Omni about math content in a audio and video stream.|
50-
|-->
49+
|
5150

5251
### Single Media inference
5352

@@ -142,12 +141,12 @@ conversation = [
142141
"content": [
143142
{
144143
"type": "video",
145-
"video": "/path/to/video.mp4"
146-
"max_pixels": 360 * 420,
147-
},
148-
{"type": "text", "text": "What cant you hear and see in this video?"},
149-
],
150-
},
144+
"video": "/path/to/video.mp4",
145+
"max_pixels": 360 * 420,
146+
},
147+
{"type": "text", "text": "What cant you hear and see in this video?"},
148+
],
149+
},
151150
]
152151

153152
# Preparation for inference
@@ -160,8 +159,7 @@ inputs = processor(text=text, audio=audios, images=images, videos=videos, return
160159

161160
# convert input to Tensor
162161
for key, value in inputs.items():
163-
if isinstance(value, np.ndarray):
164-
inputs[key] = ms.Tensor(value)
162+
inputs[key] = ms.Tensor(value)
165163
if inputs[key].dtype == ms.int64:
166164
inputs[key] = inputs[key].to(ms.int32)
167165
else:
@@ -358,22 +356,71 @@ model = Qwen2_5OmniForConditionalGeneration.from_pretrained(
358356
)
359357
```
360358

359+
### Finetuning
360+
361+
There are example scripts `finetune_lora_with_mindspore_trainer.py` and `finetune_lora_in_native_mindspore.py` for finetuning the model for OCR task with LoRA.
362+
Here's an example code for finetuning:
363+
```
364+
DEVICE_ID=0 python finetune_lora_with_mindspore_trainer.py \
365+
--model_path Qwen/Qwen2.5-Omni-3B \
366+
--lora_rank 8 \
367+
--lora_alpha 16 \
368+
--dataset_path linxy/LaTex_OCR \
369+
--output_dir ./outputs/lora \
370+
--num_train_epochs 1 \
371+
--learning_rate 1e-5 \
372+
--save_total_limit 1
373+
```
374+
or
375+
```
376+
DEVICE_ID=0 python finetune_lora_in_native_mindspore.py \
377+
--model_path Qwen/Qwen2.5-Omni-3B \
378+
--dataset_path linxy/LaTex_OCR \
379+
--enable_flash_attention \
380+
--lora_rank 8 \
381+
--lora_alpha 16 \
382+
--output_dir ./outputs/lora \
383+
--num_train_epochs 1
384+
```
385+
386+
361387
# Peformance
362388

363389
## Inference
364-
Experiments are tested on ascend 910* with mindspore 2.5.0 pynative mode.
390+
Experiments are tested on ascend 910* with mindspore 2.6.0 pynative mode.
365391

366-
|model| precision | task | resolution| FA | s/step | steps|
392+
|model| precision | task | resolution| fa | tokens/s | steps|
367393
|---|---|---|---|---|---|---|
368-
|Qwen2.5-Omni-7B| fp32 | pure text Q&A | N.A. | OFF | 0.20 | 21 |
369-
|Qwen2.5-Omni-7B| fp32 | video VQA w/ audio| 20x280x504 | OFF | 0.16 | 80 |
370-
|Qwen2.5-Omni-7B| bf16 | pure text Q&A | N.A. | OFF | 0.20 | 21 |
371-
|Qwen2.5-Omni-7B| bf16 | video VQA w/ audio| 20x280x504 | OFF | 0.20 | 89 |
372-
|Qwen2.5-Omni-7B| fp16 | pure text Q&A | N.A. | OFF | 0.22 | 21 |
373-
|Qwen2.5-Omni-7B| fp16 | video VQA w/ audio| 20x280x504 | OFF | 0.23 | 30 |
374-
|Qwen2.5-Omni-7B| bf16 | pure text Q&A | N.A. | ON | 0.18 | 21 |
375-
|Qwen2.5-Omni-7B| bf16 | video VQA w/ audio| 20x280x504 | ON | 0.17 | 32 |
376-
|Qwen2.5-Omni-7B| fp16 | pure text Q&A | N.A. | ON | 0.17 | 21 |
377-
|Qwen2.5-Omni-7B| fp16 | video VQA w/ audio| 20x280x504 | ON | 0.21 | 32 |
378-
379-
*note:apply mixed precision, `Conv3d` use fp16, `AvgPool1d` uses fp32.
394+
|Qwen2.5-Omni-7B| fp32 | pure text Q&A | N.A. | OFF | 1.88 | 22 |
395+
|Qwen2.5-Omni-7B| fp32 | video VQA w/ audio| 20x280x504 | OFF | 2.18 | 48 |
396+
|Qwen2.5-Omni-7B| bf16 | pure text Q&A | N.A. | OFF | 1.95 | 22 |
397+
|Qwen2.5-Omni-7B| bf16 | video VQA w/ audio| 20x280x504 | OFF | 1.78 | 48 |
398+
|Qwen2.5-Omni-7B| fp16 | pure text Q&A | N.A. | OFF | 1.87 | 22 |
399+
|Qwen2.5-Omni-7B| fp16 | video VQA w/ audio| 20x280x504 | OFF | 1.95 | 48 |
400+
|Qwen2.5-Omni-7B| bf16 | pure text Q&A | N.A. | ON | 4.77 | 22 |
401+
|Qwen2.5-Omni-7B| bf16 | video VQA w/ audio| 20x280x504 | ON | 5.93 | 48 |
402+
|Qwen2.5-Omni-7B| fp16 | pure text Q&A | N.A. | ON | 5.13 | 22 |
403+
|Qwen2.5-Omni-7B| fp16 | video VQA w/ audio| 20x280x504 | ON | 4.43 | 48 |
404+
405+
*note:apply mixed precision, `AvgPool1d` uses fp32.
406+
407+
## Finetuning
408+
Experiments are tested on ascend 910* with pynative mode.
409+
410+
- mindspore 2.6.0
411+
412+
|model| precision |amp| task | resolution| fa |card| batch size| max token| recompute | s/step |
413+
|---|---|---|---|---|---|---|---|---|---|---|
414+
|Qwen2.5-Omni-3B| fp32 |0| image VQA | 128x512 | ON | 1 | 1 | 4096 |OFF | 6.61 |
415+
|Qwen2.5-Omni-3B| fp32 |0| image VQA | 128x512 | ON | 2 | 1 | 4096 |OFF | 5.32 |
416+
417+
*note:apply mixed precision, `AvgPool1d` uses fp32.
418+
419+
- mindspore 2.7.0
420+
421+
|model| precision |amp| task | resolution| fa |card| batch size| max token| recompute | s/step |
422+
|---|---|---|---|---|---|---|---|---|---|---|
423+
|Qwen2.5-Omni-3B| bf16 |0| image VQA | 128x512 | ON | 1 | 1 | 4096 |OFF | 6.32 |
424+
425+
426+
*note:only mindspore >=2.7.0 supports bf16; apply mixed precision, `AvgPool1d` uses fp32.

0 commit comments

Comments
 (0)