# Best practice to run DeepSpeed

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbest-practice-to-run-deepspeed%2F31682%3E%5C
**Category:** DeepSpeed\
**Created:** [February 14, 2023, 7:47am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbest-practice-to-run-deepspeed%2F31682 "2023-02-14T07:47:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shon711](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@shon711](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fshon711)%5C
**Post date:** [February 14, 2023, 7:47am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbest-practice-to-run-deepspeed%2F31682%2F1 "2023-02-14T07:47:43Z")

</div>

Hello,

While we train model with HuggingFace Trainer there are several ways to run the training with deepspeed.

We provide the deepspeed config to the trainer as follows (script name = `train.py`):

```auto
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

training_args = TrainingArguments(
    ...
    deepspeed='ds_config.json'
)

trainer = Trainer(
        model=model,
        tokenizer=tokenizer,
        args=training_args
)
trainer.train()

```

What is the best way to run that script?

```auto
1. python train.py
2. accelerate launch --config_file config.yaml train.py
3. deepspeed train.py

```

I found option number 3 to be the best since the other options just run out of memory. I suspect I am doing something wrong with options 1 and 2.

Any advice here?

Thanks,  
Shon

---

<div class="post-metadata">

**Author:** ![Kenkentron](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@Kenkentron](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FKenkentron)%5C
**Post date:** [August 6, 2023, 10:19pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbest-practice-to-run-deepspeed%2F31682%2F2 "2023-08-06T22:19:04Z")

</div>

Did you manage to find a good answer? I am having the same doubt what is the best thing to do.

Thanks!

---

<div class="post-metadata">

**Author:** ![SantoshScienceIO](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@SantoshScienceIO](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FSantoshScienceIO)%5C
**Post date:** [December 25, 2023, 1:53am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbest-practice-to-run-deepspeed%2F31682%2F3 "2023-12-25T01:53:45Z")

</div>

I’m also interested in the answer, though it’s my understanding so far that the first one probably won’t work.
