Skip to content

Commit 35d4b8c

Browse files
authored
[Cherry-Pick][NPU] Refine doc (#774) (#775)
1. refine doc 2. make typehint compatible with python3.9
1 parent 3f7ea90 commit 35d4b8c

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

paddlemix/examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ paddlemix `examples` 目录下提供模型的一站式体验,包括模型推
1717
| [groundingdino](./groundingdino/) ||| 🚧 ||||
1818
| [imagebind](./imagebind/) |||||||
1919
| [InternLM-XComposer2](./internlm_xcomposer2/) |||||||
20-
| [Internvl2](./internvl2/) |||||| |
20+
| [Internvl2](./internvl2/) |||||| |
2121
| [llava](./llava/) ||||| 🚧 ||
2222
| [llava-next](./llava_next_interleave/) |||||||
2323
| [minigpt4](./minigpt4) |||||||

paddlemix/examples/llava/README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,35 @@ python paddlemix/tools/supervised_finetune.py paddlemix/config/llava/v1_5/lora_s
104104
python paddlemix/tools/supervised_finetune.py paddlemix/config/llava/v1_5/sft_argument.json
105105
```
106106

107-
## 5 NPU硬件训练
108-
请参照[tools](../../tools/README.md)进行NPU硬件Paddle安装和环境变量设置,配置完成后可直接执行微调命令进行训练或预测。
107+
## 6 NPU硬件训练
108+
请参照[tools](../../tools/README.md)进行NPU硬件Paddle安装和环境变量设置。执行预测和训练前需要设置如下环境变量:
109+
```shell
110+
export ASCEND_RT_VISIBLE_DEVICES=8
111+
export FLAGS_npu_storage_format=0
112+
export FLAGS_use_stride_kernel=0
113+
export FLAGS_npu_jit_compile=0
114+
export FLAGS_npu_scale_aclnn=True
115+
export FLAGS_npu_split_aclnn=True
116+
export FLAGS_allocator_strategy=auto_growth
117+
export CUSTOM_DEVICE_BLACK_LIST=set_value,set_value_with_tensor
118+
```
119+
120+
预测:
121+
```shell
122+
python paddlemix/examples/llava/run_predict_multiround.py \
123+
--model-path "paddlemix/llava/llava-v1.6-7b" \
124+
--image-file "https://bj.bcebos.com/v1/paddlenlp/models/community/GroundingDino/000000004505.jpg" \
125+
--fp16
126+
```
127+
微调:
128+
```shell
129+
# llava lora微调
130+
python paddlemix/tools/supervised_finetune.py paddlemix/config/llava/v1_5/lora_sft_argument.json
131+
132+
# llava full参数微调
133+
python paddlemix/tools/supervised_finetune.py paddlemix/config/llava/v1_5/sft_argument.json
134+
```
135+
109136

110137
### 参考文献
111138
```BibTeX

paddlemix/processors/qwen2_vl_processing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def smart_resize(
667667
return h_bar, w_bar
668668

669669

670-
def fetch_image(ele: dict[str, str | Image.Image], size_factor: int = IMAGE_FACTOR) -> Image.Image:
670+
def fetch_image(ele: dict[str, Union[str, Image.Image]], size_factor: int = IMAGE_FACTOR) -> Image.Image:
671671
if "image" in ele:
672672
image = ele["image"]
673673
else:
@@ -715,7 +715,7 @@ def fetch_image(ele: dict[str, str | Image.Image], size_factor: int = IMAGE_FACT
715715
def smart_nframes(
716716
ele: dict,
717717
total_frames: int,
718-
video_fps: int | float,
718+
video_fps: Union[int, float],
719719
) -> int:
720720
"""calculate the number of frames for video used for model inputs.
721721
@@ -850,7 +850,7 @@ def gaussian_kernel_1d(size, sigma):
850850
kernel = np.exp(-x**2 / (2 * sigma**2))
851851
return kernel / kernel.sum()
852852

853-
def fetch_video(ele: dict, image_factor: int = IMAGE_FACTOR) -> paddle.Tensor | list[Image.Image]:
853+
def fetch_video(ele: dict, image_factor: int = IMAGE_FACTOR) -> Union[paddle.Tensor, list[Image.Image]]:
854854
if isinstance(ele["video"], str):
855855
video_reader_backend = get_video_reader_backend()
856856

@@ -902,7 +902,7 @@ def fetch_video(ele: dict, image_factor: int = IMAGE_FACTOR) -> paddle.Tensor |
902902
return images
903903

904904

905-
def extract_vision_info(conversations: list[dict] | list[list[dict]]) -> list[dict]:
905+
def extract_vision_info(conversations: Union[list[dict], list[list[dict]]]) -> list[dict]:
906906
vision_infos = []
907907
if isinstance(conversations[0], dict):
908908
conversations = [conversations]
@@ -921,8 +921,8 @@ def extract_vision_info(conversations: list[dict] | list[list[dict]]) -> list[di
921921

922922

923923
def process_vision_info(
924-
conversations: list[dict] | list[list[dict]],
925-
) -> tuple[list[Image.Image] | None, list[paddle.Tensor | list[Image.Image]] | None]:
924+
conversations: Union[list[dict], list[list[dict]]],
925+
) -> tuple[Union[list[Image.Image], None, list[Union[paddle.Tensor, list[Image.Image]]], None]]:
926926
vision_infos = extract_vision_info(conversations)
927927
image_inputs = []
928928
video_inputs = []

paddlemix/tools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PaddleMIX工具箱秉承了飞桨套件一站式体验、性能极致、生态
1818
| [groundingdino](./groundingdino/) | 🚧 ||||
1919
| [imagebind](./imagebind/) |||||
2020
| [InternLM-XComposer2](./internlm_xcomposer2/) |||||
21-
| [Internvl2](./internvl2/)|||| |
21+
| [Internvl2](./internvl2/)|||| |
2222
| [llava](./llava/) ||| 🚧 ||
2323
| [llava-next](./llava_next_interleave/) |||||
2424
| [minigpt4](./minigpt4) |||||

0 commit comments

Comments
 (0)