Download code/models/tt_dit/solvers/base.py from sunandbean/diffrhythm-1.2-p100a: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/sunandbean/diffrhythm-1.2-p100a/resolve/main/code/models/tt_dit/solvers/base.py
- Command line
-
hf download hf://sunandbean/diffrhythm-1.2-p100a/code/models/tt_dit/solvers/base.py
-
curl -L -o base.py https://huggingface.co/sunandbean/diffrhythm-1.2-p100a/resolve/main/code/models/tt_dit/solvers/base.py
2.27 kB
| # SPDX-FileCopyrightText: © 2026 Tenstorrent AI ULC | |
| # SPDX-License-Identifier: Apache-2.0 | |
| from __future__ import annotations | |
| from abc import ABC, abstractmethod | |
| from typing import Any | |
| import ttnn | |
| from .schedule import Schedule | |
| class Solver(ABC): | |
| """On-device solver for one denoising trajectory. | |
| A solver owns the scheduler defining its discretization (where it has one) and the | |
| `Schedule` derived from it, so the schedule has a single owner across a run. | |
| """ | |
| def __init__(self, *, scheduler: Any = None) -> None: | |
| self._scheduler = scheduler | |
| self._schedule = None | |
| def scheduler(self) -> Any: | |
| """The scheduler this solver was built from, or `None` if it has none.""" | |
| return self._scheduler | |
| def schedule(self) -> Schedule: | |
| if self._schedule is None: | |
| msg = "schedule must be set before stepping" | |
| raise ValueError(msg) | |
| return self._schedule | |
| def sigmas(self) -> tuple[float, ...]: | |
| return self.schedule.sigmas | |
| def alphas(self) -> tuple[float, ...]: | |
| return self.schedule.alphas | |
| def timesteps(self) -> tuple[float, ...]: | |
| return self.schedule.timesteps | |
| def set_schedule( | |
| self, num_inference_steps: int | None = None, *, shift: float | None = None, **kwargs: Any | |
| ) -> None: | |
| """Derive and adopt the schedule for one denoising run. | |
| Args: | |
| num_inference_steps: Number of denoising steps. | |
| shift: Flow shift for this run only; the construction-time value is used when | |
| omitted. Each solver maps this onto its own scheduler's spelling. | |
| kwargs: Solver-specific schedule arguments. | |
| """ | |
| def step(self, *, step: int, latent: ttnn.Tensor, velocity_pred: ttnn.Tensor) -> ttnn.Tensor: | |
| """Advance the latent one step toward the clean data. | |
| Args: | |
| step: Current step index into the sigmas/alphas schedule. | |
| latent: Noisy latent at the current step. | |
| velocity_pred: Predicted velocity at the current step. | |
| Returns: | |
| The predicted latent at the next step. | |
| """ | |