deepseek-ai / deepseek-ai/DeepSeek-OCR-2

Text repetition/looping issue with multi-page PDFs and dense documents

Open
#28 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
3.4k
Forks
306
PR merge metrics
No merged PRs in 30d

Description

## Problem Description

When processing multi-page PDFs or documents with dense text (e.g., financial statements, invoices), the model enters a **repetition loop** where it outputs the same text block repeatedly instead of processing the actual document content.

### Example of the issue:
```
[Header text block]
[Same header text block repeated]
[Same header text block repeated again]
... (repeats 10-20+ times)
```

The model gets stuck repeating an early portion of the document (often header/address information) and never processes the main content.

## Environment

- **vLLM version**: 0.8.5
- **PyTorch**: 2.6.0
- **CUDA**: 11.8
- **GPU**: NVIDIA RTX 4090 (24GB)
- **Model**: DeepSeek-OCR-2 (from HuggingFace)

## Reproduction Steps

1. Load a multi-page PDF with dense tabular data (financial statement, bank statement, invoice)
2. Use the grounding prompt: `\n<|grounding|>Convert the document to markdown.`
3. Process the document
4. Observe repeated text blocks in output

## Attempted Workarounds

### 1. NoRepeatNGramLogitsProcessor adjustments

| Setting | Default | Tried | Result |
|---------|---------|-------|--------|
| `ngram_size` | 20 | 40, 50 | Slight improvement |
| `window_size` | 90 | 200, 500 | Slight improvement |

### 2. SamplingParams adjustments

- Added `repetition_penalty=1.1` - minimal effect
- `temperature=0.0` (deterministic) - no change

### 3. Prompt variations

- Non-grounding prompts (`Free OCR`) work better but lose layout information
- The `<|grounding|>` tag seems to trigger more repetition on dense documents

## Related Issues

- Issue #12 mentions "text hallucination with repeated incorrect tokens" and "visual encoding bottleneck"
- Issue #16 reports "the model loops repeatedly through table headers when processing text-based PDFs"

## Questions

1. Are there recommended parameters for processing dense multi-page documents?
2. Is this a known limitation of the visual encoding architecture?
3. Are there any undocumented inference parameters that could help?
4. Would processing pages at higher resolution help, or does it exacerbate the issue?

## Suggested Investigation

The repetition seems related to:
- Dense text regions compressing into too few visual tokens
- The grounding mode's layout detection conflicting with text extraction
- Long documents exceeding some internal context threshold

Any guidance from the team would be appreciated.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.