onnxruntime
337ec523 - Validate generation subgraph shapes (#32078)

Commit
30 days ago
Validate generation subgraph shapes (#32078) This pull request strengthens input validation and error handling for subgraph classes in the ONNX Runtime transformers codebase. It introduces additional checks for required input/output shapes and dimensions, ensuring that missing or malformed shapes are detected early with clear error messages. The changes also add corresponding unit tests to verify the new validation logic. **Validation and Error Handling Improvements:** * Added checks to ensure subgraph output names are not empty in `subgraph_base.cc`, and that required tensor shapes (such as logits and past state shapes) are not null before proceeding with parameter extraction or validation. This applies to GPT, T5, and Whisper subgraph classes (`subgraph_base.cc`, `subgraph_gpt.cc`, `subgraph_t5_decoder.cc`, `subgraph_t5_encoder.cc`, `subgraph_whisper_decoder.cc`, `subgraph_whisper_encoder.cc`). [[1]](diffhunk://#diff-36f9a180d24088d6336e1f42bbec6d0fe37210f4953c167f9a34ae1e9882a8d7R65-R66) [[2]](diffhunk://#diff-36f9a180d24088d6336e1f42bbec6d0fe37210f4953c167f9a34ae1e9882a8d7R145-R147) [[3]](diffhunk://#diff-1c3c36abe873809b84c5b9b0c4620cdd9acbac51c55cee11b2925440fd62f8b3R169-R170) [[4]](diffhunk://#diff-97b23192a59f74e96db55e7eef910270f2987285fa4b734285e69e9467569c28R54-R57) [[5]](diffhunk://#diff-97b23192a59f74e96db55e7eef910270f2987285fa4b734285e69e9467569c28R100) [[6]](diffhunk://#diff-97b23192a59f74e96db55e7eef910270f2987285fa4b734285e69e9467569c28R109-R110) [[7]](diffhunk://#diff-bb4a85473116e8ebd8b731818e28cc2bf969f5ca52f7090633c181b104e2f769R105) [[8]](diffhunk://#diff-6161e160fc3b48fb67829162a627991d3d2b9acb662d685123ab56f84d334b00R52) [[9]](diffhunk://#diff-6161e160fc3b48fb67829162a627991d3d2b9acb662d685123ab56f84d334b00R98) [[10]](diffhunk://#diff-6161e160fc3b48fb67829162a627991d3d2b9acb662d685123ab56f84d334b00R108-R109) [[11]](diffhunk://#diff-1c7fc3b879a5909572c7a602415544b6b8a37c15efdec3b1b417bdb3dc47a491L52-R52) [[12]](diffhunk://#diff-1c7fc3b879a5909572c7a602415544b6b8a37c15efdec3b1b417bdb3dc47a491R65) * Improved validation of input dimensions, such as ensuring decoder subgraph input tensors have the expected number of dimensions for T5 and Whisper models (`subgraph_t5_decoder.cc`, `subgraph_whisper_decoder.cc`). [[1]](diffhunk://#diff-97b23192a59f74e96db55e7eef910270f2987285fa4b734285e69e9467569c28R109-R110) [[2]](diffhunk://#diff-6161e160fc3b48fb67829162a627991d3d2b9acb662d685123ab56f84d334b00R108-R109) **Unit Testing:** * Added new unit tests in `beam_search_test.cc` to verify that missing logits or past state shapes are correctly rejected, and that error messages are descriptive. This includes helper code to load test models and manipulate subgraph outputs for testing. [[1]](diffhunk://#diff-782b3e352d8957cd1226d1b87f2127c58efd5ba7a6472528afbdd6baa8232198R6-R9) [[2]](diffhunk://#diff-782b3e352d8957cd1226d1b87f2127c58efd5ba7a6472528afbdd6baa8232198R18) [[3]](diffhunk://#diff-782b3e352d8957cd1226d1b87f2127c58efd5ba7a6472528afbdd6baa8232198R108-R175) **Bug Fixes:** * Fixed an error message in `subgraph_whisper_encoder.cc` to reference the correct input index for `decoder_input_ids`. These changes improve robustness by ensuring that subgraph classes fail early and clearly when required inputs are missing or malformed, and they are now covered by dedicated unit tests.
Author
Parents
Loading