deepseek-ai / deepseek-ai/DeepSeek-OCR-2

Fine-tuning DeepSeek-OCR-2 with ms-swift

Open
#11 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
3.4k
Forks
306
PR merge metrics
No merged PRs in 30d

Description

Thanks for your awesome contribution!

[ms-swift](https://github.com/modelscope/ms-swift/tree/main) now support DeepSeek-OCR-2 model
Install the ms-swift main branch to try it out.

```
# follow https://github.com/deepseek-ai/DeepSeek-OCR-2#install

git clone https://github.com/modelscope/ms-swift.git
cd ms-swift
pip install -e .

pip install transformers==4.46.0
```

### Inference

```bash
CUDA_VISIBLE_DEVICES=0 swift infer --model deepseek-ai/DeepSeek-OCR-2
```

> \ OCR:
> Input an image path or URL <<< http://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/ocr.png

```text
# 简介

SWIFT支持250+ LLM和35+ MLLM(多模态大模型)的训练、推理、评测和部署。开发者可以直接将我们的框架应用到自己的Research和生产环境中,实现模型训练评测到应用的完整链路。我们除支持PEFT提供的轻量训练方案外,也提供了一个完整的Adapters库以支持最新的训练技术,如NEFTune、LoRA+、LLaMA-PRO等,这个适配器库可以脱离训练脚本直接使用在自己的自定流程中。

为方便不熟悉深度学习的用户使用,我们提供了一个Gradio的web-ui用于控制训练和推理,并提供了配套的深度学习课程和最佳实践供新手入门。

此外,我们也在拓展其他模态的能力,目前我们支持了AnimateDiff的全参数训练和LoRA训练。

SWIFT具有丰富的文档体系,如有使用问题请查看这里。

可以在Huggingface space 和 ModelScope创空间 中体验SWIFT web-ui功能了
```

### Fine-tuning
```bash
# 16G
CUDA_VISIBLE_DEVICES=0 \
swift sft \
--model deepseek-ai/DeepSeek-OCR-2 \
--dataset AI-ModelScope/LaTeX_OCR:human_handwrite#2000 \
--split_dataset_ratio 0.01 \
--tuner_type lora \
--torch_dtype bfloat16 \
--num_train_epochs 1 \
--per_device_train_batch_size 4 \
--per_device_eval_batch_size 2 \
--learning_rate 1e-4 \
--lora_rank 8 \
--lora_alpha 32 \
--target_modules all-linear \
--freeze_vit false \
--freeze_aligner false \
--gradient_checkpointing true \
--max_pixels 802816 \
--gradient_checkpointing_kwargs '{"use_reentrant": false}' \
--attn_impl flash_attn \
--gradient_accumulation_steps 16 \
--logging_steps 5 \
--max_length 4096 \
--output_dir output \
--warmup_ratio 0.05 \
--dataloader_num_workers 4
```

Image

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.