sgl-project/sglang · warning

In ps_version 'v1', the height and width have not been swapp

Error message

In ps_version 'v1', the height and width have not been swapped back, which results in a transposed image.

What it means

This is a warning emitted by InternVL's pixel_shuffle vision projection when ps_version='v1'. In v1, the height/width swap performed during the pixel-unshuffle reshape is intentionally NOT undone (no permute back), so the resulting feature map is transposed relative to the input image. The model was trained this way, so v1 checkpoints reproduce correct behavior only with the transpose left in place; the log line exists so users know the geometry differs from v2.

Source

Thrown at python/sglang/srt/models/internvl.py:607

        }

        self.model = self.language_model.model

    def pixel_shuffle(self, x, scale_factor=0.5):
        n, w, h, c = x.size()
        # N, W, H, C --> N, W, H * scale, C // scale
        x = x.view(n, w, int(h * scale_factor), int(c / scale_factor))
        # N, W, H * scale, C // scale --> N, H * scale, W, C // scale
        x = x.permute(0, 2, 1, 3).contiguous()
        # N, H * scale, W, C // scale --> N, H * scale, W * scale, C // (scale ** 2)
        x = x.view(
            n,
            int(h * scale_factor),
            int(w * scale_factor),
            int(c / (scale_factor * scale_factor)),
        )
        if self.ps_version == "v1":
            logger.warn(
                "In ps_version 'v1', the height and width have not been swapped back, "
                "which results in a transposed image."
            )
        else:
            x = x.permute(0, 2, 1, 3).contiguous()
        return x

    def extract_feature(self, pixel_values):
        if self.select_layer == -1:
            vit_embeds = self.vision_model(
                pixel_values=pixel_values, output_hidden_states=False, return_dict=True
            ).last_hidden_state
        else:
            vit_embeds = self.vision_model(
                pixel_values=pixel_values, output_hidden_states=True, return_dict=True
            ).hidden_states[self.select_layer]
        vit_embeds = vit_embeds[:, 1:, :]

View on GitHub (pinned to 0132848349)

Solutions

  1. If your model config genuinely specifies ps_version='v1', this is expected — no action needed; suppress or ignore the log line
  2. Verify you passed the correct model/config (a v2 checkpoint misconfigured as v1 produces wrong spatial layout): check the ps_version field in config.json of the vision tower
  3. If you actually want non-transposed features, set ps_version='v2' (only valid for checkpoints trained with v2) so the permute-back branch runs
  4. Downgrade log noise via logging config if the warning floods logs in production

Example fix

// config.json (vision tower)
// before
"ps_version": "v1"
// after (only for v2-trained checkpoints)
"ps_version": "v2"
Defensive patterns

Strategy: validation

Validate before calling

ps = model.config.vision_config.ps_version
if ps == "v1":
    logging.getLogger(__name__).info("InternVL v1 pixel shuffle: transposed features expected")

Prevention

When it happens

Trigger: Loading an InternVL model whose vision config sets ps_version='v1' (older InternVL checkpoints) and running a forward pass that reaches extract_feature -> pixel_shuffle. Any multimodal request (image input) to an InternVL model triggers it once per vision forward.

Common situations: Serving older InternVL / InternVL2 variants with ps_version='v1' in the vision config; users comparing v1 vs v2 behavior or debugging 'rotated/transposed image' visual embeddings; upgrading SGLang versions where the warning was added for clarity.

Related errors


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