fix(template): align multimodal fields and handle text-only inputs - #10176
Open
taking-lying-flat wants to merge 5 commits into
Open
taking-lying-flat wants to merge 5 commits into
taking-lying-flat wants to merge 5 commits into
Conversation
| loss_scale[0] = 0 | ||
| encoded['loss_scale'] = loss_scale | ||
| token_type_ids = encoded.get('token_type_ids') | ||
| if token_type_ids is not None: |
Collaborator
There was a problem hiding this comment.
sometimes token_type_ids is a 2-d tensor, which will raise error here.
Check: ERNIE-VL please
Merge current main, retaining image_token_types support. Slice tensor token_type_ids along the sequence dimension while preserving their type and leading dimensions. Cover ERNIE-VL encoding, list and tensor forms, left/right truncation, protected positions, and mixed-length collation.
Exercise actual template encoding and collation across image, audio, and video inputs. Correct the PaliGemma prompt boundary, extend Cog visual-token loss scales, and preserve mixed CogVLM batches while rejecting unsupported CogAgent cross-attention batches.
This branch has not been deployed
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.
PR type
PR information
Multimodal token fields can become misaligned during encoding and truncation. For example, truncating a Gemma sample leaves
token_type_idsat its original length, while applying a one-dimensional mask directly to ERNIE-VL's[1, sequence_length]token-type tensor raises an indexing error.token_type_idswith the same retained-position mask as the other per-token fields. Slice tensors along their sequence dimension while preserving their dtype, device, and leading batch dimension so the collator can handle them correctly.loss_scalealongside inserted visual tokens, using zero weight for those tokens.KeyError.Local regression tests exercise the actual PaliGemma, Gemma3, Gemma3n, Molmo2, CogVLM, CogVLM2, CogAgent Chat/VQA, and Cog2Video template encoders and collators with lightweight tokenizer/processor/model-method stubs. Coverage includes image, audio and video expansion, exact token-type values (including Gemma3n audio type 3), labels, non-binary loss scales, left/right truncation, both batch orders, padding, and media tensors. ERNIE-VL's token-type assembly and generic list/tensor truncation also remain covered.
Validation
The results below were obtained at commit
30fdde5, before restoring test files to the upstream versions. The regression tests are retained as a local patch and are not included in the final PR diff. Production fixes are unchanged.pre-commit run --all-filesandgit diff --check: passed.Broader testing was attempted and is not fully green:
vllmandqwen_vl_utils. A local launcher supplies the real imports normally executed by standalone scripts and the Transformers backend argument; models and assertions are not mocked.tests/general: 820 passed, 265 subtests passed, 21 failed, 7 setup errors. Remaining failures include missing model/dataset resources, a dataset clone timeout, the existing LISA callback'sTrainingArguments.max_epochscompatibility error, and a ModelScope-only ID tested with the HF download channel. Counts overlap the focused suite and must not be added together.Validation used Python 3.11, torch 2.14 and transformers 5.16.1. Full pretrained-model forward/training across all templates remains unverified and requires the appropriate models, optional dependencies and accelerator environment.