mlx_runtime ¶
Experimental Apple MLX runtime helpers.
This package is intentionally small for now. It exists to grow the Apple-native FastWan path in measurable steps: shape planning, primitive benchmarks, then Wan block parity, then full DiT/runtime support.
Classes¶
fastvideo.mlx_runtime.AppliedMemoryLimits dataclass ¶
AppliedMemoryLimits(mlx_memory_limit_gib: float | None = None, mlx_cache_limit_gib: float | None = None, mlx_disable_cache: bool = False, mlx_wired_limit_gib: float | None = None, torch_mps_high_watermark_ratio: float | None = None, torch_mps_low_watermark_ratio: float | None = None, applied_bytes: dict[str, int] = dict(), previous_bytes: dict[str, int] = dict(), errors: dict[str, str] = dict())
Memory limits applied for one Apple Silicon benchmark/generation process.
Methods:¶
fastvideo.mlx_runtime.AppliedMemoryLimits.as_metrics ¶
Flatten the configured memory limits, applied values, previous values, and errors into a metrics dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, int | float | str | bool | None] | dict[str, int | float | str | bool | None]: Metrics keyed by limit names and their corresponding values. |
Source code in fastvideo/mlx_runtime/memory.py
fastvideo.mlx_runtime.EnhanceResult dataclass ¶
EnhanceResult(original: str, enhanced: str, backend: str, elapsed_s: float, model: str | None = None)
Outcome of a prompt enrichment call.
fastvideo.mlx_runtime.FastSpatialPlan dataclass ¶
FastSpatialPlan(plan: RefinePlan, upsample_mode: str, sharpen: float = DEFAULT_FAST_SPATIAL_SHARPEN)
Resolved geometry for a spatial-fast (upsample-only) run.
Attributes¶
fastvideo.mlx_runtime.FastSpatialPlan.enabled property ¶
enabled: bool
Determine whether spatial scaling is enabled.
Returns:
| Type | Description |
|---|---|
bool |
|
fastvideo.mlx_runtime.FastSpatialPlan.scale property ¶
scale: int
Provides the configured spatial scaling factor.
Returns:
| Name | Type | Description |
|---|---|---|
int | int | The spatial scaling factor. |
fastvideo.mlx_runtime.FastSpatialPlan.stage1_height property ¶
stage1_height: int
Provide the stage-one latent height used for reduced-resolution processing.
Returns:
| Name | Type | Description |
|---|---|---|
int | int | The stage-one latent height. |
fastvideo.mlx_runtime.MLXQuantizationSpec dataclass ¶
MLX quantized-matmul configuration for DiT linear weights.
fastvideo.mlx_runtime.MLXWanDiT ¶
MLXWanDiT(weights: dict[str, array], blocks: list[MLXWanTransformerBlock], config: dict, *, compile: bool = False)
Experimental FP16 Wan/FastWan DiT forward path in MLX.
Source code in fastvideo/mlx_runtime/fastwan.py
fastvideo.mlx_runtime.MLXWanTransformerBlock ¶
MLXWanTransformerBlock(weights: dict[str, array], *, dim: int, ffn_dim: int, num_heads: int, eps: float = 1e-06)
Dense T2V Wan transformer block for the experimental MLX runtime.
This mirrors the non-VSA PyTorch block for single-process dense attention. Rotary embeddings and sequence-parallel paths are intentionally left out of this first parity target.
Source code in fastvideo/mlx_runtime/fastwan.py
fastvideo.mlx_runtime.RefinePlan dataclass ¶
RefinePlan(target_height: int, target_width: int, stage1_height: int, stage1_width: int, spatial_scale: int, vae_spatial_compression: int, vae_temporal_compression: int, num_frames: int)
Resolved stage-1 / stage-2 geometry for a two-pass refine run.
Attributes¶
fastvideo.mlx_runtime.RefinePlan.latent_frames property ¶
latent_frames: int
Calculate the number of latent frames after VAE temporal compression.
Returns:
| Name | Type | Description |
|---|---|---|
int | int | The compressed latent frame count. |
fastvideo.mlx_runtime.RefinePlan.stage1_latent_height property ¶
stage1_latent_height: int
Return the stage-1 latent height after VAE spatial compression.
fastvideo.mlx_runtime.RefinePlan.stage1_latent_width property ¶
stage1_latent_width: int
Return the stage-one latent width after VAE spatial compression.
fastvideo.mlx_runtime.TwoPassResult dataclass ¶
TwoPassResult(latents: Any, stage1_latents: Any, plan: RefinePlan, refine_sigma: float)
Outputs of :func:run_two_pass_dmd.
fastvideo.mlx_runtime.UnsupportedMLXQuantizationError ¶
Bases: ValueError
A quantization mode the installed MLX build cannot execute.
Raised by :func:ensure_quantization_supported before any model weights are loaded, so callers (CLI flags, benchmark sweeps) can fail fast with an actionable message -- or skip the mode -- instead of crashing deep inside mx.quantize mid-load.
Functions:¶
fastvideo.mlx_runtime.add_memory_limit_args ¶
add_memory_limit_args(parser: ArgumentParser, *, mlx_memory_limit_gib: float | None = None, mlx_cache_limit_gib: float | None = None, mlx_disable_cache: bool = False, mlx_wired_limit_gib: float | None = None, torch_mps_high_watermark_ratio: float | None = None, torch_mps_low_watermark_ratio: float | None = None) -> None
Add configurable Apple Silicon memory-limit options to an argument parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser | ArgumentParser | Parser to which the options are added. | required |
mlx_memory_limit_gib | float | None | Default MLX memory limit in GiB. | None |
mlx_cache_limit_gib | float | None | Default MLX cache limit in GiB. | None |
mlx_disable_cache | bool | Whether the cache limit defaults to zero. | False |
mlx_wired_limit_gib | float | None | Default MLX wired-memory limit in GiB. | None |
torch_mps_high_watermark_ratio | float | None | Default PyTorch MPS high-watermark ratio. | None |
torch_mps_low_watermark_ratio | float | None | Default PyTorch MPS low-watermark ratio. | None |
Source code in fastvideo/mlx_runtime/memory.py
fastvideo.mlx_runtime.apply_fast_spatial_upsample ¶
apply_fast_spatial_upsample(frames: Iterable[ndarray], spatial: FastSpatialPlan) -> list[ndarray]
Resample decoded stage-1 frames up to the target resolution.
This runs on decoded RGB frames, not on latents: see the module docstring for why the latent-space version produced a blurred veil.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames | Iterable[ndarray] | Decoded HxWx3 uint8 RGB frames, produced by decoding at the stage-one resolution. | required |
spatial | FastSpatialPlan | Plan defining the target size, interpolation kernel, and unsharp strength. | required |
Returns:
| Type | Description |
|---|---|
list[ndarray] | list[np.ndarray]: Frames at the target resolution. When spatial scaling is disabled the frames are returned unchanged, as a list. |
Source code in fastvideo/mlx_runtime/fast_spatial.py
fastvideo.mlx_runtime.apply_memory_limits ¶
apply_memory_limits(*, mlx_memory_limit_gib: float | None = None, mlx_cache_limit_gib: float | None = None, mlx_disable_cache: bool = False, mlx_wired_limit_gib: float | None = None, torch_mps_high_watermark_ratio: float | None = None, torch_mps_low_watermark_ratio: float | None = None, mx_module: Any | None = None) -> AppliedMemoryLimits
Apply optional MLX allocator limits and PyTorch MPS watermarks.
PyTorch reads MPS watermark variables when the MPS backend initializes, so call this before importing PyTorch. Specifying only a high watermark sets the low watermark to 0.0. MLX limit-setting failures are recorded in the result and do not prevent other limits from being applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mlx_memory_limit_gib | float | None | Maximum MLX memory in GiB. | None |
mlx_cache_limit_gib | float | None | Maximum MLX cache size in GiB. | None |
mlx_disable_cache | bool | Whether to disable the MLX cache. | False |
mlx_wired_limit_gib | float | None | Maximum MLX wired memory in GiB. | None |
torch_mps_high_watermark_ratio | float | None | PyTorch MPS high watermark ratio. | None |
torch_mps_low_watermark_ratio | float | None | PyTorch MPS low watermark ratio. | None |
Returns:
| Name | Type | Description |
|---|---|---|
AppliedMemoryLimits | AppliedMemoryLimits | Configured values, applied and previous MLX byte limits, MPS watermark values, and per-limit errors. |
Source code in fastvideo/mlx_runtime/memory.py
fastvideo.mlx_runtime.default_refine_timesteps ¶
Derive stage-2 timesteps from the stage-1 DMD grid.
The stage-2 pass must start below full noise, otherwise the hand-off (1 - sigma) * upsampled + sigma * noise weights stage 1 at zero and the refine pass silently becomes a plain full-resolution generation at twice the cost. FastWan's stage-1 grid opens at t=1000 (sigma exactly 1.0), so reusing it verbatim — which is what happens when --refine-dmd-denoising-steps is left unset — discards stage 1.
Dropping the leading full-noise entries keeps the pass on timesteps the distilled student was actually trained on (no off-grid t the DiT has never seen) while letting the stage-1 structure through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schedule | MLXDMDSchedule | Schedule used to map timesteps to noise levels. | required |
timesteps | Sequence[float | int] | The stage-1 DMD timestep grid. | required |
Returns:
| Type | Description |
|---|---|
list[float] | list[float]: The stage-1 grid with leading full-noise timesteps removed. |
Raises:
| Type | Description |
|---|---|
ValueError | If every timestep in the grid is at full noise, leaving no usable refine step. |
Source code in fastvideo/mlx_runtime/refine.py
fastvideo.mlx_runtime.enhance_prompt ¶
enhance_prompt(prompt: str, *, backend: str = 'auto', model: str | None = None, system_prompt: str = DEFAULT_ENHANCE_SYSTEM_PROMPT, max_tokens: int = 128) -> EnhanceResult
Enhance a prompt using the selected backend, falling back to a deterministic template when configured for automatic selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt | str | The prompt to enhance. | required |
backend | str | The enhancement backend: | 'auto' |
model | str | None | The MLX language model to use. | None |
system_prompt | str | Instructions provided to the MLX language model. | DEFAULT_ENHANCE_SYSTEM_PROMPT |
max_tokens | int | Maximum number of tokens generated by the MLX language model. | 128 |
Returns:
| Name | Type | Description |
|---|---|---|
EnhanceResult | EnhanceResult | The original and enhanced prompts, selected backend, timing information, and model metadata. |
Raises:
| Type | Description |
|---|---|
ValueError | If the prompt is empty or the backend is unsupported. |
Exception | If the explicitly selected |
Source code in fastvideo/mlx_runtime/prompt_enhance.py
fastvideo.mlx_runtime.enhance_prompt_template ¶
Expand a prompt with cinematic camera, lighting, motion, and visual-quality details.
Rich prompts are preserved, while thinner prompts receive deterministic enhancements without changing their subject.
Returns:
| Name | Type | Description |
|---|---|---|
str | str | The original or expanded prompt with normalized whitespace and punctuation. |
Source code in fastvideo/mlx_runtime/prompt_enhance.py
fastvideo.mlx_runtime.enhance_result_as_metrics ¶
enhance_result_as_metrics(result: EnhanceResult | None) -> dict[str, Any]
Convert prompt enhancement results into metrics fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result | EnhanceResult | None | The enhancement result, or | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | dict[str, Any]: A metrics mapping containing enhancement status, backend metadata, timing, and original and enhanced prompts. |
Source code in fastvideo/mlx_runtime/prompt_enhance.py
fastvideo.mlx_runtime.ensure_quantization_supported ¶
ensure_quantization_supported(spec: MLXQuantizationSpec | None) -> None
Raise :class:UnsupportedMLXQuantizationError if spec cannot run here.
Source code in fastvideo/mlx_runtime/fastwan.py
fastvideo.mlx_runtime.fastwan_shape ¶
fastwan_shape(*, height: int, width: int, num_frames: int, vae_temporal_compression: int = 4, vae_spatial_compression: int = 8, patch_size: tuple[int, int, int] = (1, 2, 2), num_heads: int = 12, head_dim: int = 128) -> FastWanShape
Return the approximate DiT token shape for Wan/FastWan T2V inference.
Source code in fastvideo/mlx_runtime/fastwan.py
fastvideo.mlx_runtime.gib_to_bytes ¶
Convert a positive memory limit from GiB to bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value | float | None | Memory limit in GiB, or | required |
Returns:
| Type | Description |
|---|---|
int | None | int | None: The memory limit in bytes, or |
Raises:
| Type | Description |
|---|---|
ValueError | If |
Source code in fastvideo/mlx_runtime/memory.py
fastvideo.mlx_runtime.load_mlx_dit_checkpoint ¶
Reconstruct an MLXWanDiT model from a versioned checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_dir | str | Path | Directory containing the checkpoint manifest and weights. | required |
compile | bool | Whether to configure the reconstructed model for compilation. | False |
Returns:
| Name | Type | Description |
|---|---|---|
MLXWanDiT | MLXWanDiT | The reconstructed model. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If the checkpoint manifest or weights file is missing. |
ValueError | If the checkpoint format is unsupported or block weights are incomplete. |
Source code in fastvideo/mlx_runtime/checkpoint.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
fastvideo.mlx_runtime.load_or_enhance_prompt ¶
load_or_enhance_prompt(prompt: str, *, backend: str = 'auto', model: str | None = None, system_prompt: str = DEFAULT_ENHANCE_SYSTEM_PROMPT, max_tokens: int = 128, cache: bool = True, cache_dir: Path | None = None) -> EnhanceResult
Enhance a prompt, reusing a cached result when available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt | str | The prompt to enhance. | required |
backend | str | Enhancement backend to use. | 'auto' |
model | str | None | Optional model identifier. | None |
system_prompt | str | System prompt for model-based enhancement. | DEFAULT_ENHANCE_SYSTEM_PROMPT |
max_tokens | int | Maximum number of tokens generated by the model. | 128 |
cache | bool | Whether to read and write the on-disk cache. | True |
cache_dir | Path | None | Optional directory for cached results. | None |
Returns:
| Name | Type | Description |
|---|---|---|
EnhanceResult | EnhanceResult | The enhanced prompt and backend metadata. Cached results are marked with the |
Source code in fastvideo/mlx_runtime/prompt_enhance.py
fastvideo.mlx_runtime.mlx_block_weights_from_diffusers_safetensors ¶
mlx_block_weights_from_diffusers_safetensors(checkpoint_path: str | Path, *, block_index: int = 0, quantization: str | MLXQuantizationSpec | None = None, dtype=None) -> dict[str, array]
Load one Diffusers-format Wan block into the MLX dense-block key layout.
Source code in fastvideo/mlx_runtime/fastwan.py
fastvideo.mlx_runtime.plan_fast_spatial ¶
plan_fast_spatial(*, height: int, width: int, num_frames: int, spatial_scale: int = 2, vae_spatial_compression: int = 8, vae_temporal_compression: int = 4, patch_size: tuple[int, int, int] = (1, 2, 2), upsample_mode: str = DEFAULT_PIXEL_UPSAMPLE_MODE, sharpen: float = DEFAULT_FAST_SPATIAL_SHARPEN, enabled: bool = True) -> FastSpatialPlan
Build a plan for reduced-resolution denoising followed by pixel-space upsampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upsample_mode | str | Pixel interpolation kernel, one of :data: | DEFAULT_PIXEL_UPSAMPLE_MODE |
sharpen | float | Unsharp strength applied after the resize. | DEFAULT_FAST_SPATIAL_SHARPEN |
Returns:
| Name | Type | Description |
|---|---|---|
FastSpatialPlan | FastSpatialPlan | The validated spatial-fast processing plan. |
Raises:
| Type | Description |
|---|---|
ValueError | If the upsample mode is unsupported or |
Source code in fastvideo/mlx_runtime/fast_spatial.py
fastvideo.mlx_runtime.plan_refine_resolutions ¶
plan_refine_resolutions(*, height: int, width: int, num_frames: int, spatial_scale: int = 2, vae_spatial_compression: int = 8, vae_temporal_compression: int = 4, patch_size: tuple[int, int, int] = (1, 2, 2), enabled: bool = True, mode_label: str = 'Refine') -> RefinePlan
Validate the requested dimensions and create the stage-1 and target-resolution refinement plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height | int | Target image height in pixels. | required |
width | int | Target image width in pixels. | required |
num_frames | int | Number of frames in the input sequence. | required |
spatial_scale | int | Factor used to reduce spatial dimensions for stage 1. | 2 |
vae_spatial_compression | int | Spatial compression factor of the VAE. | 8 |
vae_temporal_compression | int | Temporal compression factor of the VAE. | 4 |
patch_size | tuple[int, int, int] | Temporal and spatial patch dimensions used to validate latent-grid alignment. | (1, 2, 2) |
enabled | bool | Whether to use two-pass refinement. | True |
mode_label | str | Name of the calling mode, used to prefix validation errors so | 'Refine' |
Returns:
| Name | Type | Description |
|---|---|---|
RefinePlan | RefinePlan | The validated stage-1 and target-resolution plan. |
Source code in fastvideo/mlx_runtime/refine.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
fastvideo.mlx_runtime.prepare_refine_latents ¶
prepare_refine_latents(clean_latents: Any, *, scale: int = 2, sigma: float = DEFAULT_REFINE_SIGMA, noise: Any | None = None, add_noise_flag: bool = True, upsample_mode: str = 'bilinear', seed: int | None = None) -> Any
Upsample clean latents spatially and optionally mix them with Gaussian noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clean_latents | Any | The stage-1 latent tensor. | required |
sigma | float | Noise mixing factor between 0 and 1. | DEFAULT_REFINE_SIGMA |
noise | Any | None | Optional noise tensor to mix with the upsampled latents. | None |
add_noise_flag | bool | Whether to apply noise mixing. | True |
upsample_mode | str | Spatial interpolation mode. | 'bilinear' |
seed | int | None | Optional seed for generated noise. | None |
Returns:
| Type | Description |
|---|---|
Any | The upsampled latents, optionally mixed with noise. |
Raises:
| Type | Description |
|---|---|
ValueError | If sigma is outside the range from 0 to 1. |
Source code in fastvideo/mlx_runtime/refine.py
fastvideo.mlx_runtime.quantization_support_error ¶
quantization_support_error(spec: MLXQuantizationSpec) -> str | None
Probe whether the installed MLX build supports spec.
Runs a tiny mx.quantize + mx.quantized_matmul with exactly the arguments :func:quantize_matrix / :func:linear use, so the result reflects the real runtime path. The affine (int8/int4) modes are stable across MLX releases, but the mxfp8/mxfp4/nvfp4 mode strings require newer MLX builds and raise otherwise. Returns None when the mode works, else the underlying error message. Cached per spec.
Source code in fastvideo/mlx_runtime/fastwan.py
fastvideo.mlx_runtime.refine_sigma_from_schedule ¶
refine_sigma_from_schedule(schedule: MLXDMDSchedule, timesteps: Sequence[float | int]) -> float
Derive the refinement noise level from the first refinement timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schedule | MLXDMDSchedule | Schedule used to map timesteps to noise levels. | required |
timesteps | Sequence[float | int] | Refinement timesteps, whose first value determines the sigma. | required |
Returns:
| Name | Type | Description |
|---|---|---|
float | float | Sigma corresponding to the first refinement timestep. |
Raises:
| Type | Description |
|---|---|
ValueError | If |
Source code in fastvideo/mlx_runtime/refine.py
fastvideo.mlx_runtime.resolve_spatial_mode ¶
Select the active spatial processing mode, with refinement taking precedence.
Returns:
| Name | Type | Description |
|---|---|---|
str | str |
|
Source code in fastvideo/mlx_runtime/fast_spatial.py
fastvideo.mlx_runtime.run_dmd_loop ¶
run_dmd_loop(*, dit: Any, latents: Any, encoder_hidden_states: Any, freqs_cis: tuple[Any, Any], timesteps: Sequence[float | int], schedule: MLXDMDSchedule, mx_dtype: Any, seed: int | None = None, step_callback: Callable[[int, int], None] | None = None, label: str = 'denoise') -> Any
Denoise latents over the supplied timesteps using the DMD schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timesteps | Sequence[float | int] | Denoising timesteps in execution order. | required |
seed | int | None | Seed for reproducible intermediate noise generation. | None |
step_callback | Callable[[int, int], None] | None | Callback receiving the completed step number and total step count. | None |
label | str | Label used for progress output when no callback is provided. | 'denoise' |
Returns:
| Name | Type | Description |
|---|---|---|
Any | Any | The denoised latents. |
Source code in fastvideo/mlx_runtime/refine.py
fastvideo.mlx_runtime.run_two_pass_dmd ¶
run_two_pass_dmd(*, dit: Any, encoder_hidden_states: Any, noise_latents_stage1: Any, freqs_cis_stage1: tuple[Any, Any], freqs_cis_stage2: tuple[Any, Any] | None, plan: RefinePlan, schedule: MLXDMDSchedule, timesteps: Sequence[float | int], refine_timesteps: Sequence[float | int] | None = None, mx_dtype: Any, seed: int = 0, add_noise_flag: bool = True, upsample_mode: str = 'bilinear', refine_sigma: float | None = None, step_callback: Callable[[str, int, int], None] | None = None) -> TwoPassResult
Run base denoising and, when enabled, spatial refinement denoising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dit | Any | DiT callable used for both denoising passes. | required |
encoder_hidden_states | Any | Prompt embeddings shared across both passes. | required |
noise_latents_stage1 | Any | Initial stage-1 noise latents. | required |
freqs_cis_stage1 | tuple[Any, Any] | RoPE tables for the stage-1 resolution. | required |
freqs_cis_stage2 | tuple[Any, Any] | None | RoPE tables for the stage-2 resolution, required when refinement is enabled. | required |
plan | RefinePlan | Refinement geometry and configuration. | required |
schedule | MLXDMDSchedule | Flow-matching schedule used by both passes. | required |
timesteps | Sequence[float | int] | Stage-1 denoising timesteps. | required |
refine_timesteps | Sequence[float | int] | None | Stage-2 denoising timesteps. Uses | None |
mx_dtype | Any | MLX dtype used for DiT inputs and outputs. | required |
seed | int | Base seed for reproducible noise generation. | 0 |
add_noise_flag | bool | Whether to add noise to the upsampled stage-1 latents. | True |
upsample_mode | str | Spatial upsampling mode, either | 'bilinear' |
refine_sigma | float | None | Stage-2 starting noise level. Derived from the first refinement timestep when omitted. | None |
step_callback | Callable[[str, int, int], None] | None | Optional callback receiving the phase name, step index, and total step count. | None |
Returns:
| Type | Description |
|---|---|
TwoPassResult | TwoPassResult containing the final latents, stage-1 latents, refinement plan, and applied refinement sigma. |
Raises:
| Type | Description |
|---|---|
ValueError | If refinement is enabled without stage-2 RoPE tables, without refinement timesteps, or if upsampled latents do not match the planned stage-2 dimensions. |
Source code in fastvideo/mlx_runtime/refine.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | |
fastvideo.mlx_runtime.save_mlx_dit_checkpoint ¶
Save a plain or quantized MLX Wan DiT checkpoint to a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dit | MLXWanDiT | Model whose weights and configuration will be saved. | required |
checkpoint_dir | str | Path | Destination directory for the checkpoint. | required |
Returns:
| Name | Type | Description |
|---|---|---|
Path | Path | Path to the checkpoint directory. |
Source code in fastvideo/mlx_runtime/checkpoint.py
fastvideo.mlx_runtime.unsharp ¶
unsharp(frame: ndarray, amount: float) -> ndarray
Light unsharp mask, used to counter resampling / optical-flow softening.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame | ndarray | HxWx3 uint8 RGB frame. | required |
amount | float | Strength; | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: A new frame; the input is never modified in place. |
Source code in fastvideo/mlx_runtime/frame_upsample.py
fastvideo.mlx_runtime.upsample_frame ¶
upsample_frame(frame: ndarray, *, width: int, height: int, mode: str = DEFAULT_PIXEL_UPSAMPLE_MODE, sharpen: float = 0.0) -> ndarray
Resample one decoded RGB frame to the target pixel size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame | ndarray | HxWx3 uint8 RGB frame. | required |
width | int | Target width in pixels. | required |
height | int | Target height in pixels. | required |
mode | str | Interpolation kernel, one of :data: | DEFAULT_PIXEL_UPSAMPLE_MODE |
sharpen | float | Unsharp strength applied after the resize. | 0.0 |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: A new frame at |
Raises:
| Type | Description |
|---|---|
ValueError | If the frame is not HxWx3, or the target size is not positive. |
Source code in fastvideo/mlx_runtime/frame_upsample.py
fastvideo.mlx_runtime.upsample_frames ¶
upsample_frames(frames: Iterable[ndarray], *, width: int, height: int, mode: str = DEFAULT_PIXEL_UPSAMPLE_MODE, sharpen: float = 0.0) -> list[ndarray]
Resample every decoded frame to the target pixel size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames | Iterable[ndarray] | Decoded HxWx3 uint8 RGB frames. | required |
width | int | Target width in pixels. | required |
height | int | Target height in pixels. | required |
mode | str | Interpolation kernel, one of :data: | DEFAULT_PIXEL_UPSAMPLE_MODE |
sharpen | float | Unsharp strength applied after each resize. | 0.0 |
Returns:
| Type | Description |
|---|---|
list[ndarray] | list[np.ndarray]: New frames at the target size, in input order. |
Source code in fastvideo/mlx_runtime/frame_upsample.py
fastvideo.mlx_runtime.upsample_latents_spatial ¶
Upsample the spatial dimensions of 5-D latent arrays while preserving the batch, channel, and temporal dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latents | Any | Latents with shape | required |
scale | int | Integer factor for enlarging the spatial dimensions. | 2 |
mode | str | Interpolation mode, either | 'bilinear' |
Returns:
| Name | Type | Description |
|---|---|---|
Any | Any | Latents with shape |