Quickstart

🤗 Optimum Graphcore was designed with one goal in mind: make training and evaluation straightforward for any 🤗 Transformers user while leveraging the complete power of IPUs.

There are two main classes one needs to know:

The IPUTrainer is very similar to the 🤗 Transformers Trainer, and adapting a script using the Trainer to make it work with IPUs will mostly consists of simply swapping the Trainer class for the IPUTrainer one. That’s how most of the example scripts were adapted from their original counterparts.

Original script:

from transformers import Trainer, TrainingArguments

# 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,
)

Transformed version that can run on IPUs:

from optimum.graphcore import IPUConfig, IPUTrainer, IPUTrainingArguments

# A lot of the same code as the original script here

# Loading the IPUConfig needed by the IPUTrainer to compile and train the model on IPUs
ipu_config = IPUConfig.from_pretrained(
    training_args.ipu_config_name if training_args.ipu_config_name else model_args.model_name_or_path,
    cache_dir=model_args.cache_dir,
    revision=model_args.model_revision,
    use_auth_token=True if model_args.use_auth_token else None,
)

# Initialize our Trainer
trainer = IPUTrainer(
    model=model,
    ipu_config=ipu_config,
    # The training arguments differ a bit from the original ones, that is why we use IPUTrainingArguments
    args=training_args,
    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,
)