Skip to content

feat(xla): add bounded audio preprocessing and serving plumbing #873

Description

@inureyes

Parent and dependency

Problem

The image prepared-prefill contract is not sufficient for audio ingestion. Audio arrives as encoded bytes/URLs or waveform data, requires bounded decode/downmix/resample and family-specific feature extraction, has duration/frame masks rather than pixel grids, and can expand to a model-specific number of placeholder tokens. The XLA worker currently rejects audio before any of this state exists.

Family issues must not each invent their own unbounded decoding, request cancellation, sample-rate, or accounting policy.

Goal

Add a backend-neutral, bounded audio preprocessing and serving seam that family-specific Phi4MM and Gemma3n preprocessors can use to produce the existing owned prepared-prefill contract.

Canonical request contract

  • Represent each decoded clip as owned mono f32 samples plus explicit sample rate, source duration, and source metadata needed for diagnostics. Samples must be finite and normalized to [-1, 1] after conversion.
  • Keep encoded bytes and decoder handles out of mlxcel-xla and out of the prepared-prefill DTO.
  • Define a family preprocessor interface that consumes decoded clips plus logical prompt tokens and returns family-specific feature/mask tensors and finally an owned PreparedMultimodalPrefill.
  • Preserve per-clip boundaries, ordering, placeholder mapping, effective expanded token count, and internal audio-frame/token counts. Do not flatten multiple clips without lengths.

Required implementation

  • Reuse the existing CLI/server media acquisition, URL/data handling, byte limits, and audio decoder. Centralize downmix/resample/normalization so MLX and XLA families receive identical waveforms.
  • Make target sample rate, channel policy, maximum duration, feature dtype, and placeholder expansion model configuration, not global guesses. The first families use their pinned official processor settings.
  • Perform decode/resample/feature extraction in a bounded cancellable stage outside the XLA scheduler loop. Bound concurrent jobs, encoded bytes, decoded samples, total duration, feature frames, clips per request, and queued host memory.
  • Reject NaN/Inf samples, unsupported codecs, empty audio, excessive duration, arithmetic overflow, placeholder mismatch, and post-expansion context overflow with per-request typed errors.
  • Extend CLI and OpenAI-compatible request preparation to preserve audio parts in prompt order. Do not move placeholders outside their rendered user turn.
  • Carry cancellation through acquisition, decode, feature extraction, and queue submission. Large buffers must be released exactly once on every exit.
  • Add separate metrics for source seconds, decoded samples, feature frames, effective prefill tokens, preprocessing latency, and rejection reason. Preserve public token-usage semantics.
  • Keep XLA multimodal/audio capability false until a loaded family preprocessor and runtime bundle complete the path; foundation availability alone is not capability.
  • Continue explicit rejection for models/backends without audio support and for video unless separately implemented.

Non-goals

  • Implementing a Phi4MM or Gemma3n audio feature extractor/encoder.
  • Selecting one universal duration limit for all checkpoints.
  • Streaming audio ingestion or speech output.

Validation

  • Unit-test mono/stereo downmix, sample-rate conversion, integer/float normalization, empty/corrupt/nonfinite input, byte/duration/frame/count limits, multi-clip ordering, and placeholder mismatch.
  • Add deterministic resampling golden vectors so CLI and server produce byte/numerically identical waveforms.
  • Test cancellation at download, decode, resample, feature extraction, and pending-queue stages; verify host-buffer release and worker health.
  • Stress bounded concurrency with oversized requests beside valid text/image requests and prove scheduler progress and memory limits.
  • Add capability tests proving no request can be accepted and then have audio silently dropped.

Acceptance criteria

  • CLI/server share one bounded waveform normalization path and identical model inputs.
  • Family-specific sample rate/duration/feature policy is explicit configuration.
  • Multi-clip boundaries, prompt order, and placeholder mapping survive to the preprocessor.
  • Decode/preprocessing is bounded, cancellable, observable, and outside the scheduler loop.
  • All failure paths release buffers and affect only the failed request.
  • Public capability stays false until a complete family implementation is loaded.
  • Existing text/image request behavior is unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:architectureArchitecture and code structure changesarea:inferenceGeneration, sampling, decoding (incl. speculative, DRY)priority:mediumMedium prioritystatus:blockedBlocked by dependencies or other issuestype:enhancementNew features, capabilities, or significant additions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions