sgl-project/sglang · error · NotImplementedError

I2I mode is not supported yet via external SGLang encoder UR

Error message

I2I mode is not supported yet via external SGLang encoder URL.

What it means

The GLM-Image pipeline was configured to use an external SGLang encoder server (server_args.srt_encoder_url set), but the request also included an input image (Image-to-Image mode). The external encoder URL path only supports text-to-image generation, so passing an image raises NotImplementedError.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py:454

        ).to(device)

        image_grid_thw = inputs.get("image_grid_thw")
        max_new_tokens, large_image_offset, token_h, token_w = (
            self._compute_generation_params(
                image_grid_thw=image_grid_thw, is_text_to_image=is_text_to_image
            )
        )

        prior_token_image_ids = None

        # For GLM-Image, greedy decoding is not allowed; it may cause repetitive outputs.
        # max_new_tokens must be exactly grid_h * grid_w + 1 (the +1 is for EOS).
        if server_args.srt_encoder_url is not None:
            if image is not None:
                logger.error(
                    "Image-to-Image tasks is not supported yet when using an external SGLang encoder server."
                )
                raise NotImplementedError(
                    "I2I mode is not supported yet via external SGLang encoder URL."
                )

            payload = {
                "input_ids": inputs["input_ids"][0].tolist(),
                "image_data": [{"image_grid_thw": image_grid_thw.tolist()}],
                "sampling_params": self._external_ar_sampling_params(
                    max_new_tokens, seed
                ),
            }
            data = self._request_external_ar(payload, server_args)
            generated_ids = data.get("output_ids")
            usage = _extract_srt_usage(data.get("meta_info"))
        else:
            if image is not None:
                source_grids = image_grid_thw[:-1]
                prior_token_image_embed = pooled_image_features_to_tensor(
                    self.vision_language_encoder.get_image_features(

View on GitHub (pinned to 0132848349)

Solutions

  1. Remove the input image to run text-to-image through the external encoder
  2. Or unset server_args.srt_encoder_url so the in-process encoder handles I2I
  3. Or wait for/implement I2I support in the external encoder request payload

Example fix

# before
server_args.srt_encoder_url = "http://encoder:8000"
result = pipe(prompt="a cat", image=input_pil_image)

# after
server_args.srt_encoder_url = None  # use in-process encoder for I2I
result = pipe(prompt="a cat", image=input_pil_image)
Defensive patterns

Strategy: type-guard

Validate before calling

if server_args.srt_encoder_url is not None and image is not None:
    raise NotImplementedError(
        "I2I requires the in-process encoder; unset srt_encoder_url"
    )

Type guard

def supports_i2i(server_args) -> bool:
    return server_args.srt_encoder_url is None

Try / catch

try:
    result = pipe(prompt=p, image=img)
except NotImplementedError as e:
    if "I2I mode" in str(e):
        server_args.srt_encoder_url = None
        result = pipe(prompt=p, image=img)  # in-process encoder
    else:
        raise

Prevention

When it happens

Trigger: Setting server_args.srt_encoder_url to an external encoder endpoint and then calling forward()/generate_prior_tokens with image != None (an input image for img2img).

Common situations: Deployments that split the encoder from the AR/decoder trying to reuse the same pipeline for img2img; migrating a working T2I external-encoder setup to I2I without realizing the limitation.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/aa067ecef161fe0b. Report an issue: GitHub.