open-mmlab/mmdetection · warning

Inputting a text that is too long will result in poor predic

Error message

Inputting a text that is too long will result in poor prediction performance. Please reduce the text length.

What it means

GLIP warns when the tokenized caption exceeds the language model's max_tokens (e.g. BERT's 256). The text is not truncated by this check — downstream embedding/prediction quality degrades because the language encoder cannot represent the full prompt.

Source

Thrown at mmdet/models/detectors/glip.py:361

        chunked_size = self.test_cfg.get('chunked_size', -1)
        if not self.training and chunked_size > 0:
            assert isinstance(original_caption,
                              (list, tuple)) or custom_entities is True
            all_output = self.get_tokens_positive_and_prompts_chunked(
                original_caption, enhanced_text_prompt)
            positive_map_label_to_token, \
                caption_string, \
                positive_map, \
                entities = all_output
        else:
            tokenized, caption_string, tokens_positive, entities = \
                self.get_tokens_and_prompts(
                    original_caption, custom_entities, enhanced_text_prompt)
            positive_map_label_to_token, positive_map = self.get_positive_map(
                tokenized, tokens_positive)
            if tokenized.input_ids.shape[1] > self.language_model.max_tokens:
                warnings.warn('Inputting a text that is too long will result '
                              'in poor prediction performance. '
                              'Please reduce the text length.')
        return positive_map_label_to_token, caption_string, \
            positive_map, entities

    def get_tokens_positive_and_prompts_chunked(
            self,
            original_caption: Union[list, tuple],
            enhanced_text_prompts: Optional[ConfigType] = None):
        chunked_size = self.test_cfg.get('chunked_size', -1)
        original_caption = [clean_label_name(i) for i in original_caption]

        original_caption_chunked = chunks(original_caption, chunked_size)
        ids_chunked = chunks(
            list(range(1,
                       len(original_caption) + 1)), chunked_size)

        positive_map_label_to_token_chunked = []

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Shorten the caption / reduce number of categories per prompt
  2. Split text into chunks and use get_tokens_positive_and_prompts_chunked with a smaller --chunked-size

Example fix

# before
results = detector(inputs, texts=['a very long caption with hundreds of words ...'])
# after
results = detector(inputs, texts=['person . dog . car .'])
Defensive patterns

Strategy: validation

Validate before calling

max_tokens = detector.language_model.max_tokens
n = detector.language_model.tokenizer([caption], return_tensors='pt').input_ids.shape[1]
assert n <= max_tokens, f'caption too long: {n} > {max_tokens}'

Prevention

When it happens

Trigger: Calling GLIP predict with a long original_caption whose tokenized input_ids length > language_model.max_tokens.

Common situations: Long descriptive prompts, concatenating many category names, or phrase-level prompts with many entities in zero-shot grounding.

Related errors


AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27). Data as JSON: /api/errors/ee1c7a88ed1e7384. Report an issue: GitHub.