# Difference between model.train and trainer.train

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdifference-between-model-train-and-trainer-train%2F32584%3E%5C
**Category:** Beginners\
**Created:** [February 26, 2023, 10:48pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdifference-between-model-train-and-trainer-train%2F32584 "2023-02-26T22:48:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eg101](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@eg101](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Feg101)%5C
**Post date:** [February 26, 2023, 10:48pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdifference-between-model-train-and-trainer-train%2F32584%2F1 "2023-02-26T22:48:14Z")

</div>

Hello I am new to hugging face. I am trying to train model one data text at a time, I am wondering whether this would be an efficient way of doing it:

```auto
   model.train(mode=True)
   outputs = model(input_ids, labels=labels)
   loss = outputs[0]
   loss.backward()
   optimizer.step()
   optimizer.zero_grad()

```

or I should do:

```auto
args = TrainingArguments(
        output_dir="output",
        num_train_epochs=epochs,
        per_device_train_batch_size=batch,
        weight_decay=0.01,
        optim = "adamw_torch"

    )

    trainer = Trainer(
        model=model,
        args=args,
        # data_collator=data_collator,
        train_dataset=train_dataset,
        #eval_dataset=val_dataset,
        compute_metrics=compute_metrics
    )
    trainer.train()

```

Which would be the most efficient way of going about it and that would lead to the most accurate results. Again, im new to ai in general so bear with me if this is a bad question. Any help would be extremely appreciated thanks
