# Accelerate doesn't seem to use my GPU?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952%3E%5C
**Category:** 🤗Accelerate\
**Created:** [April 3, 2024, 9:10am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952 "2024-04-03T09:10:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mihaien](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mihaien](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmihaien)%5C
**Post date:** [April 3, 2024, 9:10am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952%2F1 "2024-04-03T09:10:26Z")

</div>

Hi,

I’m trying to run the following example script [diffusers/examples/unconditional\_image\_generation/train\_unconditional.py at main · huggingface/diffusers · GitHub](https://github.com/huggingface/diffusers/blob/main/examples/unconditional_image_generation/train_unconditional.py) for training stable diffusion model on my dataset. I followed all the steps like in the tutorial and I configured Accelerate as following:

In which compute environment are you running?  
Please select a choice using the arrow or number keys, and selecting with enter

- This machine  
Which type of machine are you using?  
Please select a choice using the arrow or number keys, and selecting with enter
- No distributed training  
Do you want to run your training on CPU only (even if a GPU / Apple Silicon / Ascend NPU device is available)? [yes/NO]:NO  
Do you wish to optimize your script with torch dynamo?[yes/NO]:NO  
Do you want to use DeepSpeed? [yes/NO]: NO  
What GPU(s) (by id) should be used for training on this machine as a comma-seperated list? [all]:[all]  
Do you wish to use FP16 or BF16 (mixed precision)?  
Please select a choice using the arrow or number keys, and selecting with enter
- no

When running accelerate env in the terminal:  
Copy-and-paste the text below in your GitHub issue

- `Accelerate` version: 0.28.0
- Platform: Windows-10-10.0.19045-SP0
- Python version: 3.10.9
- Numpy version: 1.26.3
- PyTorch version (GPU?): 2.2.2+cu118 (True)
- PyTorch XPU available: False
- PyTorch NPU available: False
- System RAM: 13.86 GB
- GPU type: NVIDIA GeForce GTX 1650 (ignore my poor GPU XD, i’m a student and a begginer in ML)
- `Accelerate` default config:  
- compute\_environment: LOCAL\_MACHINE  
- distributed\_type: NO  
- mixed\_precision: no  
- use\_cpu: False  
- debug: False  
- num\_processes: 1  
- machine\_rank: 0  
- num\_machines: 1  
- gpu\_ids: [all]  
- rdzv\_backend: static  
- same\_network: True  
- main\_training\_function: main  
- downcast\_bf16: no  
- tpu\_use\_cluster: False  
- tpu\_use\_sudo: False  
- tpu\_env: 

But when I launch the script using the command in the tutorial, I see that Accelerate is not using my GPU, but the CPU:  
accelerate launch train\_unconditional.py --dataset\_name=“mihaien/my-dataset” --resolution=64 --center\_crop  
–random\_flip --output\_dir=“ddpm-metaphors-64” --train\_batch\_size=16 --num\_epochs=50 --gradient\_accumulation\_steps=1 --use\_ema --learning\_rate=1e-4 --lr\_warmup\_steps=500 --mixed\_p  
recision=no --push\_to\_hub  
04/03/2024 12:05:07 - INFO - **main** - Distributed environment: NO  
Num processes: 1  
Process index: 0  
Local process index: 0  
Device: cpu

Mixed precision type: no

I also tried a solution that I found, but it doesn’t seem to work for me: [Accelerate on single GPU doesnt seem to work - #2 by xtcgoat](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-on-single-gpu-doesnt-seem-to-work%2F39900%2F2)

PS: I’m using PyCharm.

Could someone please help me? Thank you so much!

---

<div class="post-metadata">

**Author:** ![swtb](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@swtb](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fswtb)%5C
**Post date:** [April 4, 2024, 10:00am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952%2F2 "2024-04-04T10:00:26Z")

</div>

Do you have torch built for GPU?  
Do you have the right CUDA and CUDAnn libraries installed?  
Below is for the GPU build of torch using CUDA 12.1

```auto
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

```

- GPU type: NVIDIA GeForce GTX 1650 (ignore my poor GPU XD, i’m a student and a begginer in ML)

By the way, Google Colab is free to use and comes with a 16GB GPU. Alternatively, as you mentioned you are a student, you may find that your institution or even a local institution will allow you access to their High Performance Computing environment. Most Universities and Colleges have some form of GPU Cluster.

---

<div class="post-metadata">

**Author:** ![mihaien](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mihaien](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmihaien)%5C
**Post date:** [April 4, 2024, 12:11pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952%2F3 "2024-04-04T12:11:34Z")

</div>

Yes, I installed CUDA and CUDAnn libraries for 11.8 version (as suggested in the post I have put in my post). I also ran the command from the pytorch site: pip3 install torch torchvision torchaudio --index-url [https://download.pytorch.org/whl/cu118](https://download.pytorch.org/whl/cu118)  
I have some resources at my university, but I firstly I have to see if everything works as expected on my local computer and that I don’t have any errors or problems because the resources that I have access to are limited.  
I tried to print to the console if cuda is available, so when I simply run the script from the pycharm torch.cuda.is\_avaiable() prints true, but if I launch the script with accelerate, the torch.cuda.is\_avaiable() will print false.  
Should I upgrade the version of CUDA to 12.1?

---

<div class="post-metadata">

**Author:** ![swtb](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@swtb](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fswtb)%5C
**Post date:** [April 4, 2024, 3:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952%2F4 "2024-04-04T15:27:40Z")

</div>

I would think accelerate would give a more descriptive error if the versioning was the problem. Try launching like this:

```auto
CUDA_VISIBLE_DEVICES=0 accelerate launch train_script.py

```

(With your config too)

---

<div class="post-metadata">

**Author:** ![muellerzr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/muellerzr/32/21583_2.png) [@muellerzr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmuellerzr)%5C
**Post date:** [April 4, 2024, 4:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952%2F5 "2024-04-04T16:32:16Z")

</div>

Might be the same as [Cuda becomes unavailable and script is excuted by multiple times · Issue #2622 · huggingface/accelerate · GitHub](https://github.com/huggingface/accelerate/issues/2622)? Are you using conda?

---

<div class="post-metadata">

**Author:** ![mihaien](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mihaien](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmihaien)%5C
**Post date:** [April 4, 2024, 7:16pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952%2F6 "2024-04-04T19:16:21Z")

</div>

This worked for me!! Thank you so much!!

---

<div class="post-metadata">

**Author:** ![swtb](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@swtb](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fswtb)%5C
**Post date:** [April 5, 2024, 12:44pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952%2F7 "2024-04-05T12:44:18Z")

</div>

Glad it worked.

If you manage to get set up on your universities compute environment you will likely end up using SLURM for job submission. At this point you can export the CUDA\_VISIBLE\_DEVICES=0 as an environment variable

for me that looks like:

```auto
export CUDA_VISIBLE_DEVICES="0"

python main.py

```

---

<div class="post-metadata">

**Author:** ![GangTu](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@GangTu](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FGangTu)%5C
**Post date:** [September 18, 2024, 1:42pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerate-doesnt-seem-to-use-my-gpu%2F79952%2F8 "2024-09-18T13:42:20Z")

</div>

I solved this by adding the parameter ‘device=“cuda”’ to the pipeline function call.`classifier = pipeline('sentiment-analysis', device="cuda")`
