🤗 Optimum Neuron was designed with one goal in mind: to make training and inference straightforward for any 🤗 Transformers user while leveraging the complete power of AWS Accelerators. There are two main classes one needs to know:
The TrainiumTrainer is very similar to the 🤗 Transformers Trainer, and adapting a script using the Trainer to make it work with Trainium will mostly consist in simply swapping the Trainer
class for the TrainiumTrainer
one.
That’s how most of the example scripts were adapted from their original counterparts.
modifications:
from transformers import TrainingArguments
-from transformers import Trainer
+from optimum.neuron import TrainiumTrainer as Trainer
training_args = TrainingArguments(
# training arguments...
)
# A lot of code here
# Initialize our Trainer
trainer = Trainer(
model=model,
args=training_args, # Original training arguments.
train_dataset=train_dataset if training_args.do_train else None,
eval_dataset=eval_dataset if training_args.do_eval else None,
compute_metrics=compute_metrics,
tokenizer=tokenizer,
data_collator=data_collator,
)