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!: New API for models initialization with accelerators parameters. Use HF implementation for LayoutPredictor. Migrate models to safetensors format. #50

Merged
merged 40 commits into from
Dec 11, 2024

Conversation

nikos-livathinos
Copy link
Collaborator

This PR includes the following tasks:

  • Export the LayoutModel pickle checkpoint into HuggingFace safe tensors format.
  • Implement a new version of LayoutPredictor that uses the HF API and safe tensors checkpoint.
  • Ensure that the predictions of the old torch.jit implementation and the new HF + safe tensors are the same (labels, bboxes).
  • Ensure support for AI accelerator devices (CUDA, MPS).
  • Introduce new tests.
  • Update the demo for the LayoutPredictor to use the safe tensors implementation and improve the output.

Links:
https://huggingface.co/docs/transformers/model_doc/rt_detr

Checklist:

  • Commit Message Formatting: Commit titles and messages follow guidelines in the
    conventional commits.
  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

cau-git and others added 12 commits November 1, 2024 08:09
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
…layout_predictor_jit.py

The safe tensors version is the layout_predictor.py

Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
…text files with the predictions

Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
… num_threads. Remove envvars.

Update unit tests.

Signed-off-by: Nikos Livathinos <[email protected]>
@PeterStaar-IBM PeterStaar-IBM marked this pull request as draft November 18, 2024 09:01
…g. Improve demo_layout_predictor

Signed-off-by: Nikos Livathinos <[email protected]>
pyproject.toml Outdated
@@ -24,6 +24,8 @@ packages = [
python = "^3.9"
torch = "^2.2.2"
torchvision = "^0"
transformers = "^4.46.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RT-DETR was published in 4.42.0 would that be a good initial version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried it with 4.42.0 and it seems to work and pass the tests. I guess we can lower the version.

pyproject.toml Outdated
@@ -24,6 +24,8 @@ packages = [
python = "^3.9"
torch = "^2.2.2"
torchvision = "^0"
transformers = "^4.46.2"
accelerate = "^1.1.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't seem to be imported. do we need it?

Copy link
Collaborator Author

@nikos-livathinos nikos-livathinos Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The accelerate module is used internally by the HF RT-DETR implementation and we need to install it, otherwise we receive an error message to do it.
I have refactored the code so that the accelerate package is not needed.

cau-git and others added 12 commits December 10, 2024 19:19
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
…ests.

Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
Signed-off-by: Nikos Livathinos <[email protected]>
Signed-off-by: Christoph Auer <[email protected]>
@cau-git cau-git changed the title feat!: Migrate the LayoutModel to the HF implementation feat!: Port layout model to HF transformers, use safetensors everywhere Dec 10, 2024
@cau-git cau-git marked this pull request as ready for review December 10, 2024 18:45
cau-git
cau-git previously approved these changes Dec 10, 2024
Copy link
Contributor

@cau-git cau-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cau-git cau-git changed the base branch from release_v3 to main December 10, 2024 18:46
@cau-git cau-git dismissed their stale review December 10, 2024 18:46

The base branch was changed.

cau-git
cau-git previously approved these changes Dec 10, 2024
Copy link
Contributor

@cau-git cau-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Signed-off-by: Christoph Auer <[email protected]>
@cau-git cau-git requested a review from dolfim-ibm December 11, 2024 10:18
@nikos-livathinos nikos-livathinos changed the title feat!: Port layout model to HF transformers, use safetensors everywhere feat!: New API for models initialization. Use HF implementation for LayoutPreditor. Migrate models to safetensors format. Dec 11, 2024
@nikos-livathinos nikos-livathinos changed the title feat!: New API for models initialization. Use HF implementation for LayoutPreditor. Migrate models to safetensors format. feat!: New API for models initialization with accelerators parameters. Use HF implementation for LayoutPreditor. Migrate models to safetensors format. Dec 11, 2024
@nikos-livathinos nikos-livathinos changed the title feat!: New API for models initialization with accelerators parameters. Use HF implementation for LayoutPreditor. Migrate models to safetensors format. feat!: New API for models initialization with accelerators parameters. Use HF implementation for LayoutPredictor. Migrate models to safetensors format. Dec 11, 2024
@nikos-livathinos nikos-livathinos merged commit 04295b2 into main Dec 11, 2024
6 checks passed
@nikos-livathinos nikos-livathinos deleted the nli/performance branch December 11, 2024 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants