Skip to main content

Crate seqpacker

Crate seqpacker 

Source
Expand description

§seqpacker

High-performance sequence packing for LLM training.

Seqpacker solves the bin-packing problem for variable-length sequences: given a set of sequences and a maximum pack length, pack them into the fewest bins possible while minimizing padding waste.

§Quick Start

use seqpacker::{Packer, PackStrategy, Sequence};

let packer = Packer::new(2048)
    .with_strategy(PackStrategy::FirstFitDecreasing);

let sequences = vec![
    Sequence::new(0, 500),
    Sequence::new(1, 600),
    Sequence::new(2, 400),
];

let result = packer.pack(sequences).unwrap();
println!("Efficiency: {:.2}%", result.metrics.efficiency * 100.0);

§Available Algorithms

AlgorithmTimeApprox. RatioBest For
NextFitO(n)2.0Memory-constrained streaming
FirstFitO(n log B)1.7Online baseline
BestFitO(n log B)1.7Tighter packing
WorstFitO(n log B)2.0Even distribution
FirstFitDecreasingO(n log n)1.22Default offline (recommended)
BestFitDecreasingO(n log n)1.22Tightest offline packing
FirstFitShuffleO(n log n)~1.3Training randomness
ModifiedFirstFitDecreasingO(n log n)1.18Mixed-size distributions
Harmonic-KO(n)~1.69Bounded-space online

Re-exports§

pub use error::PackError;
pub use metrics::PackMetrics;
pub use pack::Pack;
pub use packer::PackResult;
pub use packer::Packer;
pub use packer::PackerConfig;
pub use sequence::Sequence;
pub use strategy::PackStrategy;
pub use stream::StreamPacker;
pub use stream::StreamStrategy;

Modules§

algorithms
Bin-packing algorithm implementations.
dev
Development helpers and debugging macros.
engine
Generic greedy packing engine.
error
Error types for the seqpacker library.
metrics
Packing quality metrics.
pack
Bin and Pack types for packing output.
packer
Main Packer interface - entry point for users.
placement
PlacementIndex trait and implementations for bin selection.
sequence
Input sequence types for packing.
strategy
Packing strategy enum and algorithm trait.
stream
Streaming packer for bounded-space online algorithms.
validation
Solution validation — checks all universal packing invariants.

Macros§

dbg_type
Print a value’s type and content for debugging.