Skip to content

About

Multilingual Document Layout Parsing in a Single Vision-Language Model

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

dots.ocr API

本Fork提供Docker容器重新封装的API,支持20系等旧的 Turing GPU,以float32格式运行。测试机型:单2080ti 22GB。

This fork provides a Docker container re-packaged API that supports older Turing GPUs like the 20 series, running in float32 format. Test hardware: single 2080ti 22GB.

30系及以上显卡会默认使用bfloat,显存需求应该会减半(6-7GB显存),如果有问题可以设置环境变量TORCH_DTYPE=float32。我没有30系及以上显卡测试,有问题可以提issue告知。见ocr_api_server.py的第32行。

RTX 30 series and newer cards will use bfloat16 by default, which should halve memory requirements (6-7GB VRAM). If you encounter issues, set the environment variable TORCH_DTYPE=float32. I don't have RTX 30+ cards for testing, so please report issues. See line 32 in ocr_api_server.py.

Docker一键运行命令:(API端口为5000)API使用文档见API_Documentation.md。

Docker run command: (API port is 5000) API usage documentation is in API_Documentation.md.

# 对于20系显卡:  For 20 series(Turing or older):
docker run --name dots-ocr-container -d --runtime=nvidia --gpus=all -p 5000:5000 docker.io/am009/dots.ocr:latest
# 对于支持bfloat的30系以上的显卡:   For RTX 30 series and newer cards:
docker run --name dots-ocr-container -d --runtime=nvidia --gpus=all --entrypoint bash -p 5000:5000  docker.io/am009/dots.ocr:latest -c "sed -i 's/bf16=False/bf16=True/' /DotsOCR/weights/DotsOCR/modeling_dots_vision.py; /DotsOCR/start.sh"

配套静态PDF识别的网页界面:http://tool.latexdiff.cn https://tool.latexdiff.cn https://github.com/am009/LLM-online-tool

Companion static web interface for static PDF recognition: http://tool.latexdiff.cn https://tool.latexdiff.cn https://github.com/am009/LLM-online-tool

节约显存的同时,方便随时使用的方案:https://gist.github.com/am009/78989aa6597245c9444b9253e920ff64

GPU Memory-saving solution for convenient usage: https://gist.github.com/am009/78989aa6597245c9444b9253e920ff64

由于VLLM的token分割,图片的长和宽的像素数量最好要是28的倍数!!否则可能出现识别坐标略微错位的情况。文档转图片时,推荐使用200dpi。

Due to the token segmentation of VLLM, the pixel dimensions of the image's length and width should preferably be multiples of 28! Otherwise, there may be slight misalignment in the recognition coordinates. When converting documents to images, it is recommended to use 200 dpi.

本地运行

Local Development

  1. 配置环境。可以先尝试这里的代码,确保能跑起来。如果显存不足可以把图片再缩放小一点。

  2. Configure the environment. You can try the code here first to ensure it runs. If VRAM is insufficient, you can scale down the images further.

  3. 下载模型到weights/DotsOCR文件夹。

  4. Download the model to the weights/DotsOCR folder.

  • 如果是从ModelScope下载,注意根据这里修改sdpa相关注意力的实现。Huggingface的修改已经被合并进去了。

  • If downloading from ModelScope, note to modify the sdpa attention implementation according to here. The Huggingface changes have already been merged.

  • 模型文件中的config.json里面的attn_implementation改成sdpa

  • Change attn_implementation to sdpa in the config.json file of the model.

  • 将模型文件中的modeling_dots_vision.py里面的bf16=True改成False。

  • Change bf16=True to False in modeling_dots_vision.py in the model files.

References:

提升了基于"attn_implementation": "sdpa"的显存使用效率。现在显存占用应该只会在12GB多一点,大图片也不会出现暴涨的情况了。见:https://huggingface.co/rednote-hilab/dots.ocr/discussions/27/files 或者 https://modelscope.cn/models/rednote-hilab/dots.ocr/feedback/prDetail/44141 Huggingface的修改已经被合并进去了。

Improved memory efficiency based on "attn_implementation": "sdpa". Memory usage should now be just over 12GB, and large images won't cause memory spikes. See: https://huggingface.co/rednote-hilab/dots.ocr/discussions/27/files or https://modelscope.cn/models/rednote-hilab/dots.ocr/feedback/prDetail/44141 The Huggingface changes have been merged.

About

Multilingual Document Layout Parsing in a Single Vision-Language Model

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages