# HuggingFace ViT 10x Slower than Native Tensorflow (Not Fully Using GPU?)

**URL:** <https://discuss.huggingface.co/t/huggingface-vit-10x-slower-than-native-tensorflow-not-fully-using-gpu/20445>\
**Category:** 🤗Transformers\
**Created:** [July 16, 2022, 12:01am UTC](https://discuss.huggingface.co/t/huggingface-vit-10x-slower-than-native-tensorflow-not-fully-using-gpu/20445 "2022-07-16T00:01:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewvk](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@andrewvk](https://discuss.huggingface.co/u/andrewvk)\
**Post date:** [July 16, 2022, 12:01am UTC](https://discuss.huggingface.co/t/huggingface-vit-10x-slower-than-native-tensorflow-not-fully-using-gpu/20445/1 "2022-07-16T00:01:53Z")

</div>

Any ideas what could be causing this?

I have been using another implementation of [ViT](https://github.com/faustomorales/vit-keras) and switching to the Transformers library with ‘google/vit-base-patch16-224-in21k’ it is training about 10x slower. It also takes almost 10 minutes for the epoch to move on.

Old:

 ![old](https://us1.discourse-cdn.com/hellohellohello/original/2X/a/a094717dcd8670aae359f9f418b37fc2fba401f5.png)  
CPU usage is around 15-25% and GPU is close to 100% most of training.

HF ViT:

 ![hf_vit](https://us1.discourse-cdn.com/hellohellohello/original/2X/9/90b548ae40c3e11a6f16134790c7bce4a45d12eb.png)  
CPU usage is similar but GPU is low and spikes to 25% or 50% or 100% very sporadically.

I tried to run them with as many of the same settings as possible. Larger batch size seems to result in less GPU usage for the HF ViT.

I think this might have to do with the image data loader (from this [tutorial](https://www.philschmid.de/image-classification-huggingface-transformers-keras)) not loading images as fast as the native Tensorflow ones, so the GPU cannot be fully utilized

Any help would be much appreciated.
