2023-08-06 19:19:04 +00:00
|
|
|
|
using Diffusers.BetaSchedules
|
|
|
|
|
using Test
|
|
|
|
|
|
|
|
|
|
@testset "Variance schedules tests" begin
|
2023-09-03 18:54:35 +00:00
|
|
|
|
|
2023-08-07 18:52:57 +00:00
|
|
|
|
@testset "SNR decreases monotonically" begin
|
2023-08-06 19:19:04 +00:00
|
|
|
|
T = 1000
|
|
|
|
|
|
2023-09-03 18:54:35 +00:00
|
|
|
|
for beta_schedule_type in [
|
|
|
|
|
linear_beta_schedule,
|
|
|
|
|
scaled_linear_beta_schedule,
|
|
|
|
|
cosine_beta_schedule,
|
|
|
|
|
sigmoid_beta_schedule,
|
|
|
|
|
exponential_beta_schedule,
|
|
|
|
|
]
|
|
|
|
|
@testset "Variance schedule == $beta_schedule_type" begin
|
|
|
|
|
β = beta_schedule_type(T)
|
|
|
|
|
α = 1 .- β
|
|
|
|
|
α̅ = cumprod(α)
|
|
|
|
|
|
|
|
|
|
SNR = α̅ ./ (1 .- α̅)
|
|
|
|
|
|
|
|
|
|
@test all(diff(SNR) .<= 0)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@testset "ZeroSNR rescaling" begin
|
|
|
|
|
T = 1000
|
|
|
|
|
|
|
|
|
|
for beta_schedule_type in [
|
|
|
|
|
linear_beta_schedule,
|
|
|
|
|
scaled_linear_beta_schedule,
|
|
|
|
|
cosine_beta_schedule,
|
|
|
|
|
sigmoid_beta_schedule,
|
|
|
|
|
exponential_beta_schedule,
|
|
|
|
|
]
|
|
|
|
|
@testset "Variance schedule == $beta_schedule_type" begin
|
|
|
|
|
β = rescale_zero_terminal_snr(beta_schedule_type(T))
|
|
|
|
|
α = 1 .- β
|
|
|
|
|
α̅ = cumprod(α)
|
|
|
|
|
|
|
|
|
|
SNR = α̅ ./ (1 .- α̅)
|
|
|
|
|
|
|
|
|
|
@test SNR[end] ≈ 0
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-08-06 19:19:04 +00:00
|
|
|
|
end
|
2023-09-03 18:54:35 +00:00
|
|
|
|
|
2023-08-06 19:19:04 +00:00
|
|
|
|
end
|