var documenterSearchIndex = {"docs":
[{"location":"references/#References","page":"References","title":"References","text":"","category":"section"},{"location":"references/","page":"References","title":"References","text":"","category":"page"},{"location":"references/","page":"References","title":"References","text":"*","category":"page"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"EditURL = \"../../../examples/beta_schedulers_comparison.jl\"","category":"page"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"This example compares the different beta schedules available in Diffusers.jl. Code related to the generation of the datasets and the plots is hidden.","category":"page"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"using Diffusers.Schedulers: DDPM, forward # hide\nusing Diffusers.BetaSchedules # hide\nusing ProgressMeter # hide\nusing LaTeXStrings # hide\nusing Random # hide\nusing Plots # hide\nusing Flux # hide\nusing MLDatasets # hide\n\nfunction normalize_zero_to_one(x) # hide\n x_min, x_max = extrema(x) # hide\n x_norm = (x .- x_min) ./ (x_max - x_min) # hide\n x_norm # hide\nend # hide\n\nfunction normalize_neg_one_to_one(x) # hide\n 2 * normalize_zero_to_one(x) .- 1 # hide\nend # hide\n\nnum_timesteps = 100 # hide\nbeta_schedules = [ # hide\n linear_beta_schedule, # hide\n scaled_linear_beta_schedule, # hide\n cosine_beta_schedule, # hide\n sigmoid_beta_schedule, # hide\n exponential_beta_schedule, # hide\n] # hide\nschedulers = [ # hide\n DDPM(collect(schedule(num_timesteps))) for schedule in beta_schedules # hide\n]; # hide\nnothing #hide","category":"page"},{"location":"generated/beta_schedulers_comparison/#Swiss-Roll","page":"Beta Schedules Comparison","title":"Swiss Roll","text":"","category":"section"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"function make_spiral(n_samples::Integer=1000, t_min::Real=1.5π, t_max::Real=4.5π) # hide\n t = rand(typeof(t_min), n_samples) * (t_max - t_min) .+ t_min # hide\n\n x = t .* cos.(t) # hide\n y = t .* sin.(t) # hide\n\n permutedims([x y], (2, 1)) # hide\nend # hide\n\nn_points = 1000; # hide\ndataset = make_spiral(n_points, 1.5f0 * π, 4.5f0 * π); # hide\ndataset = normalize_neg_one_to_one(dataset); # hide\n\nnoise = randn(Float32, size(dataset)) # hide\nanim = @animate for t in cat(fill(0, 20), 1:num_timesteps, fill(num_timesteps, 20), dims=1) # hide\n plots = [] # hide\n for (i, (scheduler, beta_schedule)) in enumerate(zip(schedulers, beta_schedules)) # hide\n if t == 0 # hide\n scatter(dataset[1, :], dataset[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n legend=false, # hide\n ) # hide\n plot = scatter!(dataset[1, :], dataset[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n ) # hide\n title!(string(beta_schedule)) # hide\n xlims!(-3, 3) # hide\n ylims!(-3, 3) # hide\n else # hide\n scatter(dataset[1, :], dataset[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n legend=false, # hide\n ) # hide\n noisy_data = forward(scheduler, dataset, noise, [t]) # hide\n plot = scatter!(noisy_data[1, :], noisy_data[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n ) # hide\n title!(string(beta_schedule)) # hide\n xlims!(-3, 3) # hide\n ylims!(-3, 3) # hide\n end # hide\n push!(plots, plot) # hide\n end # hide\n plot(plots...; size=(1200, 800)) # hide\nend # hide\n\ngif(anim, anim.dir * \".gif\", fps=20) # hide","category":"page"},{"location":"generated/beta_schedulers_comparison/#Double-Square","page":"Beta Schedules Comparison","title":"Double Square","text":"","category":"section"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"function make_square(n_samples::Integer=1000) # hide\n x = rand(n_samples) .* 2 .- 1 # hide\n y = rand(n_samples) .* 2 .- 1 # hide\n p = permutedims([x y], (2, 1)) # hide\n p ./ maximum(abs.(p), dims=1) # hide\nend # hide\n\ndataset = hcat( # hide\n make_square(Int(n_points / 2)) ./ 2 .- 1.5, # hide\n make_square(Int(n_points / 2)) ./ 2 .+ 1.5 # hide\n) # hide\n\nnoise = randn(Float32, size(dataset)) # hide\nanim = @animate for t in cat(fill(0, 20), 1:num_timesteps, fill(num_timesteps, 20), dims=1) # hide\n plots = [] # hide\n for (i, (scheduler, beta_schedule)) in enumerate(zip(schedulers, beta_schedules)) # hide\n if t == 0 # hide\n scatter(dataset[1, :], dataset[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n legend=false, # hide\n ) # hide\n plot = scatter!(dataset[1, :], dataset[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n ) # hide\n title!(string(beta_schedule)) # hide\n xlims!(-3, 3) # hide\n ylims!(-3, 3) # hide\n else # hide\n scatter(dataset[1, :], dataset[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n legend=false, # hide\n ) # hide\n noisy_data = forward(scheduler, dataset, noise, [t]) # hide\n plot = scatter!(noisy_data[1, :], noisy_data[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n ) # hide\n title!(string(beta_schedule)) # hide\n xlims!(-3, 3) # hide\n ylims!(-3, 3) # hide\n end # hide\n push!(plots, plot) # hide\n end # hide\n plot(plots...; size=(1200, 800)) # hide\nend # hide\n\ngif(anim, anim.dir * \".gif\", fps=20) # hide","category":"page"},{"location":"generated/beta_schedulers_comparison/#MNIST","page":"Beta Schedules Comparison","title":"MNIST","text":"","category":"section"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"dataset = MNIST(:test)[16].features # hide\ndataset = rotl90(dataset) # hide\ndataset = normalize_neg_one_to_one(dataset) # hide\n\nnoise = randn(Float32, size(dataset)) # hide\nanim = @animate for t in cat(fill(0, 20), 1:num_timesteps, fill(num_timesteps, 20), dims=1) # hide\n plots = [] # hide\n for (i, (scheduler, beta_schedule)) in enumerate(zip(schedulers, beta_schedules)) # hide\n if t == 0 # hide\n plot = heatmap( # hide\n dataset, # hide\n c=:grayC, # hide\n legend=:none, # hide\n aspect_ratio=:equal, # hide\n grid=false, # hide\n axis=false # hide\n ) # hide\n title!(string(beta_schedule)) # hide\n else # hide\n noisy_data = forward(scheduler, dataset, noise, [t]) # hide\n plot = heatmap( # hide\n noisy_data, # hide\n c=:grayC, # hide\n legend=:none, # hide\n aspect_ratio=:equal, # hide\n grid=false, # hide\n axis=false # hide\n ) # hide\n title!(string(beta_schedule)) # hide\n end # hide\n\n push!(plots, plot) # hide\n end # hide\n plot(plots...; size=(1200, 800)) # hide\nend # hide\n\ngif(anim, anim.dir * \".gif\", fps=20) # hide","category":"page"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"","category":"page"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"This page was generated using Literate.jl.","category":"page"},{"location":"schedulers/","page":"Schedulers","title":"Schedulers","text":"(Image: Markovian Hierarchical Variational Autoencoder)","category":"page"},{"location":"schedulers/","page":"Schedulers","title":"Schedulers","text":"Modules = [Diffusers.Schedulers]","category":"page"},{"location":"schedulers/#Diffusers.Schedulers.DDIM","page":"Schedulers","title":"Diffusers.Schedulers.DDIM","text":"Denoising Diffusion Implicit Models (DDIM) scheduler.\n\nReferences\n\n[2010.02502] Denoising Diffusion Implicit Models\n\n\n\n\n\n","category":"type"},{"location":"schedulers/#Diffusers.Schedulers.DDPM","page":"Schedulers","title":"Diffusers.Schedulers.DDPM","text":"Denoising Diffusion Probabilistic Models (DDPM) scheduler.\n\nReferences\n\n[2006.11239] Denoising Diffusion Probabilistic Models\n\n\n\n\n\n","category":"type"},{"location":"schedulers/#Diffusers.Schedulers.Scheduler","page":"Schedulers","title":"Diffusers.Schedulers.Scheduler","text":"Abstract type for schedulers.\n\n\n\n\n\n","category":"type"},{"location":"schedulers/#Diffusers.Schedulers.forward-Tuple{Diffusers.Schedulers.Scheduler, AbstractArray, AbstractArray, AbstractArray}","page":"Schedulers","title":"Diffusers.Schedulers.forward","text":"Add noise to clean data using the forward diffusion process.\n\nInput\n\nscheduler::Scheduler: scheduler to use\nx₀::AbstractArray: clean data to add noise to\nϵ::AbstractArray: noise to add to clean data\nt::AbstractArray: timesteps used to weight the noise\n\nOutput\n\nxₜ::AbstractArray: noisy data at the given timesteps\n\n\n\n\n\n","category":"method"},{"location":"schedulers/#Diffusers.Schedulers.get_velocity-Tuple{Diffusers.Schedulers.Scheduler, AbstractArray, AbstractArray, AbstractArray}","page":"Schedulers","title":"Diffusers.Schedulers.get_velocity","text":"Compute the velocity of the diffusion process.\n\nInput\n\nscheduler::Scheduler: scheduler to use\nx₀::AbstractArray: clean data to add noise to\nϵ::AbstractArray: noise to add to clean data\nt::AbstractArray: timesteps used to weight the noise\n\nOutput\n\nvₜ::AbstractArray: velocity at the given timesteps\n\nReferences\n\n[1, Ann. D]\n\n\n\n\n\n","category":"method"},{"location":"schedulers/#Diffusers.Schedulers.reverse-Tuple{Diffusers.Schedulers.Scheduler, AbstractArray, AbstractArray, AbstractArray}","page":"Schedulers","title":"Diffusers.Schedulers.reverse","text":"Remove noise from model output using the backward diffusion process.\n\nInput\n\nscheduler::Scheduler: scheduler to use\nxₜ::AbstractArray: sample to be denoised\nϵᵧ::AbstractArray: predicted noise to remove\nt::AbstractArray: timestep t of xₜ\n\nOutput\n\nxₜ₋₁::AbstractArray: denoised sample at t=t-1\nx̂₀::AbstractArray: denoised sample at t=0\n\n\n\n\n\n","category":"method"},{"location":"beta_schedules/","page":"Beta Schedules","title":"Beta Schedules","text":"using Diffusers.BetaSchedules\nusing LaTeXStrings\nusing PlotlyJS\n\nT = 1000\n\nβ_linear = linear_beta_schedule(T)\nβ_scaled_linear = scaled_linear_beta_schedule(T)\nβ_cosine = cosine_beta_schedule(T)\nβ_sigmoid = sigmoid_beta_schedule(T)\nβ_exponential = exponential_beta_schedule(T)\n\nα̅_linear = cumprod(1 .- β_linear)\nα̅_scaled_linear = cumprod(1 .- β_scaled_linear)\nα̅_cosine = cumprod(1 .- β_cosine)\nα̅_sigmoid = cumprod(1 .- β_sigmoid)\nα̅_exponential = cumprod(1 .- β_exponential)\n\np1 = plot(\n [\n scatter(y=β_linear, name=\"Linear\"),\n scatter(y=β_scaled_linear, name=\"Scaled linear\", visible=\"legendonly\"),\n scatter(y=β_cosine, name=\"Cosine\"),\n scatter(y=β_sigmoid, name=\"Sigmoid\", visible=\"legendonly\"),\n scatter(y=β_exponential, name=\"Exponential\", visible=\"legendonly\"),\n ],\n Layout(\n updatemenus=[\n attr(\n type=\"buttons\",\n active=1,\n buttons=[\n attr(\n label=\"Linear\",\n method=\"relayout\",\n args=[\"yaxis.type\", \"linear\"],\n ),\n attr(\n label=\"Log\",\n method=\"relayout\",\n args=[\"yaxis.type\", \"log\"],\n ),\n ]\n ),\n ],\n xaxis=attr(\n title=L\"t\",\n ),\n yaxis=attr(\n type=\"log\",\n title=L\"\\beta\",\n )\n )\n)\n\np2 = plot(\n [\n scatter(y=α̅_linear, name=\"Linear\"),\n scatter(y=α̅_scaled_linear, name=\"Scaled linear\", visible=\"legendonly\"),\n scatter(y=α̅_cosine, name=\"Cosine\"),\n scatter(y=α̅_sigmoid, name=\"Sigmoid\", visible=\"legendonly\"),\n scatter(y=α̅_exponential, name=\"Exponential\", visible=\"legendonly\"),\n ],\n Layout(\n updatemenus=[\n attr(\n type=\"buttons\",\n buttons=[\n attr(\n label=\"Linear\",\n method=\"relayout\",\n args=[\"yaxis.type\", \"linear\"],\n ),\n attr(\n label=\"Log\",\n method=\"relayout\",\n args=[\"yaxis.type\", \"log\"],\n ),\n ],\n ),\n ],\n xaxis=attr(\n title=L\"t\",\n ),\n yaxis=attr(\n title=L\"\\overline\\alpha\",\n )\n )\n)\n\nmkpath(\"beta_schedules\")\nsavefig(p1, \"beta_schedules/beta_schedules.html\")\nsavefig(p2, \"beta_schedules/alpha_bar_schedules.html\")\nnothing","category":"page"},{"location":"beta_schedules/","page":"Beta Schedules","title":"Beta Schedules","text":"\n","category":"page"},{"location":"beta_schedules/","page":"Beta Schedules","title":"Beta Schedules","text":"Modules = [Diffusers.BetaSchedules]","category":"page"},{"location":"beta_schedules/#Diffusers.BetaSchedules.cosine_beta_schedule","page":"Beta Schedules","title":"Diffusers.BetaSchedules.cosine_beta_schedule","text":"Cosine beta schedule.\n\noverlinealpha_t = cos left( fract T + epsilon1 + epsilon fracpi2 right)\n\nInput\n\nT::Int: number of timesteps\nβₘₐₓ::Real=0.999f0: maximum value of β\nϵ::Real=1.0f-3: small value used to avoid division by zero\n\nOutput\n\nβ::Vector{Real}: βₜ values at each timestep t\n\nReferences\n\n[2, Improved Denoising Diffusion Probabilistic Models]\ngithub:openai/improved-diffusion/improveddiffusion/gaussiandiffusion.py\n\n\n\n\n\n","category":"function"},{"location":"beta_schedules/#Diffusers.BetaSchedules.exponential_beta_schedule","page":"Beta Schedules","title":"Diffusers.BetaSchedules.exponential_beta_schedule","text":"Exponential beta schedule.\n\noverlinealpha_t = exp left( frac-12 tT right)\n\nInput\n\nT::Int: number of timesteps\nβₘₐₓ::Real=0.999f0: maximum value of β\n\nOutput\n\nβ::Vector{Real}: βₜ values at each timestep t\n\n\n\n\n\n","category":"function"},{"location":"beta_schedules/#Diffusers.BetaSchedules.linear_beta_schedule","page":"Beta Schedules","title":"Diffusers.BetaSchedules.linear_beta_schedule","text":"Linear beta schedule.\n\nbeta_t = beta_1 + fract - 1T - 1 (beta_-1 - beta_1)\n\nInput\n\nT::Integer: number of timesteps\nβ₁::Real=1.0f-4: initial (t=1) value of β\nβ₋₁::Real=2.0f-2: final (t=T) value of β\n\nOutput\n\nβ::Vector{Real}: βₜ values at each timestep t\n\nReferences\n\n[3, Denoising Diffusion Probabilistic Models]\n\n\n\n\n\n","category":"function"},{"location":"beta_schedules/#Diffusers.BetaSchedules.rescale_zero_terminal_snr-Tuple{AbstractArray}","page":"Beta Schedules","title":"Diffusers.BetaSchedules.rescale_zero_terminal_snr","text":"Rescale β to have zero terminal Signal to Noise Ratio (SNR).\n\nInput\n\nβ::AbstractArray: βₜ values at each timestep t\n\nOutput\n\nβ::Vector{Real}: rescaled βₜ values at each timestep t\n\nReferences\n\n[4, Rescaling Diffusion Models (Alg. 1)]\n\n\n\n\n\n","category":"method"},{"location":"beta_schedules/#Diffusers.BetaSchedules.scaled_linear_beta_schedule","page":"Beta Schedules","title":"Diffusers.BetaSchedules.scaled_linear_beta_schedule","text":"Scaled linear beta schedule.\n\nbeta_t = left( sqrtbeta_1 + fract - 1T - 1 left( sqrtbeta_-1 - sqrtbeta_1 right) right)^2\n\nInput\n\nT::Int: number of timesteps\nβ₁::Real=1.0f-4: initial value of β\nβ₋₁::Real=2.0f-2: final value of β\n\nOutput\n\nβ::Vector{Real}: βₜ values at each timestep t\n\nReferences\n\n[3, Denoising Diffusion Probabilistic Models]\n\n\n\n\n\n","category":"function"},{"location":"beta_schedules/#Diffusers.BetaSchedules.sigmoid_beta_schedule","page":"Beta Schedules","title":"Diffusers.BetaSchedules.sigmoid_beta_schedule","text":"Sigmoid beta schedule.\n\nbeta_t = sigma left( 12 fract - 1T - 1 - 6 right) ( beta_-1 - beta_1 ) + beta_1\n\nInput\n\nT::Int: number of timesteps\nβ₁::Real=1.0f-4: initial value of β\nβ₋₁::Real=2.0f-2: final value of β\n\nOutput\n\nβ::Vector{Real}: βₜ values at each timestep t\n\nReferences\n\n[5, GeoDiff: a Geometric Diffusion Model for Molecular Conformation Generation]\ngithub.com:MinkaiXu/GeoDiff/models/epsnet/diffusion.py\n\n\n\n\n\n","category":"function"},{"location":"","page":"Home","title":"Home","text":"CurrentModule = Diffusers","category":"page"},{"location":"#Diffusers","page":"Home","title":"Diffusers","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Documentation for Diffusers.jl.","category":"page"},{"location":"#Index","page":"Home","title":"Index","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"","category":"page"}]
}