Training a neural network model with PyTorch
The target of this section is to build and train one simple neural network model using PyTorch. The model will be a simple one-layer model, with no additional fancy layers. It is simple but with all the elements required to train a Stable Diffusion LoRA, as we will see later in this chapter.
Feel free to skip this section if you are familiar with PyTorch model training. If it is your first time to start training a model, this simple model training will help you thoroughly understand the process of model training.
Before starting, make sure you have installed all the required packages mentioned in the Technical requirements section.
Preparing the training data
Let’s assume we want to train a model with four weights and output one digital result show, as shown in the following:
y = w 1 × x 1 + w 2 × x 2 + w 3 × x 3 + w 4 × x 4
The four weights, w 1, w...