Skip to content

Training, adaptation, compression, and systems techniques · Training, fine-tuning, adaptation, compression, and systems techniques · TRN001 · Training method

Stochastic gradient descent with momentum

Updates trainable weights using minibatch gradients and a running velocity. It is an optimizer, not a predictive model, and applies to supervised, self-supervised, and generative objectives.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through decide.offline_rl, decide.rl_dqn, decide.rl_ppo, discover.autoencoder, discover.contrastive, discover.dagmm, discover.deep_svdd, discover.graph_embed, discover.ts_embed, discover.vae, forecast.deepar, forecast.nbeats, forecast.nhits, forecast.patchtst, forecast.rnn, forecast.tcn, forecast.tft, forecast.timegrad, learn.cnn, learn.dann, learn.deep_ensemble, learn.ft_transformer, learn.gnn, learn.neural_cde, learn.set_model, learn.tabm, learn.tabnet, learn.torch_mlp, missing.csdi, simulate.calibrate, synth.flow, synth.flow_matching, synth.tvae. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Updates trainable weights using minibatch gradients and a running velocity. It is an optimizer, not a predictive model, and applies to supervised, self-supervised, and generative objectives.

Question / hypotheses

Does this intervention improve the intended quality, adaptation, resource, or reliability objective under a controlled comparison? It defines a method, not an intrinsic null-hypothesis test.

Architecture / computational structure

A gradient computation feeds a velocity buffer and parameter update; the neural architecture remains unchanged.

Assumptions

The objective must supply usable gradients. Learning-rate scale, batch sampling, feature normalization, and loss reduction affect stability. Momentum/Nesterov implementations differ in buffer initialization and dampening.

Formula / computational definition

vt=μvt−1+gt,θt+1=θt−ηtvt.v_t=\mu v_{t-1}+g_t,\qquad\theta_{t+1}=\theta_t-\eta_t v_t.

Parameters and notation

Learned quantities: model weights theta; optimizer state: velocity v. Hyperparameters: learning rate eta, momentum mu, schedule, batch size, dampening, weight decay, Nesterov option.

Fitting, fine-tuning, and adaptation

For transfer, define separate head/backbone parameter groups and use a smaller backbone step. Reinitialize optimizer state when deliberately starting a new adaptation stage; preserve it for an exact training resume.

How to use and calibrate

Track loss, gradient/update norms, validation curves, and throughput. Compare optimizers under matched training budgets; check a tiny-batch overfit before a large run. Example: fine-tune a residual image classifier.

Example application

fine-tune a residual image classifier.

Interpretation / pitfalls

Watch out

Accumulated gradients require correct averaging. A lower training loss does not establish generalization. Large momentum can carry updates through a changed task distribution.

Python and R code examples

Scope: numerical mechanism demonstration. Validation: Python executed successfully on the supplied synthetic inputs; R reviewed but not executed (Rscript unavailable).

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — numerical mechanism demonstration. · needs numpy

import numpy as np
w=np.array([1.,-1.]); v=np.array([.2,-.1]); g=np.array([.3,.4])
v=.9*v+g; w=w-.01*v; print(w)
R

Component demo, not a trained model — numerical mechanism demonstration.

w <- c(1,-1); v <- c(.2,-.1); g <- c(.3,.4)
v <- .9*v+g; w <- w-.01*v; print(w)

Sources

From the CodeSplash reference, entry TRN001.