Skip to content

Add a packed SFT notebook that benchmarks the packed-rows layout - #8732

Closed
behroozazarkhalili wants to merge 1 commit into
huggingface:mainfrom
behroozazarkhalili:add-sft-packing-tldr-example
Closed

behroozazarkhalili wants to merge 1 commit into
huggingface:mainfrom
behroozazarkhalili:add-sft-packing-tldr-example

Conversation

@behroozazarkhalili

@behroozazarkhalili behroozazarkhalili commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

This adds examples/sft_packing_tldr/sft_packing_tldr.ipynb and its row in the examples overview.

The notebook measures what the packed-rows layout from #7804 does for SDPA training: padded batches, packed rows and the flattened layout are run on the same tokens with Qwen3-0.6B-Base. In the committed run, packed rows train 2.37x faster than the flattened layout and 1.24x faster than padded batches; with flash attention 2 the two layouts are within 5% of each other. It then fine-tunes on trl-lib/tldr with packing and checks the loss mask and the document boundaries in the packed rows.

Peak GPU memory stays under 4 GB. The outputs come from one end-to-end run on a 10 GB slice of an H100; I did not run it on a T4.


Note

Low Risk
Documentation and example notebook only; no changes to TRL library training code or runtime behavior.

Overview
Adds examples/sft_packing_tldr/sft_packing_tldr.ipynb, a Colab-oriented walkthrough for SFTTrainer packing with SDPA. The notebook benchmarks three batch layouts on the same token budget (padded batches, TRL 1.19 packed rows with padding_free=False, and the legacy flattened layout via padding_free=True), optional flash-attention-2 runs, and reports tokens/s, padding fraction, step time, and peak GPU memory. It then runs a packed LoRA fine-tune of Qwen3-0.6B-Base on trl-lib/tldr with checks that completion-only loss masks and per-document position_ids keep packed documents isolated under SDPA.

docs/source/example_overview.md gains a new index row for sft_packing_tldr with description and an Open in Colab badge, inserted in the SFT examples list.

Reviewed by Cursor Bugbot for commit 31f481d. Bugbot is set up for automated code reviews on this repo. Configure here.

@bot-ci-comment

bot-ci-comment Bot commented Dec 2, 2026

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

@sergiopaniego

Copy link
Copy Markdown
Member

Closing, see #8686 (comment). This measures the packed-rows layout from #7804 more than it shows a task, and packing is already covered in the docs and SFT examples. Good to have the SDPA numbers on record here, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants