cd /news/machine-learning/neural-networks-with-pytorch-and-lig… · home topics machine-learning article
[ARTICLE · art-35033] src=dev.to ↗ pub= topic=machine-learning verified=true sentiment=↑ positive

Neural Networks with PyTorch and Lightning AI Part 5: Final Results and GPU Acceleration

A developer using PyTorch and Lightning AI demonstrated automated neural network training with GPU acceleration. By setting the trainer's accelerator and devices to 'auto', Lightning automatically detects and utilizes available GPUs, simplifying hardware acceleration. The final bias value was optimized to -16.0098, and the model's output was visualized.

read2 min views1 publishedJun 20, 2026

In the previous article, we saw how we automated several manual pieces when training a neural network. In this article, we will check the final results and also see how we can do hardware acceleration.

For verifying that the final_bias

is correctly optimized, we can print out the new value:

trainer.fit(model, train_datas=data)
print(model.final_bias.data)

This gives us -16.0098

.

Let’s also visualize it:

output_values = model(input_doses)

sns.set(style="whitegrid")

sns.lineplot(
    x=input_doses,
    y=output_values.detach(),
    color="green",
    linewidth=2.5
)

plt.ylabel("Effectiveness")
plt.xlabel("Dose")

Now there are some practical questions, like: if we want to use GPU acceleration, how is that possible?

On most basic laptops, the CPU does all the work.

In that case, both:

are stored and processed on the CPU.

All computations happen there.

But CPUs have limited cores, so when we run something like neural network training, it can become very slow.

To speed things up, we use Graphics Processing Units (GPUs).

A GPU has 10x to 100x more compute cores compared to a CPU.

However, without tools like Lightning, using GPUs requires manually assigning tensors and operations to the correct device, which becomes complicated.

With Lightning, this process is automated.

We can simply write:

trainer = L.Trainer(
    max_epochs=34,
    accelerator="auto",
    devices="auto"
)

Here:

accelerator="auto"

allows Lightning to automatically detect whether a GPU is availabledevices="auto"

lets Lightning decide how many GPUs to useThis means the same code can:

So Lightning makes training not only simpler, but also hardware-flexible without extra effort.

In the coming series, we will explore more such applications of lightning.

AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.

Any feedback or contributors are welcome! It's online, source-available, and ready for anyone to use.

Give it a ⭐ star on Github

── more in #machine-learning 4 stories · sorted by recency
── more on @pytorch 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/neural-networks-with…] indexed:0 read:2min 2026-06-20 ·