Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Add NPU support #1419

Merged
merged 18 commits into from
Jan 6, 2025
Merged

feat:Add NPU support #1419

merged 18 commits into from
Jan 6, 2025

Conversation

myhloli
Copy link
Collaborator

@myhloli myhloli commented Jan 6, 2025

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Please describe the motivation of this PR and the goal you want to achieve through this PR.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

Does the modification introduce changes that break the backward compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here and update the documentation.

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects.
  • CLA has been signed and all committers have signed the CLA in this PR.

- Add NPU support for memory cleaning and model initialization
- Optimize table model initialization and prediction process
- Update memory utils to support NPU
- Add language parameter for table model
- Update clean_memory function to support both CUDA and NPU devices
- Implement get_device function to centralize device selection logic
- Modify model initialization and memory cleaning to use the selected device
- Update RapidTableModel to support both RapidOCR and PaddleOCR engines
- Add openai package to requirements-docker.txt
- Remove upper version limit for pydantic dependency
- This change allows for the use of the latest pydantic version
- Update `clean_memory.py` to use `torch_npu.npu` instead of `torch.npu`
- Update `model_utils.py` to use `torch_npu.npu` instead of `torch.npu`
- Simplify NPU availability check and bfloat16 support in `pdf_parse_union_core_v2.py`
- Remove use_npu variable initialization
- Comment out device assignment and npu check
- Comment out use_npu parameter in ModifiedPaddleOCR constructor
…xtraction

- Update the logic for inserting spaces between characters- Consider the next character's position instead of the previous one
- Adjust the spacing threshold to 25% of the average character width
- Ignore spaces at the end of lines to prevent double spaces
- Implement ONNXModelSingleton to manage ONNX models
- Modify ModifiedPaddleOCR to use ONNX models on ARM CPUs without CUDA
- Update RapidTableModel to use RapidOCR with ONNXRuntime on CPU
- Add rapidocr_onnxruntime dependency in setup.py
- Remove logger.info() call for additional_ocr_params to reduce log verbosity
- Add missing 'else' statement in OCR model selection logic
- Ensure consistent formatting of 'if' statements for better readability
- Remove unnecessary empty line in the 'app.py' file
… code formatting- Remove extra space in conditional statement for character spacing logic

- Adjust spacing in trigonometric checks for line direction- Improve overall code readability and consistency
- Add `draw_char_bbox` function to `draw_bbox.py` for drawing character bounding boxes
- Integrate `draw_char_bbox` into `common.py` for use in PDF processing pipeline
- Include option to draw character bounding boxes in debug mode
- Add section for using NPU acceleration in both English and Chinese README files
- Update system requirements to include CANN environment for NPU support
- Enhance the "Quick Start" guide with NPU-related information- Modify hardware requirements to specify "Ascend 910b" for NPU acceleration
- Add Dockerfile for global setup with Ubuntu base image
- Add Dockerfile for Huawei NPU setup with Ascend base image
- Update requirements file structure:  - Rename requirements-docker.txt to docker/china/requirements.txt - Add new requirements files for global and Huawei NPU setups
- Install necessary packages and dependencies in both Dockerfiles- Set up virtual environment and install Python packages
- Download models and configure magic-pdf for both setups
- Update Dockerfiles in china, global, and huawei_npu directories
- Improve wget commands by specifying output file names
- Update READMEs to reflect new Dockerfile locations
- Update package sources to use Aliyun mirrors for faster downloads
- Upgrade pip and install Python packages in virtual environment
- Add python3.10-dev package to Huawei NPU Dockerfile
- Update requirements file URLs to master branch- Install specific version of torch_npu in Huawei NPU Dockerfile
- Update magic-pdf installation method
- Improve modelscope installation process
- Optimize model download and configuration update steps
@myhloli myhloli merged commit a8831ba into opendatalab:dev Jan 6, 2025
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant