bridge.diffusion.data.common.sequence_packing_utils#

Module Contents#

Functions#

packing_length

Returns the bin-packing length of an item.

API#

bridge.diffusion.data.common.sequence_packing_utils.packing_length(item: Any) int#

Returns the bin-packing length of an item.

This is the only diffusion-specific piece of sequence packing: the bin-packing algorithms themselves live in megatron.bridge.data.packing.algorithms and are shared with LLM offline SFT packing. Diffusion packs live DiffusionSample objects rather than integer lengths, so it computes each sample’s length with this adapter and passes the results as item_lengths to the shared packer.

Items are either plain sequence lengths or objects that report their length by adding with an int – DiffusionSample does this, returning its padded query sequence length when one is set and its unpadded length otherwise. Going through 0 + item keeps this module free of a hard dependency on the sample type, and matches the length the previous sum(bin) + s capacity check used.

Parameters:

item – A sequence length, or an object implementing __radd__ against an int.

Returns:

The integer length used for bin-packing capacity accounting.