perf(workers): scaled embedding preprocessing and idle-only backoff
- Embedding and tagging workers now sleep their backoff interval (500ms/750ms) only when the queue is empty, the model is not ready, or a batch errored — previously every batch paid the sleep even with work pending. - CLIP preprocessing no longer decodes originals at full resolution: decode_for_thumbnail is generalized into decode_image_scaled with a cover mode (shortest side >= target) and the embedder decodes JPEGs at the smallest DCT scale covering its 224px fill-crop, in parallel via rayon. The forward pass, not image decode, is now the dominant embedding cost. - EXIF orientation is now applied before embedding, so rotated photos embed the way they are displayed (previously embedded sideways). Existing stored embeddings are unaffected.
This commit is contained in:
@@ -191,9 +191,11 @@ fn resolve_device() -> Result<Device> {
|
||||
}
|
||||
|
||||
fn load_image(path: &Path, image_size: usize) -> Result<Tensor> {
|
||||
let image = image::ImageReader::open(path)?
|
||||
.with_guessed_format()?
|
||||
.decode()?;
|
||||
// Scaled decode: CLIP only needs image_size² pixels, so decoding a large
|
||||
// JPEG at full resolution is wasted work. Cover mode keeps the shortest
|
||||
// side at or above image_size for the fill-crop below. Also applies EXIF
|
||||
// orientation, so rotated photos embed the way they are displayed.
|
||||
let image = crate::thumbnail::decode_image_scaled(path, image_size as u32, true)?;
|
||||
let image = image.resize_to_fill(
|
||||
image_size as u32,
|
||||
image_size as u32,
|
||||
@@ -208,10 +210,11 @@ fn load_image(path: &Path, image_size: usize) -> Result<Tensor> {
|
||||
}
|
||||
|
||||
fn load_images(paths: &[PathBuf], image_size: usize) -> Result<Tensor> {
|
||||
let mut images = Vec::with_capacity(paths.len());
|
||||
for path in paths {
|
||||
images.push(load_image(path, image_size)?);
|
||||
}
|
||||
use rayon::prelude::*;
|
||||
let images = paths
|
||||
.par_iter()
|
||||
.map(|path| load_image(path, image_size))
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
Ok(Tensor::stack(&images, 0)?)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user