# Accelerator not performing multi-gpu train in jupyter

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerator-not-performing-multi-gpu-train-in-jupyter%2F41190%3E%5C
**Category:** 🤗Accelerate\
**Created:** [May 28, 2023, 1:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerator-not-performing-multi-gpu-train-in-jupyter%2F41190 "2023-05-28T01:06:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon51616952](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@anon51616952](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fanon51616952)%5C
**Post date:** [May 28, 2023, 1:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerator-not-performing-multi-gpu-train-in-jupyter%2F41190%2F1 "2023-05-28T01:06:16Z")

</div>

I am trying to train the TimeSeries Transformer on multiple gpus from a jupyter notebook using the accelerator, but it always uses just one gpu. I’ve looked at and followed the available examples online, so I’m not sure what is wrong with the code (see below). Thanks in advance for any help.

accelerator = Accelerator()  
device = accelerator.device

optimizer = AdamW(model.parameters(), lr=6e-4, betas=(0.9, 0.95), weight\_decay=1e-1)

model, optimizer, train\_dataloader = accelerator.prepare(model, optimizer, train\_dataloader,)

model.train()  
for epoch in range(num\_epochs):  
for idx, batch in enumerate(train\_dataloader):  
optimizer.zero\_grad()  
outputs = model(  
static\_categorical\_features=batch[“static\_categorical\_features”].to(device)  
if config.num\_static\_categorical\_features \> 0  
else None,  
static\_real\_features=batch[“static\_real\_features”].to(device)  
if config.num\_static\_real\_features \> 0  
else None,  
past\_time\_features=batch[“past\_time\_features”].to(device),  
past\_values=batch[“past\_values”].to(device),  
future\_time\_features=batch[“future\_time\_features”].to(device),  
future\_values=batch[“future\_values”].to(device),  
past\_observed\_mask=batch[“past\_observed\_mask”].to(device),  
future\_observed\_mask=batch[“future\_observed\_mask”].to(device),  
)  
loss = outputs.loss

```
    # Backpropagation
    accelerator.backward(loss)
    optimizer.step()

    if idx % 100 == 0:
        print(loss.item())

```

---

<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:** [May 28, 2023, 1:42am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Faccelerator-not-performing-multi-gpu-train-in-jupyter%2F41190%2F2 "2023-05-28T01:42:18Z")

</div>

You need to ensure youre using the jupyter launcher:

> **[Launching Multi-GPU Training from a Jupyter Environment](https://huggingface.co/docs/accelerate/basic_tutorials/notebook)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.
