Why is my model learning so slow?

sort: <p>My model is a really basic one, I made it just to learn, but it learns really slow. I ran the model tens thousands of times but the loss only decreased from 640 to 420. How would I increase the rate at which my model learns? I use visual studio 2022 and am on windows 11.<br>
my code:</p>
<p><span class="hashtag-raw">#include</span> &lt;torch/torch.h&gt;<br>
<span class="hashtag-raw">#include</span> <br>
<span class="hashtag-raw">#include</span> <br>
<span class="hashtag-raw">#include</span> <br>
struct Net : torch::nn::Module {<br>
//constructor initializes a random set of weights which have a size of n rows and m columns, and a bias tensor with a size of m rows<br>
Net()<br>
{<br>
layer1 = register_module(“layer1”, torch::nn::Linear(1, 10));<br>
layer2 = register_module(“layer2”, torch::nn::Linear(10, 1));<br>
}<br>
//redifine the virtual function forward from tensor<br>
torch::Tensor forward(torch::Tensor var1)<br>
{<br>
//goes through input layer and gets changed<br>
var1 = layer1-&gt;forward(var1);<br>
//relu removes all the negative numbers and turns them into 0’s<br>
var1 = torch::relu(var1);<br>
//goes through output layer<br>
var1 = layer2-&gt;forward(var1);<br>
return var1;<br>
}</p>
<pre><code>//initializes the variables(does not matter what order)
torch::nn::Linear layer1{ nullptr }, layer2{ nullptr };
</code></pre>
<p>};<br>
//had to add save and load models because for some reason the torch::load did not work<br>
void save_model(std::string path, const Net&amp; model) {<br>
torch::serialize::OutputArchive output_archive;<br>
model.save(output_archive);<br>
output_archive.save_to(path);</p>
<p>}<br>
void load_model(std::string path, Net&amp; model) {<br>
torch::serialize::InputArchive input_archive;<br>
input_archive.load_from(path);<br>
model.load(input_archive);<br>
}</p>
<p>int main() {</p>
<pre><code>torch::manual_seed(0);
Net net;
float avg = 0;
std::vector&lt;float&gt; average_group;
torch::Tensor specific_values_tensor = torch::tensor({ 5.0 }, torch::kFloat32).view({ 1, 1 });
try {
    load_model("test_model01.pt", net);
    std::cout &lt;&lt; "Model loaded successfully." &lt;&lt; std::endl;
}
catch (const std::exception&amp; e) {
    std::cerr &lt;&lt; "Failed to load model: " &lt;&lt; e.what() &lt;&lt; std::endl;
}
std::cout &lt;&lt; net &lt;&lt; std::endl;
//auto output = net.forward(specific_values_tensor);
//std::cout &lt;&lt; output &lt;&lt; std::endl;
torch::optim::Adam optimizer(net.parameters(), torch::optim::AdamOptions(0.005));
auto scheduler = torch::optim::StepLR(optimizer, /*step_size=*/100, /*gamma=*/0.1);
std::cout &lt;&lt; "enter the number of iterations that should be done (each iteration amount will be done 3 times)\n";
size_t iter_num = 5;
try
{
    std::cin &gt;&gt; iter_num;
    if (std::cin.fail())
        throw("wrong input type");
}
catch (const char* msg)
{
    std::cout &lt;&lt; msg &lt;&lt; std::endl;
    std::cin.clear();
    std::cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
    std::cin &gt;&gt; iter_num;
}
//a 3 time loop that starts with a 1 because of later logic reasons
</code></pre>
<p>for(int op = 0; op &lt; 3; op++)<br>
{<br>
avg = 0;<br>
for (size_t a = 0; a &lt; iter_num; a++)<br>
{<br>
auto input = torch::rand({ 1, 1 }) * 5;<br>
auto target = input * input;<br>
optimizer.zero_grad();<br>
auto output = net.forward(input);<br>
auto loss = torch::mse_loss(output, target);<br>
//calculates the negative gradient<br>
loss.backward();<br>
torch::nn::utils::clip_grad_norm_(net.parameters(), /<em>max_norm=</em>/0.5);<br>
//changes values based off the negative gradient calculated by loss.backward()<br>
optimizer.step();<br>
scheduler.step();<br>
if (a % 100 == 0)<br>
{<br>
auto prev_loss = loss;<br>
std::cout &lt;&lt; "\niteration number: " &lt;&lt; a;<br>
std::cout &lt;&lt; "\nLoss: " &lt;&lt; loss.item() &lt;&lt; std::endl;<br>
std::cout &lt;&lt; "Prediction: " &lt;&lt; output.item();<br>
std::cout &lt;&lt; "\nTarget: " &lt;&lt; target.item();<br>
}<br>
avg += loss.item();<br>
}<br>
//the average is divided by the iter_num*op because the cycle loops 3 times<br>
average_group.push_back(avg / (iter_num));<br>
}<br>
for (auto iterator : average_group)<br>
{<br>
std::cout &lt;&lt; "\naverage: ";<br>
std::cout &lt;&lt; iterator;<br>
}<br>
save_model(“test_model01.pt”, net);<br>
//potential: save test_model01.pt, had an average last loss of 420. split it into 3 different models(or more if needed) and change activation function: ReLU(control)<br>
//sigmoid and tanh. Tweak some parameters, add batch sizes.<br>
}</p>