Diffusers.jl/docs/src/beta_schedules.md

2.2 KiB
Raw Blame History

using Diffusers.BetaSchedules
using LaTeXStrings
using PlotlyJS

T = 1000

β_linear = linear_beta_schedule(T)
β_scaled_linear = scaled_linear_beta_schedule(T)
β_cosine = cosine_beta_schedule(T)
β_sigmoid = sigmoid_beta_schedule(T)

α̅_linear = cumprod(1 .- β_linear)
α̅_scaled_linear = cumprod(1 .- β_scaled_linear)
α̅_cosine = cumprod(1 .- β_cosine)
α̅_sigmoid = cumprod(1 .- β_sigmoid)

p1 = plot(
  [
    scatter(y=β_linear, name="Linear"),
    scatter(y=β_scaled_linear, name="Scaled linear"),
    scatter(y=β_cosine, name="Cosine"),
    scatter(y=β_sigmoid, name="Sigmoid"),
  ],
  Layout(
    updatemenus=[
      attr(
        type="buttons",
        active=1,
        buttons=[
          attr(
            label="Linear",
            method="relayout",
            args=["yaxis.type", "linear"],
          ),
          attr(
            label="Log",
            method="relayout",
            args=["yaxis.type", "log"],
          ),
        ]
      ),
    ],
    title="Beta schedules",
    xaxis=attr(
      title=L"$t$",
    ),
    yaxis=attr(
      type="log",
      title=L"\beta",
    )
  )
)

savefig(p1, "fig_beta_schedules.html")

p2 = plot(
  [
    scatter(y=α̅_linear, name="Linear"),
    scatter(y=α̅_scaled_linear, name="Scaled linear"),
    scatter(y=α̅_cosine, name="Cosine"),
    scatter(y=α̅_sigmoid, name="Sigmoid"),
  ],
  Layout(
    updatemenus=[
      attr(
        type="buttons",
        buttons=[
          attr(
            label="Linear",
            method="relayout",
            args=["yaxis.type", "linear"],
          ),
          attr(
            label="Log",
            method="relayout",
            args=["yaxis.type", "log"],
          ),
        ],
      ),
    ],
    title="Cumulative alpha schedules",
    xaxis=attr(
      title=L"$t$",
    ),
    yaxis=attr(
      title=L"\overline\alpha",
    )
  )
)

savefig(p2, "fig_alpha_bar_schedules.html")

nothing
<object type="text/html" data="fig_beta_schedules.html" style="width:100%;height:420px;"></object>
<object type="text/html" data="fig_alpha_bar_schedules.html" style="width:100%;height:420px;"></object>
Modules = [Diffusers.BetaSchedules]