# Gpt-oss training on A100 - OOM error

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%3E%5C
**Category:** Beginners\
**Created:** [November 20, 2025, 8:26am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658 "2025-11-20T08:26:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![clementlr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/clementlr/32/3207_2.png) [@clementlr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fclementlr)%5C
**Post date:** [November 20, 2025, 8:26am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F1 "2025-11-20T08:26:53Z")

</div>

Dear community,

I am following OpenAI/HF cookbook to fine-tune gpt-oss:

[Fine-tuning with gpt-oss and Hugging Face Transformers](https://cookbook.openai.com/articles/gpt-oss/fine-tune-transfomers)

I tried training gpt-oss with A100 GPU that comes with 80 GB vRAM but got the below OOM error.

I already set my trl config as below to try to reduce memory pressure.

I appreciate your feedback.

training\_args = SFTConfig(

```
learning_rate=2e-4,

```

gradient\_checkpointing=True,

num\_train\_epochs=1,

logging\_steps=1,

per\_device\_train\_batch\_size=4,

gradient\_accumulation\_steps=4,

max\_length=1024,

warmup\_ratio=0.03,

lr\_scheduler\_type=“cosine\_with\_min\_lr”,

lr\_scheduler\_kwargs={“min\_lr\_rate”: 0.1},

output\_dir=“gpt-oss-20b-multilingual-reasoner”,

push\_to\_hub=True,

)

from trl import SFTTrainer

trainer = SFTTrainer(

model=peft\_model,

args=training\_args,

train\_dataset=dataset,

processing\_class=tokenizer,

)

trainer.train()

> > > trainer.train()

0%| | 0/63 [00:43\<?, ?it/s]

Traceback (most recent call last): | 0/63 [00:00\<?, ?it/s]

File “”, line 1, in

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/trainer.py”, line 2316, in train

```
return inner_training_loop(

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/trainer.py”, line 2674, in \_inner\_training\_loop

```
tr_loss_step = self.training_step(model, inputs, num_items_in_batch)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/trl/trainer/sft\_trainer.py”, line 1190, in training\_step

```
return super().training_step(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/trainer.py”, line 4020, in training\_step

```
loss = self.compute_loss(model, inputs, num_items_in_batch=num_items_in_batch)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/trl/trainer/sft\_trainer.py”, line 1103, in compute\_loss

```
(loss, outputs) = super().compute_loss(

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/trainer.py”, line 4110, in compute\_loss

```
outputs = model(\*\*inputs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1775, in \_wrapped\_call\_impl

```
return self.\_call_impl(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1786, in \_call\_impl

```
return forward_call(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/accelerate/utils/operations.py”, line 819, in forward

```
return model_forward(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/accelerate/utils/operations.py”, line 807, in \__call_\_

```
return convert_to_fp32(self.model_forward(\*args, \*\*kwargs))

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/amp/autocast\_mode.py”, line 44, in decorate\_autocast

```
return func(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/accelerate/utils/operations.py”, line 819, in forward

```
return model_forward(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/accelerate/utils/operations.py”, line 807, in \__call_\_

```
return convert_to_fp32(self.model_forward(\*args, \*\*kwargs))

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/amp/autocast\_mode.py”, line 44, in decorate\_autocast

```
return func(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/peft/peft\_model.py”, line 921, in forward

```
return self.get_base_model()(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1775, in \_wrapped\_call\_impl

```
return self.\_call_impl(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1786, in \_call\_impl

```
return forward_call(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/utils/generic.py”, line 918, in wrapper

```
output = func(self, \*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/models/gpt\_oss/modeling\_gpt\_oss.py”, line 668, in forward

```
outputs: MoeModelOutputWithPast = self.model(

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1775, in \_wrapped\_call\_impl

```
return self.\_call_impl(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1786, in \_call\_impl

```
return forward_call(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/utils/generic.py”, line 1064, in wrapper

```
outputs = func(self, \*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/models/gpt\_oss/modeling\_gpt\_oss.py”, line 507, in forward

```
hidden_states = decoder_layer(

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/modeling\_layers.py”, line 93, in \__call_\_

```
return self.\_gradient_checkpointing_func(partial(super().\__call_\_, \*\*kwargs), \*args)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/\_compile.py”, line 53, in inner

```
return disable_fn(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/\_dynamo/eval\_frame.py”, line 1044, in \_fn

```
return fn(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/utils/checkpoint.py”, line 496, in checkpoint

```
return CheckpointFunction.apply(function, preserve, \*args)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/autograd/function.py”, line 581, in apply

```
return super().apply(\*args, \*\*kwargs) # type: ignore\[misc\]

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/utils/checkpoint.py”, line 262, in forward

```
outputs = run_function(\*args)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1775, in \_wrapped\_call\_impl

```
return self.\_call_impl(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1786, in \_call\_impl

```
return forward_call(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/utils/deprecation.py”, line 172, in wrapped\_func

```
return func(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/models/gpt\_oss/modeling\_gpt\_oss.py”, line 371, in forward

```
hidden_states, \_ = self.self_attn(

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1775, in \_wrapped\_call\_impl

```
return self.\_call_impl(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1786, in \_call\_impl

```
return forward_call(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/utils/deprecation.py”, line 172, in wrapped\_func

```
return func(\*args, \*\*kwargs)

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/models/gpt\_oss/modeling\_gpt\_oss.py”, line 328, in forward

```
attn_output, attn_weights = attention_interface(

```

File “/home/user/.pyenv/versions/3.10.19/lib/python3.10/site-packages/transformers/models/gpt\_oss/modeling\_gpt\_oss.py”, line 253, in eager\_attention\_forward

```
attn_weights = torch.matmul(query, key_states.transpose(2, 3)) \* scaling

```

torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 512.00 MiB. GPU 0 has a total capacity of 79.25 GiB of which 401.88 MiB is free. Process 213371 has 78.85 GiB memory in use. Of the allocated memory 77.36 GiB is allocated by PyTorch, and 1011.53 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH\_CUDA\_ALLOC\_CONF=expandable\_segments:True to avoid fragmentation. See documentation for Memory Management ( [CUDA semantics — PyTorch 2.9 documentation](https://pytorch.org/docs/stable/notes/cuda.html#environment-variables) )

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [November 20, 2025, 6:05pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F2 "2025-11-20T18:05:35Z")

</div>

Perhaps [real OOM](https://huggingface.co/datasets/John6666/forum2/blob/main/gpt_oss_ft_a100_oom_1.md)?

---

<div class="post-metadata">

**Author:** ![DhineshR](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/dhineshr/32/55576_2.png) [@DhineshR](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FDhineshR)%5C
**Post date:** [November 20, 2025, 6:31pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F3 "2025-11-20T18:31:11Z")

</div>

Do you want to train in fp32 precision? If not required, try bf16 precision. I see ` convert_to_fp32` in the stack trace and hence this suggestion.

Also, make sure the training data shapes are as expected.

---

<div class="post-metadata">

**Author:** ![clementlr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/clementlr/32/3207_2.png) [@clementlr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fclementlr)%5C
**Post date:** [November 20, 2025, 9:41pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F4 "2025-11-20T21:41:26Z")

</div>

> [@DhineshR](#):
>
> convert\_to\_fp32

Dear DhineshR, thanks for your reply.

The convert\_to\_fp32 you mentioned is part of error message but I did not set such parameter.

The torch dtype of the model config is the one recommended in openAI cookbook:

import torch

from transformers import AutoModelForCausalLM, Mxfp4Config

quantization\_config = Mxfp4Config(dequantize=True)

model\_kwargs = dict(

attn\_implementation=“eager”,

torch\_dtype=torch.bfloat16,

quantization\_config=quantization\_config,

use\_cache=False,

device\_map=“auto”,

)

I appreciate your feedback.

model = AutoModelForCausalLM.from\_pretrained(“openai/gpt-oss-20b”, \*\*model\_kwargs)

---

<div class="post-metadata">

**Author:** ![DhineshR](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/dhineshr/32/55576_2.png) [@DhineshR](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FDhineshR)%5C
**Post date:** [November 21, 2025, 4:30am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F5 "2025-11-21T04:30:37Z")

</div>

Though not set explicitly, the stack trace shows at some point the tensors are converted to fp32.

You could try increasing the batch size by 1 starting from 1 and find the breaking point.

You could also calculate size of activations for your batch\_size, max\_length, and precision of training. And, check if there is enough space left in the GPU for activations after allocating required amount of memory for fine-tuning.

---

<div class="post-metadata">

**Author:** ![clementlr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/clementlr/32/3207_2.png) [@clementlr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fclementlr)%5C
**Post date:** [November 21, 2025, 1:43pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F6 "2025-11-21T13:43:03Z")

</div>

Dear **[DhineshR](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdhineshr)%2C** thanks for your feedback.

I try downsizing:

_per\_device\_train\_batch\_size=1, gradient\_accumulation\_steps=1,_

But still results in OOM error message.

I also tried to:

_model\_kwargs = dict(_

attn\_implementation=“eager”,

_torch\_dtype=torch.bfloat16,_

_quantization\_config=quantization\_config,_

_use\_cache=False,_

_#device\_map=“auto”,_

_)_

as I noticed warning info about model beeing on multiple device (although runnning on A100 single GPU) after:

_trainer = SFTTrainer(_

_… model=peft\_model,_

_… args=training\_args,_

_… train\_dataset=dataset,_

_… processing\_class=tokenizer,_

_… )_

_The model is already on multiple devices. Skipping the move to device specified in `args`._

But still result in OOM error.

Do you have other thought ?

Right now I am considering testing on H100 but not sure this will make it as VRAM is equal to 80 GB as well.

Kind regards

---

<div class="post-metadata">

**Author:** ![DhineshR](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/dhineshr/32/55576_2.png) [@DhineshR](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FDhineshR)%5C
**Post date:** [November 22, 2025, 8:00am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F7 "2025-11-22T08:00:23Z")

</div>

I’d suggest checking the number of GPUs you have and make sure they are as expected by running `nvidia-smi`.

If you want to only use one GPU, try setting CUDA\_VISIBLE\_DEVICES=0 environment variable when running the training script.

However, I believe 80GB is not enough to fientune gpt-oss 20B at bf16 precision. There are many guides available online that would help you estimate the amount of memory required to fine-tune. I’d suggest performing those calculations for your use case.

---

<div class="post-metadata">

**Author:** ![clementlr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/clementlr/32/3207_2.png) [@clementlr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fclementlr)%5C
**Post date:** [November 26, 2025, 5:35pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F8 "2025-11-26T17:35:14Z")

</div>

> [@DhineshR](#):
>
> CUDA\_VISIBLE\_DEVICES

Dear DhineshR, thanks for your feedback.  
In [OpenAI cookbook](https://cookbook.openai.com/articles/gpt-oss/fine-tune-transfomers) documentation they state that:

\*\*\*Note: This notebook is designed to be run on a single H100 GPU with 80GB of memory. If you have access to a smaller GPU, you can reduce the batch size and sequence length in the hyperparameters below.

* * *

I tried additional HW set up testing with **Nvidia H100** and **Nvidia 4xA10G large (which comes with 92 GB VRAM).** In both cases I still get OOM error.

Any other idea ? Tx

 ![H100](https://us1.discourse-cdn.com/hellohellohello/original/3X/3/d/3d30e78f632f33058b403637150ff53a845f1b04.png)

 ![H100-OOM](https://us1.discourse-cdn.com/hellohellohello/original/3X/6/2/6252b3e5b9ee26d05c6107990705fb7e57bf2e3d.png)

 ![A10G](https://us1.discourse-cdn.com/hellohellohello/original/3X/9/b/9bb141176d85df00802ace5ed37caa029e77f3a7.png)

 ![A10G-OOM](https://us1.discourse-cdn.com/hellohellohello/original/3X/f/c/fccc42aad78fdfb597cb29ffe0fef15d07f37921.png)

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [November 26, 2025, 11:18pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F9 "2025-11-26T23:18:24Z")

</div>

When considering the difference compared to the H100 GPU environment shown in OpenAI’s Notebook, the overhead of executing `torch.compile` might be the culprit. Next in line are differences in PyTorch, CUDA, or Transformers versions.

Either way, I think VRAM is quite tight and failures are likely to occur from even minor differences, so personally, I recommend using QLoRA.

* * *

## Main causes of OOM on a single H100

1. **You’re really doing BF16 LoRA on a 20B MoE, not FP4 training**

2. **Attention uses full L×L “eager” kernels**

3. **80GB H100 is “just enough”, so any extra overhead breaks it**

4. **This is a known pattern, not just your setup**

* * *

## Practical solutions / workarounds on a single H100

### A. Best fix: switch to an optimized QLoRA stack (Unsloth)

- Unsloth’s GPT-OSS guide: **gpt-oss-20B fine-tuning fits in ~14GB VRAM** ; they recommend ≥16GB for stable runs. ([Unsloth](https://unsloth.ai/blog/gpt-oss "Fine-tune gpt-oss with Unsloth"))
- Their key point: Unsloth keeps GPT-OSS in a quantized / optimized form and uses Flex Attention, cutting VRAM by ≈70–80% compared to BF16 LoRA.

If you can change stack, this is by far the cleanest fix: your H100 then has _massive_ headroom instead of being at the cliff edge.

### B. If you must stay on HF/TRL BF16 LoRA notebook

1. **Shrink “tokens per step” hard**

2. **Remove avoidable overhead**

3. **Consider better attention kernels on H100**

Even with all of this, BF16 LoRA on gpt-oss-20B will always be near the 80GB limit; QLoRA / Unsloth is the only way to make it “comfortable”.

* * *

## Key links

- OpenAI Cookbook – Fine-tuning gpt-oss with Transformers (original notebook, H100-80GB target) ([OpenAI Cookbook](https://cookbook.openai.com/articles/gpt-oss/fine-tune-transfomers "Fine-tuning with gpt-oss and Hugging Face Transformers"))
- Unsloth guide – “gpt-oss: How to run and fine-tune” (explains 65GB vs 14GB VRAM for 20B) ([Unsloth Docs](https://docs.unsloth.ai/models/gpt-oss-how-to-run-and-fine-tune "gpt-oss: How to Run & Fine-tune"))
- Zenn hardware outline for GPT-OSS fine-tuning (20B LoRA BF16 ≈ 60GB+ VRAM, QLoRA ≈ 14GB+) ([Zenn](https://zenn.dev/hiraoku/scraps/126ba194607f5e "OpenAI GPT-OSSファインチューニング実践手順書のアウトライン"))

---

<div class="post-metadata">

**Author:** ![clementlr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/clementlr/32/3207_2.png) [@clementlr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fclementlr)%5C
**Post date:** [November 27, 2025, 6:00am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgpt-oss-training-on-a100-oom-error%2F170658%2F10 "2025-11-27T06:00:44Z")

</div>

Dear John6666,

thanks for the heads up analysis your provided.

I was reading unsloth documentation yesterday so this is probably where I am going to look next.

I’ll update the thread while I will be able to run new tests.

Kind regards
