fix(layoutlm): resolve invoices question answering support#1181
Draft
fuliucansheng wants to merge 1 commit into
Draft
fix(layoutlm): resolve invoices question answering support#1181fuliucansheng wants to merge 1 commit into
fuliucansheng wants to merge 1 commit into
Conversation
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
This PR adds support for
DmitrySpartak/layoutlm-invoicesby fixing task resolution for*ForQuestionAnsweringarchitecture heads when Optimum cannot infer a task, then adding validated CPU recipes for fp32 and fp16 LayoutLM invoice question answering. The shipped outcome is Outcome-L1: a class-derived resolver fix, regression coverage, and exact-evidence CPU recipes. L0 build, L1 perf, and L2 PyTorch-vs-ONNX comparison pass for both precisions; L3 task-metric eval is CLI-blocked today because the generic SQuAD question-answering evaluator does not supply LayoutLMbboxandtoken_type_idsinputs.Model metadata
What the model does
DmitrySpartak/layoutlm-invoicesis a LayoutLM document question-answering checkpoint for extracting answer spans from invoice text with OCR/layout coordinates. The checkpoint is cataloged locally asdocument-question-answering, while the export/runtime surface is canonical spanquestion-answeringwithstart_logitsandend_logits.Primary user stories
Supported tasks
document-question-answeringDmitrySpartak/layoutlm-invoicesquestion-answeringLayoutLMForQuestionAnswering;LayoutLMQAIOConfig; currentwinml inspectresolves taskquestion-answeringModel architecture
Source/confidence: checkpoint config and HTP export hierarchy for
LayoutLMForQuestionAnswering(verified).Validation and support evidence
Baseline
26a4a82b638f2169b5a2f75758abb31a60b1774e(origin/mainwhen this branch was cut).winml, version 0.2.0.origin/mainhasLayoutLMQAIOConfigregistered forlayoutlm/question-answering, but Optimum'sTasksManager.infer_task_from_model(LayoutLMForQuestionAnswering)does not infer the task. Before this fix, auto-resolution fell through to thelayoutlmfamily default (next-sentence-prediction), producing the wrong task/output contract (logits) for this checkpoint.winml inspect -m DmitrySpartak/layoutlm-invoices --format jsonresolvesmodel_type=layoutlm,architectures=[LayoutLMForQuestionAnswering], taskquestion-answering, exporterLayoutLMQAIOConfig, inputsinput_ids,bbox,attention_mask,token_type_ids, and outputsstart_logits,end_logits.Goal
architectures[]suffix and generalizes to question-answering heads without naming this model.Outcome
src/winml/modelkit/loader/resolution.pytests/unit/loader/test_resolve_task.pyexamples/recipes/DmitrySpartak_layoutlm-invoices/cpu/cpu/question-answering_fp32_config.jsonexamples/recipes/DmitrySpartak_layoutlm-invoices/cpu/cpu/question-answering_fp16_config.jsonPer-EP/device/precision results
winml build ... --no-analyze --no-optimize --no-quant --no-compile --rebuild; build complete in 31.1s; final artifactmodel.onnx; IR 8 / opset 17; inputs[1,512],bbox [1,512,4]; outputsstart_logits,end_logits; external data beside model (model.onnx.data508,803,072 bytes).winml build ... --precision fp16 --no-analyze --no-optimize --no-compile --rebuild; build complete in 30.2s; FP16 stage emitted 242.8 MB artifact;Model Precision: fp16; 208 FLOAT16 initializers and 12 INT64 initializers; external data beside model (model.onnx.data254,401,536 bytes).winml perf ... --input-data temp/layoutlm_invoices_valid_inputs.npz --iterations 20 --warmup 3; Avg 121.32 ms, P50 122.92 ms, throughput 8.24 samples/sec, RAM total +454.9 MB.winml perf ... --input-data temp/layoutlm_invoices_valid_inputs.npz --iterations 20 --warmup 3; Avg 150.94 ms, P50 152.95 ms, throughput 6.63 samples/sec, RAM total +473.6 MB; perf printedModel Precision: fp16.LayoutLMForQuestionAnsweringPyTorch reference vs ONNX Runtime on identical valid LayoutLM inputs:start_logitscosine 1.00000000 / max_abs 0.00002289;end_logitscosine 1.00000000 / max_abs 0.00001907.start_logitscosine 0.99999998 / max_abs 0.00927544;end_logitscosine 0.99999999 / max_abs 0.00676346.winml eval ... --task question-answering --samples 2uses defaultrajpurkar/squadand fails withMissing required inputs: {'token_type_ids', 'bbox'}. Generic SQuAD QA schema has no LayoutLM bbox/OCR layout fields.Missing required inputs: {'token_type_ids', 'bbox'}.Note:
winml perfon a raw ONNX path with random generated inputs can create invalidtoken_type_idsfor this checkpoint (type_vocab_size=1). Perf evidence therefore uses a real.npzinput file with valid monotonic bbox coordinates and all-zerotoken_type_ids.Delta
config.architectures. The fallback currently mapsForQuestionAnsweringtoquestion-answeringand only runs after resolving the architecture class but before falling back to broad family defaults. It does not branch on model id.layoutlm+LayoutLMForQuestionAnswering, proving task and optimum task resolve toquestion-answeringwithTaskSource.TASKS_MANAGER.input_ids,bbox,attention_mask,token_type_ids), usesbboxrange[0,1000], keepstoken_type_idsin the valid half-open[0,1]range for this checkpoint, and emitsstart_logits/end_logits.Analyze summary - component level and op level
Static rule analysis completed with
ANALYZE-PARTIAL-SUCCESS:winml analyze --ep allexited nonzero because VitisAI has no rule data, but the JSON is complete and parseable for QNN, OpenVINO, and VitisAI rule coverage.Component-level summary
Op-level summary
Reproduce commands
Quality gates run locally:
Results: ruff passed, mypy passed, focused loader tests passed (21 passed), models/loader/datasets/export partition passed (1375 passed, 6 skipped, 1 xfailed), and commands/config/build/compiler/session/eval partition passed (2383 passed, 6 skipped, 2 deselected).