feat(layoutlm): add document question answering support#1133
Draft
ssss141414 wants to merge 1 commit into
Draft
Conversation
Contributor
Author
Independent reviewer verdict: REQUEST_CHANGESThe Lane B implementation and independently reproduced model evidence pass, but the required learner-owned Lane A knowledge shipment has not landed. This is a fail-closed workflow blocker. Blocking item
Independently verified gates
No producer code or recipe change is requested. Models 3–8 were not inspected or started. |
Contributor
Author
|
Resolved the REQUEST_CHANGES blocker exactly as requested:
Requesting a fresh independent review. |
Contributor
Author
Independent reviewer verdict: APPROVEThe prior reviewer blocker is resolved. The Lane B head remains unchanged, all applicable gates pass, and this PR must remain DRAFT. REQUEST_CHANGES resolution
Fresh state and discussion inventory
Diff and engineering review
Independent model evidence rechecked
No code, body, recipe, or draft-state mutation was made during this review. Models 3–8 were not inspected or started. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds class-wide LayoutLM v1
document-question-answeringexport support and verified CPU fp32/fp16 recipes forDmitrySpartak/layoutlm-invoices. This matters because currentmainmisresolves this checkpoint to next-sentence prediction and cannot build it. The shipped contribution is Effort L1 / Outcome L1 and independently reaches Goal L2 PASS for both required tuples; end-to-end task evaluation remains CLI-blocked and is tracked by #1132.Model metadata
What the model does
This pinned LayoutLM v1 checkpoint is an extractive document-question-answering model for invoices and other documents. Its model forward consumes token IDs, normalized token bounding boxes, an attention mask, and token-type IDs, then emits per-token start and end logits. It does not consume a PDF or image directly: OCR, word/box construction, token alignment, and answer decoding are external pipeline stages. The resolved stock Transformers class ignores the checkpoint's extra
token_classifier_headweights, so the model card's advertised non-consecutive-token behavior is not verified on this concrete runtime path. Confidence: verified.Durable sources: pinned model card, pinned checkpoint config, and
LayoutLMForQuestionAnsweringin Transformers 4.57.6.Primary user stories
Sources: the pinned model card, pinned checkpoint config, and Transformers 4.57.6 implementation.
Supported tasks
document-question-answering— supported by the checkpoint and Transformers model head. Confidence: verified. WinML export/config support is added by this PR; WinML end-to-end evaluation is not yet supported and is tracked by #1132. Plainquestion-answeringwas deliberately not substituted because it would erase the document-layout contract.Model architecture
LayoutLMForQuestionAnsweringsource in Transformers 4.57.6 (verified).Validation and support evidence
Baseline
e7509b1e908c74beff0a5655b8f8d7de69c5afae, WinML0.2.0.Task 'document-question-answering' not supported by TasksManager; no requested-task config artifact produced.next-sentence-prediction/AutoModelForNextSentencePrediction; this diagnostic output is not a valid starting recipe.Unrecognized LayoutLMConfig for AutoModelForNextSentencePrediction; no model.onnx produced.ONNX file not found because baseline build failed.ONNX file not found; independent schema probe also rejects exact task document-question-answering as unsupported. Plain question-answering schema exists but was not substituted.layoutlm: vendor tasks and post-WinML tasks are bothfeature-extraction,fill-mask,text-classification, andtoken-classification; WinML adds no task. Verdict fordocument-question-answering: UNREGISTERED.Goal
Outcome
7e939ae638193e0f83f717d7bee4f9b5b4311bf1, tracked by ModelKitArtifacts PR #159.document-question-answering_fp32_config.jsondocument-question-answering_fp16_config.json7e939ae638193e0f83f717d7bee4f9b5b4311bf1on ModelKitArtifacts PR #159:layoutlm-002architecture-driven exact-task resolution;layoutlm-003input bounds and generic high-exclusive range propagation;layoutlm-004fp32/fp16 build, perf, parity, and analysis;layoutlm-005exact eval blocker and issue Add end-to-end document-question-answering inference and eval contract #1132.winml perfvalue-range friction documented by_meta-017. No new methodology finding or verdict shape was required; no skill edit is part of this model PR.Per-EP/device/precision results — including perf and eval data
Goal ladder
LayoutLMForQuestionAnsweringcomparison on identical named 512-token inputs with 33 nonzero boxed document tokens; start/end argmaxes preserved.Build and structural coverage
onnx.checkerPASS; IR=8; opset=17; nodes=442; inputs=input_ids,bbox,attention_mask,token_type_ids; outputs=start_logits,end_logits; initializers: FLOAT 208, INT64 12; final artifact 508,972,442 bytes with external data.onnx.checkerPASS; IR=8; opset=17; nodes=444; inputs=input_ids,bbox,attention_mask,token_type_ids; outputs=start_logits,end_logits; initializers: FLOAT16 208, INT64 12; final artifact 254,570,982 bytes with external data.Perf — named semantic document inputs
Each row used normalized OCR boxes, all-zero
token_type_ids, 10 warmups, and 100 timed iterations onCPUExecutionProvider.Perf — default generated inputs after the generic range repair
These rows used no
--input-data; each completed 10 warmups and 100 timed iterations.Default
winml perfnow honors config-derived ranges for both repaired artifacts; generic integer, float, singleton, and unspecified-range behavior passes independently.L2 numeric parity
The identical semantic input contains 33 nonzero document-box tokens,
bboxrange 0–755, monotonic boxes, and only token type 0. Reference/ONNX argmaxes are preserved at 16 forstart_logitsand 22 forend_logits.Eval
Schema command verdict: CLI-BLOCKED, exit 2.
Error: Evaluation failed: Task 'document-question-answering' is not supported. Supported tasks: compare-tensor, depth-estimation, feature-extraction, fill-mask, image-classification, image-feature-extraction, image-segmentation, image-to-text, keypoint-detection, mask-generation, next-sentence-prediction, object-detection, question-answering, sentence-similarity, sequence-classification, text-classification, token-classification, zero-shot-classification, zero-shot-image-classification.Error: Evaluation failed: Task 'document-question-answering' is not supported. Supported tasks: compare-tensor, depth-estimation, feature-extraction, fill-mask, image-classification, image-feature-extraction, image-segmentation, image-to-text, keypoint-detection, mask-generation, next-sentence-prediction, object-detection, question-answering, sentence-similarity, sequence-classification, text-classification, token-classification, zero-shot-classification, zero-shot-image-classification.No dataset or metric was produced. This is an eval task-family blocker, not an export, precision, or model-quality failure. The checkpoint forward graph is only the neural span scorer; OCR, PDF/image decoding, word/box normalization and alignment, and answer decoding remain external. The exact generalized gap is #1132 — Add end-to-end document-question-answering inference and eval contract (open).
Delta
Recipes
optim={},quant=null,compile=null.optim={},quant.mode=fp16,compile=null.Generalized code and tests
src/winml/modelkit/loader/resolution.pymodel_type + architectures[0]registry lookup before Optimum inference with explicitTaskSource.ARCHITECTURE_MAPPINGprovenance. There is no model-ID or LayoutLM branch in shared resolution code.src/winml/modelkit/models/hf/layoutlm.pyLayoutLMForQuestionAnswering → document-question-answering,AutoModelForDocumentQuestionAnswering, bbox-preserving four-input export,start_logits/end_logits, type-vocabulary-derived token types, and conditional RoBERTa position-offset handling.src/winml/modelkit/models/hf/__init__.pysrc/winml/modelkit/commands/perf.pygenerate_random_inputsnow readsio_config.input_value_rangesper input and forwards valid metadata ranges. Canonical ranges stay high-exclusive; integer maxima are reduced by one only at the legacy generator's inclusive-max adapter boundary. Float ranges, shapes, tensor classification, and unspecified ranges retain prior behavior.tests/unit/loader/test_layoutlm_resolution.pytests/unit/export/test_layoutlm_onnx_config.pytests/unit/commands/test_perf_cli.pyThe fix remains reducible and consistent with the frozen charter: it is class-of-models L1 code, metadata-driven, recipe-free accepted, and contains no checkpoint-only branching. Other LayoutLM heads remain on existing Optimum task paths.
Analyze summary — component level and op level
ANALYZE-PARTIAL-SUCCESS (exit 1): OpenVINO plugin registration failed because
onnxruntime_providers_shared.dllwas missing (Error 126); emitted JSON remained complete for all 11 EP/device rows. This is static rule analysis, not runtime execution on those accelerator EPs.Component-level summary
Div,Erf,Add,Mul; unsupported=noneDiv,Erf,Add,Mul; unsupported=noneBuilt-artifact ONNX mapping was absent from the frozen planner report; the tester derived it from emitted full hierarchy tags.
Op-level summary
Div,Erf,Add,Mul, unsupported=none; all types unknown for CUDA/GPU, MIGraphX/GPU, Dml/GPU, CPU/CPU, VitisAI/NPU.Div,Erf,Add,Mul, unsupported=none; all types unknown for CUDA/GPU, MIGraphX/GPU, Dml/GPU, CPU/CPU, VitisAI/NPU.The host exposed
DmlExecutionProviderandCPUExecutionProvider; only CPU runtime measurements are claimed. Static rows for NvTensorRTRTX, CUDA, MIGraphX, QNN, OpenVINO, DML, CPU, and VitisAI do not imply runtime validation.Reproduce commands
The sequence below is portable PowerShell. It embeds the tester-supplied L2 harness verbatim and uses the versioned public
rules-v0.2.0.ziparchive with SHA-256 verification.