SShortSingh.
Back to feed

How Backpropagation Works: Manual Gradient Calculation Verified by PyTorch

0
·3 views

A developer walks through computing gradients by hand for a two-layer neural network using only scalar values and the chain rule. The network consists of one input, a hidden neuron with a ReLU activation, an output neuron, and a squared-error loss function with four trainable parameters. Starting from a forward pass that produces a loss of 25, the backward pass traces gradients step by step, arriving at values of 30, 30, 20, and 10 for w1, b1, w2, and b2 respectively. The same network is then built in PyTorch using autograd, which produces identical gradient values after a single call to loss.backward(). The exercise illustrates how gradients flow back through layers by multiplying local derivatives at each node, a process that scales to any network depth.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

14-Year-Old Indian Developer Ships 3 Web Projects Using Only a Budget Smartphone

Adrish, a 14-year-old developer from India, has built and deployed three web projects without access to a laptop or PC. His entire development setup runs on a Samsung M11 using free mobile code editors TrebEdit and Cxxdroid. His completed projects include a personal portfolio, a calculator, and a password generator, all hosted on Cloudflare. The calculator and password generator were collaborative efforts, with Adrish handling HTML and CSS while a friend contributed the JavaScript. He works with Vanilla HTML, Vanilla CSS, C, QB64, and is a beginner in Python.

0
ProgrammingDEV Community ·

Silent workflow bug reported 'success' 27 times daily while skipping all real work

A developer discovered that 27 workflow branches were being silently skipped every day, yet each run was marked as COMPLETED with no warnings. The root cause was an enum value, StepExecutionStatus.SKIPPED, that had existed in the codebase since the project's start but had never actually been written to the database. Skipped steps left no database rows, making them invisible in the UI and impossible to query without manually parsing a JSON blob. The fix involved writing real database rows for skipped steps and adding run-level counts for processed, skipped, and failed steps. The incident highlighted a broader problem: health checks and status indicators can appear green while the system silently does nothing meaningful.

0
ProgrammingDEV Community ·

Testcontainers Guide: Run Real Docker Dependencies in Automated Tests

Testcontainers is a multi-language library that programmatically starts and stops real Docker containers during automated test runs, supporting .NET, Java, Go, Python, Node.js, and more. It solves key problems with older approaches like docker-compose setups, where container lifecycles were decoupled from test execution and stale data or unready services caused flaky tests. The library provides genuine readiness detection to confirm a service is truly accepting connections, not just that its process has started, eliminating race-condition failures. It also handles dynamic port allocation, automatic cleanup via a Ryuk-based safety net, and supports a broad module ecosystem well beyond databases. Performance features like container reuse help make Testcontainers practical for routine use rather than an occasional, costly testing option.

0
ProgrammingDEV Community ·

Run AI Models Locally Using Docker Model Runner and Spring AI

Developers building Java applications with Spring AI can run large language models locally using Docker Model Runner, eliminating the need for cloud-hosted AI services like OpenAI or AWS Bedrock. Docker Model Runner exposes an OpenAI-compatible API endpoint, allowing Spring Boot applications to communicate with local models through standard Spring AI abstractions such as ChatClient and ChatModel. Running models locally helps developers avoid API costs during experimentation, keep sensitive data on-device, and work without an active internet connection. The setup requires Docker Desktop and the Spring AI OpenAI starter dependency, which connects to the local runtime rather than OpenAI's cloud infrastructure. This approach lets developers test prompts, RAG pipelines, and tool-calling logic without configuring cloud credentials each time.