-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat: Layout + VLM model with layout prompt #2244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cau-git
wants to merge
14
commits into
main
Choose a base branch
from
cau/layout_vlm_pipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c1dcb05
adding granite-docling preview
PeterStaar-IBM 0e2f370
updated the model specs
PeterStaar-IBM 72007b9
Add Layout+VLM pipeline with prompt injection, ApiVlmModel updates
cau-git ed68b47
Update layout injection, move to experimental
cau-git 57c40b1
Merge branch 'main' of github.com:DS4SD/docling into cau/layout_vlm_p…
cau-git 0a39e2f
Adjust defaults
cau-git 98fde58
Map Layout+VLM pipeline to GraniteDoclign
cau-git 0be5ebc
Update from main
cau-git f06664a
Remove base_prompt from layout injection prompt
cau-git 77107fe
Sync branch with main
cau-git f248bbd
Reinstate custom prompt
cau-git 6ea00bb
add demo_layout file that produces with vs without layout injection
ElHachem02 fa0b603
merge with main branch
ElHachem02 8cf23e7
feat: merge wit main, remove inverence time fron api_vlm_model
ElHachem02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| """Experimental modules for Docling. | ||
|
|
||
| This package contains experimental features that are under development | ||
| and may change or be removed in future versions. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Experimental datamodel modules.""" |
31 changes: 31 additions & 0 deletions
31
docling/experimental/datamodel/threaded_layout_vlm_pipeline_options.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """Options for the threaded layout+VLM pipeline.""" | ||
|
|
||
| from typing import Union | ||
|
|
||
| from docling.datamodel.layout_model_specs import DOCLING_LAYOUT_HERON | ||
| from docling.datamodel.pipeline_options import LayoutOptions, PaginatedPipelineOptions | ||
| from docling.datamodel.pipeline_options_vlm_model import ( | ||
| ApiVlmOptions, | ||
| InlineVlmOptions, | ||
| ) | ||
| from docling.datamodel.vlm_model_specs import GRANITEDOCLING_TRANSFORMERS | ||
|
|
||
|
|
||
| class ThreadedLayoutVlmPipelineOptions(PaginatedPipelineOptions): | ||
| """Pipeline options for the threaded layout+VLM pipeline.""" | ||
|
|
||
| images_scale: float = 2.0 | ||
|
|
||
| # VLM configuration (will be enhanced with layout awareness by the pipeline) | ||
| vlm_options: Union[InlineVlmOptions, ApiVlmOptions] = GRANITEDOCLING_TRANSFORMERS | ||
|
|
||
| # Layout model configuration | ||
| layout_options: LayoutOptions = LayoutOptions( | ||
| model_spec=DOCLING_LAYOUT_HERON, skip_cell_assignment=True | ||
| ) | ||
|
|
||
| # Threading and batching controls | ||
| layout_batch_size: int = 4 | ||
| vlm_batch_size: int = 4 | ||
| batch_timeout_seconds: float = 2.0 | ||
| queue_max_size: int = 50 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,169 @@ | ||||||
| #!/usr/bin/env python3 | ||||||
| """Demo script for the new ThreadedLayoutVlmPipeline. | ||||||
| This script demonstrates the usage of the new pipeline that combines | ||||||
| layout model preprocessing with VLM processing in a threaded manner. | ||||||
| """ | ||||||
|
|
||||||
| import argparse | ||||||
| import logging | ||||||
| from io import BytesIO | ||||||
| from pathlib import Path | ||||||
|
|
||||||
| from docling.datamodel.base_models import ConversionStatus, DocumentStream, InputFormat | ||||||
| from docling.datamodel.pipeline_options import VlmPipelineOptions | ||||||
| from docling.datamodel.vlm_model_specs import ( | ||||||
| GRANITEDOCLING_TRANSFORMERS, | ||||||
| GRANITEDOCLING_VLLM, | ||||||
| ) | ||||||
| from docling.document_converter import DocumentConverter, PdfFormatOption | ||||||
| from docling.experimental.datamodel.threaded_layout_vlm_pipeline_options import ( | ||||||
| ThreadedLayoutVlmPipelineOptions, | ||||||
| ) | ||||||
| from docling.experimental.pipeline.threaded_layout_vlm_pipeline import ( | ||||||
| ThreadedLayoutVlmPipeline, | ||||||
| ) | ||||||
| from docling.pipeline.vlm_pipeline import VlmPipeline | ||||||
|
|
||||||
| _log = logging.getLogger(__name__) | ||||||
|
|
||||||
|
|
||||||
| def _parse_args(): | ||||||
| parser = argparse.ArgumentParser( | ||||||
| description="Demo script for the new ThreadedLayoutVlmPipeline" | ||||||
| ) | ||||||
| parser.add_argument( | ||||||
| "--input", type=str, required=True, help="Input directory containing PDF files" | ||||||
| ) | ||||||
| parser.add_argument( | ||||||
| "--output", | ||||||
| type=str, | ||||||
| default="../results/", | ||||||
| help="Output directory for converted files", | ||||||
| ) | ||||||
| return parser.parse_args() | ||||||
|
|
||||||
|
|
||||||
| def _get_docs(input_doc_paths): | ||||||
| """Yield DocumentStream objects from list of input document paths""" | ||||||
| for path in input_doc_paths: | ||||||
| buf = BytesIO(path.read_bytes()) | ||||||
| stream = DocumentStream(name=path.name, stream=buf) | ||||||
| yield stream | ||||||
|
|
||||||
|
|
||||||
| def demo_threaded_layout_vlm_pipeline( | ||||||
| input_doc_paths: list[Path], out_dir_layout_aware: Path, out_dir_classic_vlm: Path | ||||||
| ): | ||||||
| """Demonstrate the threaded layout+VLM pipeline.""" | ||||||
|
|
||||||
| # Configure pipeline options | ||||||
| print("Configuring pipeline options...") | ||||||
| pipeline_options_layout_aware = ThreadedLayoutVlmPipelineOptions( | ||||||
| # VLM configuration - defaults to GRANITEDOCLING_TRANSFORMERS | ||||||
| vlm_options=GRANITEDOCLING_TRANSFORMERS, | ||||||
| # Layout configuration - defaults to DOCLING_LAYOUT_HERON | ||||||
| # Batch sizes for parallel processing | ||||||
| layout_batch_size=2, | ||||||
| vlm_batch_size=1, | ||||||
| # Queue configuration | ||||||
| queue_max_size=10, | ||||||
| batch_timeout_seconds=1.0, | ||||||
| # Layout coordinate injection | ||||||
| include_layout_coordinates=True, | ||||||
| coordinate_precision=1, | ||||||
| # Image processing | ||||||
| images_scale=2.0, | ||||||
| generate_page_images=True, | ||||||
| ) | ||||||
|
|
||||||
| pipeline_options_classic_vlm = VlmPipelineOptions(vlm_otpions=GRANITEDOCLING_VLLM) | ||||||
|
||||||
| pipeline_options_classic_vlm = VlmPipelineOptions(vlm_otpions=GRANITEDOCLING_VLLM) | |
| pipeline_options_classic_vlm = VlmPipelineOptions(vlm_options=GRANITEDOCLING_VLLM) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Experimental pipeline modules.""" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate import:
SegmentedPageis imported both at line 4 and inside theTYPE_CHECKINGblock at line 13. The import at line 4 should be removed since it's only used for type annotations and is already imported in the TYPE_CHECKING block.