refactor(packing): replace global HF monkeypatch with typed metadata - #3577
refactor(packing): replace global HF monkeypatch with typed metadata#3577beccohov wants to merge 6 commits into
Conversation
Signed-off-by: Arkadii Be <beccohov@gmail.com>
|
Hey, @yuhezhang-ai |
a997781 to
92e10e9
Compare
Signed-off-by: Arkadii Be <beccohov@gmail.com>
92e10e9 to
d39a29e
Compare
|
/ok to test d81ddcf |
yuhezhang-ai
left a comment
There was a problem hiding this comment.
Thanks for taking this on — replacing the process-wide monkeypatches with explicit packed-sequence metadata is a much cleaner direction. I had two follow-ups that would make this safer to rely on broadly:
-
In
_validate_model_consumes_packed_contract, could we require either**kwargs,_packed_seq_ids, or all four varlen kwargs? The current set intersection accepts a forward that exposes only one of the four.filter_forward_kwargscan then drop the remaining cumulative-length fields, while Transformers enters its varlen path only when all four are present. Usingset(_PACKED_VARLEN_KWARGS).issubset(params)for that branch would keep this check fail-closed. -
Could we narrow the FlashAttention availability probe so unexpected model/CUDA execution failures are not converted into skips? The real GPU parity test currently covers Llama with a single packed row. It would also be valuable to exercise batch size greater than one with uneven row padding and the actual Qwen3-VL packed FlashAttention path. The release matrix should auto-discover the Qwen3-VL config; we would also be happy to help run the relevant scoped CI job after the PR is updated.
The focused CPU tests passed locally; the FlashAttention cases skipped in the CPU-only environment. Thanks again!
Signed-off-by: Arkadii Be <beccohov@gmail.com>
|
Thanks, @yuhezhang-ai, I believe I've addressed all of your suggestions:
I think we need to run CI |
|
/ok to test 9bde8b1 |
What does this PR do ?
Replaces the process-wide monkeypatching that NEAT packing used to route packed sequences through FlashAttention with typed metadata that the collaters build and pass through the public HF kwargs.
Changelog
PackedSeqParamsandpacked_seq_params_from_doc_ids(datasets/packed_seq.py). The collater derivescu_seqlens/max_seqlenfrom the document map and emits them asFlashAttentionKwargs(cu_seq_lens_q/k,max_length_q/k). Thecu_seqlensspan the full flattened batch, including padding, with a forced boundary at every row so a row-filling document cannot merge with the next row._packed_seq_idsfor the loss and context-parallel consumers.configure_packingand the three patch sites (_get_unpad_data,_preprocess_mask_arguments, per-modulecreate_causal_mask). In their placevalidate_flash_packing_supportfails early when the installed Transformers build or the model cannot accept the typed contract.Before your PR is "Ready for review"
Pre checks:
Additional Information