Skip to content

perf: fp16 autocast, parallel Redis KNN, and Docker runtime fixes - #14

Merged
danellecline merged 4 commits into
mainfrom
perf/speedup
Jul 17, 2026
Merged

perf: fp16 autocast, parallel Redis KNN, and Docker runtime fixes#14
danellecline merged 4 commits into
mainfrom
perf/speedup

Conversation

@danellecline

@danellecline danellecline commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

  • Speed up inference with fp16 autocast (VSS_AMP, default on for CUDA), model.eval(), and torch.inference_mode(); embeddings are cast back to float32 for the Redis index.
  • Batch Redis KNN queries concurrently via search_vectors() instead of one serial round-trip per image (VSS_KNN_WORKERS, default 16).
  • Harden Docker/runtime for optional VSS_TORCH_COMPILE: uid-agnostic cache env vars, gcc/g++ on the CUDA base image (avoid devel LD_LIBRARY_PATH cuBLAS conflicts), and eager fallback if lazy compile fails on first forward.

Test plan

  • Benchmarked 2,930 Kelp crops against production FastAPI (batch 32, 4 workers): ~20.4 → ~21.7 img/s (~6% gain); per-worker throughput suggests Redis FLAT index / producer queue starvation remain the dominant bottlenecks.
  • Rebuild and redeploy worker image from this branch.
  • Verify workers start cleanly under compose user: 12078:20 (no getpwuid / cuBLAS init errors).
  • Smoke test /knn and /embed with default env and with VSS_TORCH_COMPILE=1.
  • Confirm KNN results match baseline (fp16 may cause tiny score differences on ties).

Env knobs

  • VSS_AMP=1 (default) — fp16 autocast on CUDA
  • VSS_KNN_WORKERS=16 (default) — concurrent KNN queries per batch
  • VSS_TORCH_COMPILE=0 (default) — optional torch.compile; requires gcc/g++ in image

danellecline and others added 4 commits July 16, 2026 16:30
Speed up inference throughput on two fronts:
- process_vits: run the ViT forward pass under fp16 autocast (CUDA) with
  model.eval() and torch.inference_mode(), non-blocking host->device copies,
  and an optional torch.compile path. Embeddings are cast back to float32 to
  match the FLOAT32 Redis index. Toggle via VSS_AMP / VSS_TORCH_COMPILE.
- vector_similarity: add search_vectors() to issue a batch of KNN queries
  concurrently over the connection pool instead of one serial round-trip per
  image; predict() now uses it. Concurrency tunable via VSS_KNN_WORKERS.

Co-authored-by: Cursor <cursoragent@cursor.com>
torch._dynamo (imported transitively by transformers) calls getpass.getuser()
at import time, which raises KeyError when the container runs as an arbitrary
uid with no /etc/passwd entry (e.g. compose `user: 12078:20`). Set USER/HOME so
getpass short-circuits on the env var, and route torch/HF caches to writable
/tmp so the optional torch.compile path works for any uid.

Co-authored-by: Cursor <cursoragent@cursor.com>
Switch the runtime image to the CUDA devel base (plus python3.11-dev) so the
Inductor/Triton backend used by VSS_TORCH_COMPILE=1 has the gcc/nvcc toolchain
and headers it JIT-compiles against, fixing the "Failed to find C compiler"
error. Also catch lazy torch.compile failures on the first forward and fall
back to eager execution so a compile problem no longer fails every prediction.

Co-authored-by: Cursor <cursoragent@cursor.com>
The devel image sets LD_LIBRARY_PATH=/usr/local/cuda/lib64, which shadows the
CUDA libraries bundled with the pip torch wheel and caused
CUBLAS_STATUS_NOT_INITIALIZED (cublasLtMatmulAlgoGetHeuristic) at runtime.
Revert to the lightweight base image and install just gcc/g++ so the optional
VSS_TORCH_COMPILE (Triton) path still has a C/C++ compiler without dragging in
the conflicting system CUDA libs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@danellecline
danellecline merged commit f0fc937 into main Jul 17, 2026
1 check passed
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.

1 participant