mirror of
https://github.com/Laurent2916/Diffusers.jl.git
synced 2024-09-19 19:15:27 +00:00
✨ (Schedulers) create Abstract.jl holding scheduler type and methods
This commit is contained in:
parent
9d5201d068
commit
42c2bcb5bb
44
src/Schedulers/Abstract.jl
Normal file
44
src/Schedulers/Abstract.jl
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
"""
|
||||||
|
Abstract type for schedulers.
|
||||||
|
|
||||||
|
"""
|
||||||
|
abstract type Scheduler end
|
||||||
|
|
||||||
|
"""
|
||||||
|
Add noise to clean data using the forward diffusion process.
|
||||||
|
|
||||||
|
## Input
|
||||||
|
* `scheduler::Scheduler`: scheduler to use
|
||||||
|
* `x₀::AbstractArray`: clean data to add noise to
|
||||||
|
* `ϵ::AbstractArray`: noise to add to clean data
|
||||||
|
* `t::AbstractArray`: timesteps used to weight the noise
|
||||||
|
|
||||||
|
## Output
|
||||||
|
* `xₜ::AbstractArray`: noisy data at the given timesteps
|
||||||
|
"""
|
||||||
|
function add_noise(
|
||||||
|
scheduler::Scheduler,
|
||||||
|
x₀::AbstractArray,
|
||||||
|
ϵ::AbstractArray,
|
||||||
|
t::AbstractArray,
|
||||||
|
) end
|
||||||
|
|
||||||
|
"""
|
||||||
|
Remove noise from model output using the backward diffusion process.
|
||||||
|
|
||||||
|
## Input
|
||||||
|
* `scheduler::Scheduler`: scheduler to use
|
||||||
|
* `xₜ::AbstractArray`: sample to be denoised
|
||||||
|
* `ϵᵧ::AbstractArray`: predicted noise to remove
|
||||||
|
* `t::AbstractArray`: timestep t of `xₜ`
|
||||||
|
|
||||||
|
## Output
|
||||||
|
* `xₜ₋₁::AbstractArray`: denoised sample at t=t-1
|
||||||
|
* `x̂₀::AbstractArray`: denoised sample at t=0
|
||||||
|
"""
|
||||||
|
function step(
|
||||||
|
scheduler::Scheduler,
|
||||||
|
xₜ::AbstractArray,
|
||||||
|
ϵᵧ::AbstractArray,
|
||||||
|
t::AbstractArray,
|
||||||
|
) end
|
|
@ -1,8 +1,4 @@
|
||||||
"""
|
include("Abstract.jl")
|
||||||
Abstract type for schedulers.
|
|
||||||
|
|
||||||
"""
|
|
||||||
abstract type Scheduler end
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Denoising Diffusion Probabilistic Models (DDPM) scheduler.
|
Denoising Diffusion Probabilistic Models (DDPM) scheduler.
|
||||||
|
@ -69,18 +65,6 @@ function DDPM(V::DataType, β::AbstractVector)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
"""
|
|
||||||
Add noise to clean data using the forward diffusion process.
|
|
||||||
|
|
||||||
## Input
|
|
||||||
* `scheduler::DDPM`: scheduler to use
|
|
||||||
* `x₀::AbstractArray`: clean data to add noise to
|
|
||||||
* `ϵ::AbstractArray`: noise to add to clean data
|
|
||||||
* `t::AbstractArray`: timesteps used to weight the noise
|
|
||||||
|
|
||||||
## Output
|
|
||||||
* `xₜ::AbstractArray`: noisy data at the given timesteps
|
|
||||||
"""
|
|
||||||
function add_noise(
|
function add_noise(
|
||||||
scheduler::DDPM,
|
scheduler::DDPM,
|
||||||
x₀::AbstractArray,
|
x₀::AbstractArray,
|
||||||
|
@ -102,19 +86,6 @@ function add_noise(
|
||||||
return xₜ
|
return xₜ
|
||||||
end
|
end
|
||||||
|
|
||||||
"""
|
|
||||||
Remove noise from model output using the backward diffusion process.
|
|
||||||
|
|
||||||
## Input
|
|
||||||
* `scheduler::DDPM`: scheduler to use
|
|
||||||
* `xₜ::AbstractArray`: sample to be denoised
|
|
||||||
* `ϵᵧ::AbstractArray`: predicted noise to remove
|
|
||||||
* `t::AbstractArray`: timestep t of `xₜ`
|
|
||||||
|
|
||||||
## Output
|
|
||||||
* `xₜ₋₁::AbstractArray`: denoised sample at t=t-1
|
|
||||||
* `x̂₀::AbstractArray`: denoised sample at t=0
|
|
||||||
"""
|
|
||||||
function step(
|
function step(
|
||||||
scheduler::DDPM,
|
scheduler::DDPM,
|
||||||
xₜ::AbstractArray,
|
xₜ::AbstractArray,
|
||||||
|
|
Loading…
Reference in a new issue