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

Enable pyTorch-IMage-Models (TIMM) with HPUs #1459

Merged
merged 34 commits into from
Dec 3, 2024

Conversation

ZhengHongming888
Copy link
Contributor

What does this PR do?

This PR contains the scripts that showcases how to inference/fine-tune the TIMM models on intel's HPUs with the lazy/graph modes. We support the training for single/multiple HPU cards both two. Currently we support several most downloadable models from Hugging Face as below list.

Here we support the below features:

  1. Single-HPU training
    Here we show how to fine-tune the imagenette2-320 dataset and model with timm/resnet50.a1_in1k from Hugging Face.
  1. training with hpu lazy mode
python train_hpu_lazy.py \
    --data-dir ./imagenette2-320/ \
    --device 'hpu' \
    --model resnet50.a1_in1k
  1. training with hpu graph mode
python train_hpu_graph.py \
    --data-dir ./imagenette2-320/ \
    --device 'hpu' \
    --model resnet50.a1_in1k
  1. Multi-HPU training
  1. training with hpu lazy mode
torchrun --nnodes 1 --nproc_per_node 2 \
    train_hpu_lazy.py \
    --data-dir ./imagenette2-320/ \
    --device 'hpu' \
    --model resnet50.a1_in1k
  1. training with hpu graph mode
torchrun --nnodes 1 --nproc_per_node 2 \
    train_hpu_graph.py \
    --data-dir ./imagenette2-320/ \
    --device 'hpu' \
    --model resnet50.a1_in1k
  1. Single HPU inference
  1. hpu with graph_mode
python inference.py \
    --data-dir='./download_ds/imagenette2-320' \
    --device='hpu' \
    --model resnet50.a1_in1k \
    --graph_mode
  1. hpu with lazy mode
python inference.py \
    --data-dir='./download_ds/imagenette2-320' 
    --device='hpu' \
    --model resnet50.a1_in1k

Welcome for any suggestions/comments. Thanks.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@libinta libinta added the run-test Run CI for PRs from external contributors label Nov 25, 2024
Copy link

The code quality check failed, please run make style.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
examples/pytorch-image-models/README.md Outdated Show resolved Hide resolved
@regisss
Copy link
Collaborator

regisss commented Nov 28, 2024

@ZhengHongming888 Can you add a link to the scripts these examples are inspired of please? You can put it in the docstring at the beginning of each file

@ZhengHongming888
Copy link
Contributor Author

@ZhengHongming888 Can you add a link to the scripts these examples are inspired of please? You can put it in the docstring at the beginning of each file

@regisss updated please check! Thanks.

Copy link
Collaborator

@regisss regisss left a comment

Choose a reason for hiding this comment

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

Finally can you create a test_timm.py file in https://github.com/huggingface/optimum-habana/tree/main/tests where you quickly test the example scripts please?
For example just running a few training/inference steps to make sure the examples work.

@ZhengHongming888
Copy link
Contributor Author

Finally can you create a test_timm.py file in https://github.com/huggingface/optimum-habana/tree/main/tests where you quickly test the example scripts please? For example just running a few training/inference steps to make sure the examples work.

Thanks @regisss Done please check! Thanks.

Copy link
Collaborator

@regisss regisss left a comment

Choose a reason for hiding this comment

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

LGTM!

@regisss regisss merged commit 5485726 into huggingface:main Dec 3, 2024
4 checks passed
@ZhengHongming888
Copy link
Contributor Author

LGTM!

@regisss @libinta Thanks much for your time on review!!

regisss added a commit that referenced this pull request Dec 3, 2024
Liangyx2 pushed a commit to HabanaAI/optimum-habana-fork that referenced this pull request Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-test Run CI for PRs from external contributors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants