Skip to content

feat(image): honor JPEG/WebP quality in H3-Image and synchronous responses - #1704

Open
NorthCedar wants to merge 3 commits into
ModelTC:mainfrom
NorthCedar:feat/image-output-encoding
Open

NorthCedar wants to merge 3 commits into
ModelTC:mainfrom
NorthCedar:feat/image-output-encoding

Conversation

@NorthCedar

@NorthCedar NorthCedar commented Nov 13, 2026 •

Copy link
Copy Markdown

Closes #1702.

Problem

MiniMax-H3-Image has no request-level output quality setting. Its PIL and OpenCV file writers use their encoder defaults, while synchronous image APIs always encode PNG and report PNG in response metadata, download filenames and presigned-upload Content-Type. Selecting a JPEG/WebP output filename therefore does not select that format for synchronous responses.

This prevents callers from trading file size against image quality.

Change

  • Add output_compression to H3-Image CLI, Python generation, startup defaults and image requests: integer 0–100, default 95. Explicit zero is retained; invalid values are rejected before inference.
  • Apply JPEG/WebP quality in both H3-Image save paths (pil and opencv). PNG ignores the setting. Shared file-writer callers that omit quality retain their previous encoder defaults.
  • Select PNG/JPEG/WebP from save_result_path; synchronous requests without a filename suffix default to PNG. No output_format request field is added.
  • Encode Tensor/NumPy results directly through PIL for JPEG/WebP, avoiding an intermediate PNG encode/decode. Preserve the existing NumPy BGR and Tensor RGB conventions, including grayscale and alpha handling.
  • Carry encoded bytes through the synchronous worker and result cache, and derive response metadata, URL filenames, download MIME types and presigned-upload Content-Type from the actual format.

The synchronous encoding change is shared by image-serving runners; per-request field admission remains model-specific. This does not change model inference or sampling.

Testing

92 CPU tests passed, covering both actual H3-Image runner save paths, JPEG/WebP quality-dependent files, PNG invariance, synchronous responses, download/upload types, pixel conversion and validation. Additional checks covered startup defaults, request overrides/reset, explicit zero, Python/CLI forwarding and cache eviction.

Additional deployment validation passed 79 CPU encoding/API tests using the existing runtime dependencies. Checks against the adapted runner covered request-field admission, startup defaults, request overrides and reset, explicit zero, invalid values, JPEG/WebP file encoding and PNG invariance.

Eleven text-to-image requests completed successfully on four MUSA GPUs with a fixed prompt, seed 42 and 2048 × 2048 output, exercising native synchronous and OpenAI-compatible generation APIs. JPEG/WebP file sizes changed with the requested quality, explicit zero was honored, and omitted quality matched explicit 95 in same-interface comparisons. PNG outputs at quality 10 and 95 were byte-identical. Invalid quality values returned HTTP 422. Response formats, filenames and actual download Content-Type values matched the encoded images; downloaded content was byte-identical to the generated files. The service remained healthy with no task failures or container restarts.

Fixed-image encoding measurements are recorded in #1702 (832 × 1104 RGB, Pillow 12.2.0):

Quality JPEG size JPEG SSIM WebP size WebP SSIM
10 29.9 KiB 0.7839 24.2 KiB 0.8420
85 187.0 KiB 0.9584 129.5 KiB 0.9620
95 302.2 KiB 0.9939 258.1 KiB 0.9865

The reference PNG was 1405.3 KiB; PNG output was unchanged across quality values, and omitted quality matched 95. These are encoding measurements on fixed pixels, not model inference benchmarks.

Full-repository pre-commit checks passed with the repository-pinned Ruff 0.11.0. Together with #1705, 118 image tests passed; the wider CPU suite reported 430 passed and the same six failures reproduced on the unmodified upstream base. Diffusers numerical-parity checks were not run. Deployment validation covered the adapted runner and LightX2V APIs; other models, external presigned uploads and performance benchmarks were not tested in that run.

@NorthCedar NorthCedar changed the title feat(minimax_h3_image): support configurable image output encoding Nov 13, 2026

Copy link
Copy Markdown

Additional validation

The output-encoding changes were backported onto an existing MUSA deployment while retaining its model implementation and runtime dependencies.

  • Regression tests: 79 CPU encoding/API tests passed in the deployment environment. Additional checks against the deployed runner passed for request-field admission, startup defaults, request overrides/reset, explicit 0, invalid values, JPEG/WebP file encoding, and PNG invariance.
  • Model inference: 11 text-to-image requests completed successfully on four MUSA GPUs, using a fixed prompt, seed 42, and 2048 × 2048 output. Both native synchronous and OpenAI-compatible generation APIs were exercised.
  • Quality controls: JPEG/WebP output sizes changed with the requested quality; explicit 0 was honored. In same-interface comparisons, omitted quality matched explicit 95. PNG outputs at quality 10 and 95 were byte-identical.
  • Validation and delivery: Invalid quality values returned HTTP 422. JPEG/WebP/PNG response types and filenames matched the encoded formats; actual downloads returned the correct Content-Type and byte-identical content.
  • Service health: All 11 generation requests completed without task failures, and the service remained healthy with no container restarts.

These checks cover the LightX2V APIs and the adapted runner. Other models, external presigned uploads, and performance benchmarks were not tested in this deployment run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants