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
| Algorithm | Time | Approx. Ratio | Best For |
|---|---|---|---|
| NextFit | O(n) | 2.0 | Memory-constrained streaming |
| FirstFit | O(n log B) | 1.7 | Online baseline |
| BestFit | O(n log B) | 1.7 | Tighter packing |
| WorstFit | O(n log B) | 2.0 | Even distribution |
| FirstFitDecreasing | O(n log n) | 1.22 | Default offline (recommended) |
| BestFitDecreasing | O(n log n) | 1.22 | Tightest offline packing |
| FirstFitShuffle | O(n log n) | ~1.3 | Training randomness |
| ModifiedFirstFitDecreasing | O(n log n) | 1.18 | Mixed-size distributions |
| Harmonic-K | O(n) | ~1.69 | Bounded-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.