svgtimestep-loss
Diffusion loss by step
At which noise levels does a diffusion model still struggle to denoise?
How to read it
- Read x as how much noise was added: small steps are nearly clean rows, large steps nearly pure noise.
- Read y as how far the model's denoising guess is from the truth at that step.
- High loss at small steps means the fine detail of the rows isn't learned yet; high loss at large steps is expected for categories.
- Callout 1: Small t: fine-detail denoising.
- Callout 2: Large t: almost pure noise.
- Callout 3: The categories' part.
Watch out
- The two parts are on different scales (squared error vs KL), so compare each line's shape, not their heights.
- A flat, low curve can also mean memorization; check the scorecard's distance to closest record.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Draws the engine's numbers as given (codesplash ↔ codesplashr torch twins); the chart computes nothing statistical.
- Each point is the loss on the same (up to 256) training rows with fixed shared-stream noise at one step t.
- The Gaussian part is the mean squared error of the predicted noise; the multinomial part is the KL between the true and predicted reverse steps (−log p(x₀ | x₁) at t = 1).
# Diffusion loss by step — Codesplash Chart Lab (recipe "timestep-loss")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
df = pd.read_csv("timestep-loss-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["part"] = pd.Categorical(df["part"].astype("string"), categories=["Gaussian (numbers)", "multinomial (categories)"])
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
T = "diffusion step t"
V = "loss"
C = "part"
d = df.dropna(subset=[T, V])
fig, ax = plt.subplots(figsize=(8, 4))
for name in levels_of(d[C]):
s = d[d[C].astype(str) == name].sort_values(T)
ax.plot(s[T], s[V], marker="o", markersize=3, label=name)
ax.set_ylim(bottom=min(0, d[V].min()))
ax.set_xlabel(f"{T} (more noise →)")
ax.set_ylabel(V)
ax.legend(frameon=False)
plt.show()Needs pandas, numpy, matplotlib · reads timestep-loss-demo.csv · app theme from the optional codesplash helper
# Diffusion loss by step — Codesplash Chart Lab (recipe "timestep-loss")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else px.colors.qualitative.Plotly
df = pd.read_csv("timestep-loss-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["part"] = pd.Categorical(df["part"].astype("string"), categories=["Gaussian (numbers)", "multinomial (categories)"])
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
T = "diffusion step t"
V = "loss"
C = "part"
d = df.dropna(subset=[T, V])
fig = go.Figure()
for name in levels_of(d[C]):
s = d[d[C].astype(str) == name].sort_values(T)
fig.add_trace(go.Scatter(x=s[T], y=s[V], mode="lines+markers", name=name))
fig.update_layout(xaxis_title=f"{T} (more noise →)", yaxis_title=V, template="plotly_white")
fig.update_yaxes(rangemode="tozero")
fig.show()Needs pandas, numpy, plotly · reads timestep-loss-demo.csv · app theme from the optional codesplash helper
# Diffusion loss by step — Codesplash Chart Lab (recipe "timestep-loss")
# controls: defaults
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("timestep-loss-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["part"]] <- factor(df[["part"]], levels = c("Gaussian (numbers)", "multinomial (categories)"))
levels_of <- function(v) if (is.factor(v)) levels(droplevels(v)) else unique(as.character(v[!is.na(v)]))
T <- "diffusion step t"
V <- "loss"
C <- "part"
d <- df[!is.na(df[[T]]) & !is.na(df[[V]]), ]
d$part <- factor(as.character(d[[C]]), levels = levels_of(d[[C]]))
p <- ggplot(d, aes(x = .data[[T]], y = .data[[V]], colour = part)) + geom_line() + geom_point(size = 1.2) +
expand_limits(y = 0) + labs(x = paste(T, "(more noise →)"), y = V, colour = NULL) + theme_minimal()
print(p)Needs ggplot2 · reads timestep-loss-demo.csv · app theme from the optional codesplashr helper