Skip to content

mlx_server

Serve native FastH3 MLX through the shared video-job API and playground.

Classes

fastvideo.entrypoints.openai.mlx_server.MLXH3Generator

MLXH3Generator(config: MLXGeneratorConfig)

Keep one pipeline on one MLX thread; preserve its phase-memory policy.

Source code in fastvideo/entrypoints/openai/mlx_server.py
def __init__(self, config: MLXGeneratorConfig) -> None:
    self._worker = ThreadPoolExecutor(max_workers=1, thread_name_prefix="h3-mlx")
    try:
        self._pipeline = self._worker.submit(self._load, config).result()
    except BaseException:
        self._worker.shutdown(wait=True)
        raise

Functions:

fastvideo.entrypoints.openai.mlx_server.validate_mlx_video_request

validate_mlx_video_request(request: VideoGenerationRequest) -> None

Reject unsupported inputs before fetching media or creating a job.

Source code in fastvideo/entrypoints/openai/mlx_server.py
def validate_mlx_video_request(request: VideoGenerationRequest) -> None:
    """Reject unsupported inputs before fetching media or creating a job."""
    allowed = {
        "model",
        "prompt",
        "seed",
        "size",
        "width",
        "height",
        "fps",
        "num_frames",
        "seconds",
        "video_params",
        "task",
        "guidance_scale",
        "num_inference_steps",
        "negative_prompt",
    }
    unsupported = request.model_fields_set - allowed
    if unsupported:
        raise ValueError("H3 MLX serving does not support: " + ", ".join(sorted(unsupported)))
    if request.task not in (None, "t2va"):
        raise ValueError("H3 MLX serving supports task=t2va only.")
    if request.guidance_scale not in (None, 1.0):
        raise ValueError("FastH3 MLX requires guidance_scale=1.")
    if request.negative_prompt not in (None, ""):
        raise ValueError("FastH3 MLX does not use a negative prompt.")
    if request.num_inference_steps not in (None, 5):
        raise ValueError(
            "FastH3 MLX serving uses five sigma points and four DiT forwards; num_inference_steps must be 5.")
    if request.seed is not None and not 0 <= request.seed <= 2**32 - 1:
        raise ValueError("H3 MLX seed must be between 0 and 4294967295.")