# Cuda memory error even when passing the no\_cuda argument

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcuda-memory-error-even-when-passing-the-no-cuda-argument%2F26588%3E%5C
**Category:** 🤗Transformers\
**Created:** [November 23, 2022, 1:52pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcuda-memory-error-even-when-passing-the-no-cuda-argument%2F26588 "2022-11-23T13:52:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rimusa](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rimusa/32/21498_2.png) [@rimusa](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frimusa)%5C
**Post date:** [November 23, 2022, 1:52pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcuda-memory-error-even-when-passing-the-no-cuda-argument%2F26588%2F1 "2022-11-23T13:52:05Z")

</div>

Hi, at my uni servers we don’t have much GPU capacity, so they end up being in constant use. This means that if I try to run a model when the GPUs are in use by someone else, I will get an out of memory error (`CUDA error: out of memory`).

Looking through the documentation, I saw that if I pass the argument `no_cuda=True` to the `TrainingArguments` for a `Trainer`, then it won’t be using GPUs anymore, even when they are available. However, once I do `trainer.predict(dataset)`, I still get the out of memory error for CUDA. Is this expected?

This is the code I’m using, for reference:

```auto
HF_model_name = "../models/test_results_0"

HF_model = AutoModelForSequenceClassification.from_pretrained(HF_model_name, output_hidden_states=True).to("cpu")
HF_tokenizer = AutoTokenizer.from_pretrained(HF_model_name)

args = TrainingArguments(no_cuda=True,output_dir=".")

trainer = Trainer(
        model=HF_model,
        args=TrainingArguments(args,output_dir="."),
    )

data_files = "../data/fakenews/cleaned_data/text_dataset.tsv"
 df = pd.read_csv(data_files, sep="\t")

 text = df.loc[0,"text"]

def tokenize_data(example):
    return HF_tokenizer(example["text"], padding="max_length")

print(len(text))

text_small = text[:200]
tokenized_text = pd.DataFrame([text_small], columns=["text"])
dataset = Dataset.from_dict(tokenized_text)
dataset = dataset.map(tokenize_data, batched=True)

T = trainer.predict(dataset)

```
