recipe(layoutlm): add document QA support for impira/layoutlm-document-qa#1093
recipe(layoutlm): add document QA support for impira/layoutlm-document-qa#1093DingmaomaoBJTU wants to merge 2 commits into
Conversation
|
REQUEST_CHANGES I re-checked PR #1093 from the PR head ( Blocking fixes before I can approve:
What I did verify locally:
|
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5bd5ad4 to
b945df3
Compare
|
APPROVE Re-check complete on head The two prior blocking reviewer items are resolved:
Spot checks also passed:
Reviewer blocking issues are resolved. From the independent-review gate, this draft is ready to be converted to ready-for-review by the orchestrator. |
This PR adds
impira/layoutlm-document-qasupport to the LayoutLM export path inwinml-cli, along with flat fp32 and w8a16 document-QA recipes. It ships at OutcomeL1(effort=L1-light,goal_ceiling=L2) and the supplied tester verdicts reachedL2 PASS. The main caveat is that rawwinml perfwith random dummy inputs crashes on this checkpoint becausetoken_type_idscan contain1whiletype_vocab_size=1; the tester therefore used the valid-input fallback path for L1 measurements.Implementation summary: this adds
LayoutLMQAIOConfigregistration for (layoutlm,question-answering), aZeroTokenTypeLayoutLMTextInputGeneratorthat forces all-zerotoken_type_ids, genericbboxordering support insrc\winml\modelkit\onnx\io.py, README indexing, fp32/w8a16 recipes, and unit coverage intests/unit/export/test_onnx_config_overrides.pyandtests/unit/export/test_pytorch_export.py.Recipe path(s)
examples/recipes/impira_layoutlm-document-qa/question-answering_fp32_config.jsonexamples/recipes/impira_layoutlm-document-qa/question-answering_w8a16_config.jsonsrc/winml/modelkit/models/hf/layoutlm.py,src/winml/modelkit/models/hf/__init__.py,src/winml/modelkit/onnx/io.py,tests/unit/export/test_onnx_config_overrides.py,tests/unit/export/test_pytorch_export.pyREADME row
examples/recipes/README.md: yes.Build output dir
origin/mainf102649b63e6bf013a180523d15e6cab75906dd9.temp\impira_layoutlm-document-qa\baseline_offlinetemp\impira_layoutlm-document-qa\fp32temp\impira_layoutlm-document-qa\w8a16C:\Users\qiowu\source\repos\winml-cli\.venv\Scripts\winml.exe build -m impira/layoutlm-document-qa -o temp\impira_layoutlm-document-qa\baseline_offline --ep cpu --device cpu --no-analyze --no-optimize --no-quant --no-compile --rebuildFAILwith exact evidenceError: Unrecognized configuration class <class 'transformers.models.layoutlm.configuration_layoutlm.LayoutLMConfig'> for this kind of AutoModel: AutoModelForNextSentencePrediction.origin/mainfails at the refreshed isolated baseline above, while the branch-specific LayoutLM QA registration/input-generation changes below produce successful fp32 and w8a16 builds.Build log
./.venv/Scripts/winml.exe build -c examples/recipes/impira_layoutlm-document-qa/question-answering_fp32_config.json -m impira/layoutlm-document-qa -o temp\impira_layoutlm-document-qa\fp32 --ep cpu --device cpu --rebuild✅ Build complete in 278.1stemp\impira_layoutlm-document-qa\fp32\model.onnxinput_ids,bbox,attention_mask,token_type_idsas INT32 with shapes[1,512],[1,512,4],[1,512],[1,512]; outputsstart_logits,end_logitsas FLOAT[1,512]FLOAT=206, INT64=63null./.venv/Scripts/winml.exe build -c examples/recipes/impira_layoutlm-document-qa/question-answering_w8a16_config.json -m impira/layoutlm-document-qa -o temp\impira_layoutlm-document-qa\w8a16 --rebuild✅ Quantize 82.3s/Precision: uint8/uint16 (weight/activation)/✅ Build complete in 392.4stemp\impira_layoutlm-document-qa\w8a16\model.onnxFLOAT=411, INT32=196, INT64=63, UINT16=225, UINT8=196mode=static, weight_type=uint8, activation_type=uint16Appended findings
26e1b7b1d83919d53c673c142854dbda16c6eb84appendedlayoutlm-001,layoutlm-002, andlayoutlm-003tocopilot-skills/dev_skill/adding-model-support/model_knowledge/layoutlm.json._meta-060was also appended locally in the skill repo; it is declared here for traceability but intentionally excluded from this model PR diff.Optimum-coverage probe
['feature-extraction','fill-mask','text-classification','token-classification']['feature-extraction','fill-mask','text-classification','token-classification','question-answering']['question-answering']question-answeringcoverage for LayoutLM beyond the vendor baseline.Claimed (Effort, Goal, Outcome)
model_id:impira/layoutlm-document-qamodel_type:layoutlmeffort:L1-lightgoal_ceiling:L2outcome:L1target_eps:cpuarchitectures=["LayoutLMForQuestionAnswering"],model_type="layoutlm",is_encoder_decoder=false,type_vocab_size=1,max_position_embeddings=514,max_2d_position_embeddings=1024; the critical finding was that vendor dummy generation can emittoken_type_ids=1, so this checkpoint required forcing all-zerotoken_type_ids.FAIL(item 3) to branch-state recipe builds/L1/L2PASSevidence (items 4, 8, 10, 11).Goal-ladder verdict table
Catalog gate summary: refreshed-current-main
baseline_build=FAIL,verdict=real-engineering,file_pr=true.origin/mainfailed withError: Unrecognized configuration class <class 'transformers.models.layoutlm.configuration_layoutlm.LayoutLMConfig'> for this kind of AutoModel: AutoModelForNextSentencePrediction.After the branch's LayoutLM QA export/input-generation changes, both recipe builds succeeded. fp32 producedtemp\impira_layoutlm-document-qa\fp32\model.onnxwith INT32 inputs (input_ids,bbox,attention_mask,token_type_ids) and FLOAT outputs (start_logits,end_logits), histogramFLOAT=206, INT64=63, andbuild_quant=null. w8a16 producedtemp\impira_layoutlm-document-qa\w8a16\model.onnxwith the same I/O contract, histogramFLOAT=411, INT32=196, INT64=63, UINT16=225, UINT8=196, andbuild_quant={mode: static, weight_type: uint8, activation_type: uint16}.['AzureExecutionProvider', 'CPUExecutionProvider']. Rawwinml perfon both artifacts crashed with `Error: Benchmark failed: Inference failedstart_logitscosine0.9999999999219783, max_abs0.0022459030151367188, mean_abs2.549774944782257e-05;end_logitscosine0.9999999999193658, max_abs0.0023813247680664062, mean_abs2.7379952371120453e-05. w8a16 vs PT:start_logitscosine0.9522225190737116, max_abs13.425172805786133, mean_abs2.4731171131134033;end_logitscosine0.9597506819201421, max_abs12.746326446533203, mean_abs2.3781232833862305.Methodology-evolution declaration
_meta-060(silent-failure) was appended locally in the Lane A skill repo: explicitwinml buildoverrides such as--device cpu --ep cpucan silently clearconfig.quant, yielding a successful build of the wrong precision for a quant recipe.Perf & eval data
Raw
winml perfon both artifacts crashed on random dummy inputs with the Gather/token-type error quoted in item 8, so the tester used the valid-input fallback path for the L1 measurements below.5005.385395001213 ms5076.764100005676 ms0.19978481597015124 samples/s+467062784 B total (+358121472 B session init)N/A (goal ceiling L2)5581.969174998085 ms5745.492499998363 ms0.1791482483420097 samples/s+311275520 B total (+25878528 B session init)N/A (goal ceiling L2)./.venv/Scripts/winml.exe analyze --model temp\impira_layoutlm-document-qa\fp32\model.onnx --ep all --output temp\impira_layoutlm-document-qa\analyze_fp32.jsontemp\impira_layoutlm-document-qa\analyze_fp32.json395total operators across16unique operator types.QNNExecutionProvider / NPU:16 supported / 0 partial / 0 unsupported / 0 unknown(395total ops covered)OpenVINOExecutionProvider / NPU:15 supported / 1 partial / 0 unsupported / 0 unknown; partial op:OP/ai.onnx/SliceVitisAIExecutionProvider / NPU:0 supported / 0 partial / 0 unsupported / 16 unknown(no rule data)