{"slug": "neural-networks-with-pytorch-and-lightning-ai-part-5-final-results-and-gpu", "title": "Neural Networks with PyTorch and Lightning AI Part 5: Final Results and GPU Acceleration", "summary": "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.", "body_md": "In the [previous article](https://dev.to/rijultp/neural-networks-with-pytorch-and-lightning-ai-part-4-from-manual-training-to-automated-training-2nkf), 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.\n\nFor verifying that the `final_bias`\n\nis correctly optimized, we can print out the new value:\n\n```\ntrainer.fit(model, train_dataloaders=dataloader)\nprint(model.final_bias.data)\n```\n\nThis gives us `-16.0098`\n\n.\n\nLet’s also visualize it:\n\n```\noutput_values = model(input_doses)\n\nsns.set(style=\"whitegrid\")\n\nsns.lineplot(\n    x=input_doses,\n    y=output_values.detach(),\n    color=\"green\",\n    linewidth=2.5\n)\n\nplt.ylabel(\"Effectiveness\")\nplt.xlabel(\"Dose\")\n```\n\nNow there are some practical questions, like: if we want to use GPU acceleration, how is that possible?\n\nOn most basic laptops, the **CPU does all the work**.\n\nIn that case, both:\n\nare stored and processed on the CPU.\n\nAll computations happen there.\n\nBut CPUs have limited cores, so when we run something like neural network training, it can become very slow.\n\nTo speed things up, we use **Graphics Processing Units (GPUs)**.\n\nA GPU has **10x to 100x more compute cores** compared to a CPU.\n\nHowever, without tools like Lightning, using GPUs requires manually assigning tensors and operations to the correct device, which becomes complicated.\n\nWith Lightning, this process is automated.\n\nWe can simply write:\n\n```\ntrainer = L.Trainer(\n    max_epochs=34,\n    accelerator=\"auto\",\n    devices=\"auto\"\n)\n```\n\nHere:\n\n`accelerator=\"auto\"`\n\nallows Lightning to automatically detect whether a GPU is available`devices=\"auto\"`\n\nlets Lightning decide how many GPUs to useThis means the same code can:\n\nSo Lightning makes training not only simpler, but also **hardware-flexible without extra effort**.\n\nIn the coming series, we will explore more such applications of lightning.\n\nAI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.\n\n[git-lrc](https://github.com/HexmosTech/git-lrc) fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.\n\nAny feedback or contributors are welcome! It's online, source-available, and ready for anyone to use.\n\nGive it a ⭐ [star on Github](https://github.com/HexmosTech/git-lrc)", "url": "https://wpnews.pro/news/neural-networks-with-pytorch-and-lightning-ai-part-5-final-results-and-gpu", "canonical_source": "https://dev.to/rijultp/neural-networks-with-pytorch-and-lightning-ai-part-5-final-results-and-gpu-acceleration-4m0m", "published_at": "2026-06-20 18:06:54+00:00", "updated_at": "2026-06-20 18:36:49.127035+00:00", "lang": "en", "topics": ["machine-learning", "neural-networks", "developer-tools"], "entities": ["PyTorch", "Lightning AI", "GPU"], "alternates": {"html": "https://wpnews.pro/news/neural-networks-with-pytorch-and-lightning-ai-part-5-final-results-and-gpu", "markdown": "https://wpnews.pro/news/neural-networks-with-pytorch-and-lightning-ai-part-5-final-results-and-gpu.md", "text": "https://wpnews.pro/news/neural-networks-with-pytorch-and-lightning-ai-part-5-final-results-and-gpu.txt", "jsonld": "https://wpnews.pro/news/neural-networks-with-pytorch-and-lightning-ai-part-5-final-results-and-gpu.jsonld"}}