Skip to content

Train a model on CPU

Isaac Schifferer edited this page May 23, 2024 · 1 revision

Training without a GPU.

It is possible to train a model using a processor rather than a GPU. Although this generally takes longer it may have the advantage of using the system memory which may be much larger than is typically available in a GPU.

For the training on CPU there is a guide on Huggingface There is also a guide for inferencing on a CPU

Huggingface recommend installing IPEX which is optimized for CPUs with AVX-512 or above, and functionally works for CPUs with only AVX2. IPEX is expected to bring performance benefit for Intel CPU generations with AVX-512 or above while CPUs with only AVX2 might gain better performance under IPEX that is not guaranteed. The version of IPEX depends on the version of PyTorch.

In the transformers package, the training arguments are set through the function "Seq2SeqTrainingArguments". By default, fine-tuning is done on the GPU, so by default all these arguments are set to "False".

In order to add 'no_cuda' and 'use_ipex' to the training arguments and set them to "True", change hugging_face_config.py (which is located in 'nmt' folder within 'silnlp' folder). Add them to the dictionary "args" like this: under the line 697 "args: dict = {}"

args["use_ipex"] = "True"

args["no_cuda"] = "True"

args["bf16"] = "True"